Added bare bones physics
This commit is contained in:
@@ -285,24 +285,72 @@ void Application::onCleanup() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
double grav = 0.32666666666666666666666666666667;
|
/*
|
||||||
void Application::onLogic() {
|
|
||||||
//PhysicsStart
|
|
||||||
|
|
||||||
for(size_t i = 0; i < this->_dataModel->getWorkspace()->physicalObjects.size(); i++)
|
Class HyperSnapSolver
|
||||||
|
|
||||||
|
function getCollisionDepth(Part colliding, part collider);
|
||||||
|
function getFaceCollision(Part colliding, part collider);
|
||||||
|
|
||||||
|
function eject(Part colliding, Part collider)
|
||||||
{
|
{
|
||||||
if(PartInstance* collider = dynamic_cast<PartInstance*>(this->_dataModel->getWorkspace()->physicalObjects.at(i)))
|
if(!colliding.canCollide || !collider.canCollide)
|
||||||
|
return;
|
||||||
|
if(getCollisionDepth(colliding, collider) != 0) {
|
||||||
|
int ejectMultiplier, ejectMultipliery = 1-(collider.Friction+colliding.Friction), ejectMultiplierz = 1-(collider.Friction/2+colliding.Friction/2);
|
||||||
|
if(colliding.Anchored)
|
||||||
|
ejectMultiplier = collider.elasticity;
|
||||||
|
int faceCollided = getFaceCollision(colliding, collider);
|
||||||
|
if(faceCollided % 3 == 1)
|
||||||
|
{
|
||||||
|
ejectMultipliery = ejectMultiplier;
|
||||||
|
ejectMultiplier = 1-(collider.Friction+colliding.Friction/2);
|
||||||
|
}
|
||||||
|
else if(faceCollided % 3 == 2)
|
||||||
|
{
|
||||||
|
ejectMultiplierz = ejectMultiplier;
|
||||||
|
ejectMultiplier = 1-(collider.Friction+colliding.Friction/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
collider.Velocity *= Vector3.new(colliding.Velocity.x*ejectMultiplier,colliding.Velocity.y*ejectMultipliery,colliding.Velocity.z)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
double grav = 0.32666666666666666666666666666667;
|
||||||
|
void simGrav(PartInstance * collider)
|
||||||
{
|
{
|
||||||
if(!collider->anchored)
|
if(!collider->anchored)
|
||||||
{
|
{
|
||||||
collider->setPosition(collider->getPosition()+collider->getVelocity());
|
collider->setPosition(collider->getPosition()+collider->getVelocity());
|
||||||
collider->setVelocity(Vector3(collider->getVelocity().x,collider->getVelocity().y-grav,collider->getVelocity().z));
|
collider->setVelocity(collider->getVelocity()-Vector3(0,grav,0));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void eject(PartInstance * colliding, PartInstance * collider)
|
||||||
|
{
|
||||||
|
if(colliding == collider || !colliding->canCollide || !collider->canCollide)
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Application::onLogic() {
|
||||||
|
//PhysicsStart
|
||||||
|
for_each (_dataModel->getWorkspace()->partObjects.begin(), _dataModel->getWorkspace()->partObjects.end(), simGrav);
|
||||||
|
for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++)
|
||||||
|
{
|
||||||
|
for(size_t j = 0; j < _dataModel->getWorkspace()->partObjects.size(); j++)
|
||||||
|
{
|
||||||
|
eject(_dataModel->getWorkspace()->partObjects[i], _dataModel->getWorkspace()->partObjects[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Application::onNetwork() {
|
void Application::onNetwork() {
|
||||||
// Poll net messages here
|
// Poll net messages here
|
||||||
}
|
}
|
||||||
@@ -319,6 +367,7 @@ std::vector<Instance*> Application::getSelection()
|
|||||||
}
|
}
|
||||||
void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
||||||
|
|
||||||
|
if(_dataModel->isRunning())
|
||||||
onLogic();
|
onLogic();
|
||||||
|
|
||||||
_dataModel->getGuiRoot()->update();
|
_dataModel->getGuiRoot()->update();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "MenuButtonListener.h"
|
#include "MenuButtonListener.h"
|
||||||
#include "toggleimagebuttoninstance.h"
|
#include "toggleimagebuttoninstance.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
void onButton1MouseClick(BaseButtonInstance* button)
|
void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
||||||
{
|
{
|
||||||
if(button->name == "go")
|
if(button->name == "go")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ void PartInstance::setParent(Instance* parent)
|
|||||||
{
|
{
|
||||||
if(WorkspaceInstance* workspace = dynamic_cast<WorkspaceInstance*>(parent))
|
if(WorkspaceInstance* workspace = dynamic_cast<WorkspaceInstance*>(parent))
|
||||||
{
|
{
|
||||||
workspace->physicalObjects.erase(std::remove(workspace->physicalObjects.begin(), workspace->physicalObjects.end(), this), workspace->physicalObjects.end());
|
workspace->partObjects.erase(std::remove(workspace->partObjects.begin(), workspace->partObjects.end(), this), workspace->partObjects.end());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cparent = cparent->getParent();
|
cparent = cparent->getParent();
|
||||||
@@ -93,7 +93,7 @@ void PartInstance::setParent(Instance* parent)
|
|||||||
{
|
{
|
||||||
if(WorkspaceInstance* workspace = dynamic_cast<WorkspaceInstance*>(parent))
|
if(WorkspaceInstance* workspace = dynamic_cast<WorkspaceInstance*>(parent))
|
||||||
{
|
{
|
||||||
workspace->physicalObjects.push_back(this);
|
workspace->partObjects.push_back(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
parent = parent->getParent();
|
parent = parent->getParent();
|
||||||
@@ -188,7 +188,7 @@ void PartInstance::setShape(Enum::Shape::Value shape)
|
|||||||
void PartInstance::setPosition(Vector3 pos)
|
void PartInstance::setPosition(Vector3 pos)
|
||||||
{
|
{
|
||||||
position = pos;
|
position = pos;
|
||||||
cFrame = CoordinateFrame(pos);
|
cFrame = CoordinateFrame(cFrame.rotation, pos);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,33 @@ void ToggleImageButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool
|
|||||||
positionRelative = Vector2(rd->getWidth() + position.x, position.y);
|
positionRelative = Vector2(rd->getWidth() + position.x, position.y);
|
||||||
}
|
}
|
||||||
int renderimage = openGLID;
|
int renderimage = openGLID;
|
||||||
|
if(checked)
|
||||||
|
{
|
||||||
|
renderimage = openGLID2;
|
||||||
|
if(selected == true && !image_dn2.isNull() && !disabled)
|
||||||
|
{
|
||||||
|
renderimage = openGLID2_dn;
|
||||||
|
}
|
||||||
|
else if(disabled)
|
||||||
|
{
|
||||||
|
if(!image_ds2.isNull())
|
||||||
|
renderimage = openGLID2_ds;
|
||||||
|
else
|
||||||
|
drawDisabledBox = true;
|
||||||
|
}
|
||||||
|
else if(mouseInArea(positionRelative.x, positionRelative.y, positionRelative.x + size.x, positionRelative.y + size.y, mousePos.x, mousePos.y))
|
||||||
|
{
|
||||||
|
if(mouseDown && !image_dn2.isNull())
|
||||||
|
{
|
||||||
|
renderimage = openGLID2_dn;
|
||||||
|
}
|
||||||
|
else if(!image_ovr2.isNull())
|
||||||
|
{
|
||||||
|
renderimage = openGLID2_ovr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if(selected == true && !image_dn.isNull() && !disabled)
|
if(selected == true && !image_dn.isNull() && !disabled)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "GroupInstance.h"
|
#include "GroupInstance.h"
|
||||||
|
#include "PartInstance.h"
|
||||||
|
|
||||||
class WorkspaceInstance :
|
class WorkspaceInstance :
|
||||||
public GroupInstance
|
public GroupInstance
|
||||||
@@ -7,5 +8,5 @@ class WorkspaceInstance :
|
|||||||
public:
|
public:
|
||||||
WorkspaceInstance(void);
|
WorkspaceInstance(void);
|
||||||
~WorkspaceInstance(void);
|
~WorkspaceInstance(void);
|
||||||
std::vector<PVInstance *> physicalObjects;
|
std::vector<PartInstance *> partObjects;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user