Made physics work
This commit is contained in:
@@ -54,6 +54,7 @@ public:
|
|||||||
void setShape(Enum::Shape::Value shape);
|
void setShape(Enum::Shape::Value shape);
|
||||||
void setChanged();
|
void setChanged();
|
||||||
void setSurface(int face, Enum::SurfaceType::Value surface);
|
void setSurface(int face, Enum::SurfaceType::Value surface);
|
||||||
|
float getMass();
|
||||||
|
|
||||||
//Collision
|
//Collision
|
||||||
bool collides(PartInstance * part);
|
bool collides(PartInstance * part);
|
||||||
@@ -70,4 +71,4 @@ private:
|
|||||||
bool changed;
|
bool changed;
|
||||||
Box itemBox;
|
Box itemBox;
|
||||||
GLuint glList;
|
GLuint glList;
|
||||||
};
|
};
|
||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
dSpaceID physSpace;
|
dSpaceID physSpace;
|
||||||
dJointGroupID contactgroup;
|
dJointGroupID contactgroup;
|
||||||
|
|
||||||
void createBody(PartInstance* partInstance);
|
void createBody(PartInstance* partInstance, float stepSize);
|
||||||
void deleteBody(PartInstance* partInstance);
|
void deleteBody(PartInstance* partInstance);
|
||||||
void updateBody(PartInstance* partInstance, CoordinateFrame * cFrame);
|
void updateBody(PartInstance* partInstance, CoordinateFrame * cFrame);
|
||||||
};
|
};
|
||||||
@@ -298,12 +298,7 @@ void Application::onCleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Application::onLogic() {
|
void Application::onLogic() {
|
||||||
// XplicitNgine Start
|
|
||||||
for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++)
|
|
||||||
{
|
|
||||||
PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i];
|
|
||||||
_dataModel->getEngine()->createBody(partInstance);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::onNetwork() {
|
void Application::onNetwork() {
|
||||||
@@ -323,8 +318,18 @@ 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())
|
if(_dataModel->isRunning())
|
||||||
|
{
|
||||||
|
// XplicitNgine Start
|
||||||
|
for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++)
|
||||||
|
{
|
||||||
|
PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i];
|
||||||
|
_dataModel->getEngine()->createBody(partInstance, sdt*15/_dataModel->getWorkspace()->partObjects.size());
|
||||||
|
}
|
||||||
|
|
||||||
onLogic();
|
onLogic();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
_dataModel->getGuiRoot()->update();
|
_dataModel->getGuiRoot()->update();
|
||||||
|
|
||||||
if(_dataModel->name != _title)
|
if(_dataModel->name != _title)
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
|
|||||||
xml_node<> *propNode = node->first_node();
|
xml_node<> *propNode = node->first_node();
|
||||||
xml_node<> *cFrameNode=0;
|
xml_node<> *cFrameNode=0;
|
||||||
xml_node<> *sizeNode=0;
|
xml_node<> *sizeNode=0;
|
||||||
|
xml_node<> *anchoredNode=0;
|
||||||
xml_node<> *shapeNode=0;
|
xml_node<> *shapeNode=0;
|
||||||
xml_node<> *colorNode=0;
|
xml_node<> *colorNode=0;
|
||||||
xml_node<> *brickColorNode=0;
|
xml_node<> *brickColorNode=0;
|
||||||
@@ -307,6 +308,10 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
|
|||||||
if (xmlValue=="CFrame" | xmlValue=="CoordinateFrame")
|
if (xmlValue=="CFrame" | xmlValue=="CoordinateFrame")
|
||||||
{
|
{
|
||||||
cFrameNode = partPropNode;
|
cFrameNode = partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="Anchored")
|
||||||
|
{
|
||||||
|
anchoredNode = partPropNode;
|
||||||
}
|
}
|
||||||
if (xmlValue=="Name")
|
if (xmlValue=="Name")
|
||||||
{
|
{
|
||||||
@@ -418,6 +423,11 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
|
|||||||
{
|
{
|
||||||
test->color = bcToRGB(atoi(brickColorNode->value()));
|
test->color = bcToRGB(atoi(brickColorNode->value()));
|
||||||
}
|
}
|
||||||
|
if(anchoredNode)
|
||||||
|
{
|
||||||
|
printf("AAAAAAAAAAAAAAAAAAAA %s\n", anchoredNode->value());
|
||||||
|
test->anchored = stricmp(anchoredNode->value(), "true") == 0;
|
||||||
|
}
|
||||||
test->setSize(Vector3(sizeX,sizeY+_modY,sizeZ));
|
test->setSize(Vector3(sizeX,sizeY+_modY,sizeZ));
|
||||||
test->setName(newName);
|
test->setName(newName);
|
||||||
CoordinateFrame cf;
|
CoordinateFrame cf;
|
||||||
|
|||||||
@@ -28,6 +28,13 @@ PartInstance::PartInstance(void)
|
|||||||
shape = Enum::Shape::Block;
|
shape = Enum::Shape::Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float PartInstance::getMass()
|
||||||
|
{
|
||||||
|
if(shape == Enum::Shape::Block)
|
||||||
|
return size.x*size.y*size.z*0.7F;
|
||||||
|
else
|
||||||
|
return 1.3333333333333333333333333333333F*(size.x/2)*(size.y/2)*(size.z/2)*0.7F;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3 PartInstance::getVelocity()
|
Vector3 PartInstance::getVelocity()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#define _WINSOCKAPI_
|
#define _WINSOCKAPI_
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "WindowFunctions.h"
|
#include "WindowFunctions.h"
|
||||||
#include "../../resource.h"
|
#include "resource.h"
|
||||||
#include "PropertyWindow.h"
|
#include "PropertyWindow.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "strsafe.h"
|
#include "strsafe.h"
|
||||||
|
|||||||
@@ -75,12 +75,11 @@ void XplicitNgine::deleteBody(PartInstance* partInstance)
|
|||||||
}
|
}
|
||||||
dBodyDestroy(partInstance->physBody);
|
dBodyDestroy(partInstance->physBody);
|
||||||
dGeomDestroy(partInstance->physGeom[0]);
|
dGeomDestroy(partInstance->physGeom[0]);
|
||||||
printf("Body should be destroyed");
|
|
||||||
partInstance->physBody = NULL;
|
partInstance->physBody = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XplicitNgine::createBody(PartInstance* partInstance)
|
void XplicitNgine::createBody(PartInstance* partInstance, float stepSize)
|
||||||
{
|
{
|
||||||
// calculate collisions
|
// calculate collisions
|
||||||
dSpaceCollide (physSpace,0,&collisionCallback);
|
dSpaceCollide (physSpace,0,&collisionCallback);
|
||||||
@@ -101,37 +100,46 @@ void XplicitNgine::createBody(PartInstance* partInstance)
|
|||||||
|
|
||||||
dVector3 result;
|
dVector3 result;
|
||||||
dGeomBoxGetLengths(partInstance->physGeom[0], result);
|
dGeomBoxGetLengths(partInstance->physGeom[0], result);
|
||||||
printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n",
|
//printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n",
|
||||||
result[0],
|
// result[0],
|
||||||
result[1],
|
// result[1],
|
||||||
result[2]
|
// result[2]
|
||||||
);
|
//);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
partInstance->physGeom[0] = dCreateSphere(physSpace, partInstance->getSize()[0]/2);
|
partInstance->physGeom[0] = dCreateSphere(physSpace, partInstance->getSize()[0]/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dMass mass;
|
||||||
|
mass.setBox(partInstance->getSize().x, partInstance->getSize().y, partInstance->getSize().z, 0.7F);
|
||||||
|
dBodySetMass(partInstance->physBody, &mass);
|
||||||
|
|
||||||
// Debug output
|
// Debug output
|
||||||
|
|
||||||
|
|
||||||
// Create rigid body
|
// Create rigid body
|
||||||
printf("[XplicitNgine] Created Geom for PartInstance\n");
|
//printf("[XplicitNgine] Created Geom for PartInstance\n");
|
||||||
dBodySetPosition(partInstance->physBody,
|
dBodySetPosition(partInstance->physBody,
|
||||||
partInstance->getPosition()[0],
|
partInstance->getPosition()[0],
|
||||||
partInstance->getPosition()[1],
|
partInstance->getPosition()[1],
|
||||||
partInstance->getPosition()[2]
|
partInstance->getPosition()[2]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dGeomSetPosition(partInstance->physGeom[0],
|
||||||
|
partInstance->getPosition()[0],
|
||||||
|
partInstance->getPosition()[1],
|
||||||
|
partInstance->getPosition()[2]);
|
||||||
|
|
||||||
Matrix3 g3dRot = partInstance->getCFrame().rotation;
|
Matrix3 g3dRot = partInstance->getCFrame().rotation;
|
||||||
float rotation [12] = { g3dRot[0][0], g3dRot[0][1], g3dRot[0][2], 0,
|
float rotation [12] = { g3dRot[0][0], g3dRot[0][1], g3dRot[0][2], 0,
|
||||||
g3dRot[1][0], g3dRot[1][1], g3dRot[1][2], 0,
|
g3dRot[1][0], g3dRot[1][1], g3dRot[1][2], 0,
|
||||||
g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0};
|
g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0};
|
||||||
|
|
||||||
|
dGeomSetRotation(partInstance->physGeom[0], rotation);
|
||||||
dBodySetRotation(partInstance->physBody, rotation);
|
dBodySetRotation(partInstance->physBody, rotation);
|
||||||
|
|
||||||
printf("[XplicitNgine] Created Body for PartInstance\n");
|
//printf("[XplicitNgine] Created Body for PartInstance\n");
|
||||||
|
|
||||||
if(!partInstance->anchored)
|
if(!partInstance->anchored)
|
||||||
dGeomSetBody(partInstance->physGeom[0], partInstance->physBody);
|
dGeomSetBody(partInstance->physGeom[0], partInstance->physBody);
|
||||||
@@ -152,8 +160,8 @@ void XplicitNgine::createBody(PartInstance* partInstance)
|
|||||||
Vector3(physPosition[0], physPosition[1], physPosition[2])));
|
Vector3(physPosition[0], physPosition[1], physPosition[2])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//STEP SHOULD NOT BE HERE!
|
||||||
dWorldQuickStep(physWorld,0.05F);
|
dWorldQuickStep(physWorld, stepSize);
|
||||||
dJointGroupEmpty(contactgroup);
|
dJointGroupEmpty(contactgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +169,6 @@ void XplicitNgine::updateBody(PartInstance *partInstance, CoordinateFrame * cFra
|
|||||||
{
|
{
|
||||||
if(partInstance->physBody != NULL)
|
if(partInstance->physBody != NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
printf("Position is supposed to be set\n");
|
|
||||||
Vector3 position = cFrame->translation;
|
Vector3 position = cFrame->translation;
|
||||||
|
|
||||||
dBodySetPosition(partInstance->physBody,
|
dBodySetPosition(partInstance->physBody,
|
||||||
@@ -178,8 +184,4 @@ void XplicitNgine::updateBody(PartInstance *partInstance, CoordinateFrame * cFra
|
|||||||
|
|
||||||
dBodySetRotation(partInstance->physBody, rotation);
|
dBodySetRotation(partInstance->physBody, rotation);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Null???\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user