diff --git a/Dialogs.rc b/Dialogs.rc index cb89866..2f4904e 100644 --- a/Dialogs.rc +++ b/Dialogs.rc @@ -5,7 +5,7 @@ #include #include #include -#include "resource.h" +#include "src/include/resource.h" diff --git a/resource.h b/resource.h deleted file mode 100644 index c126a1e..0000000 --- a/resource.h +++ /dev/null @@ -1,10 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by dialogs.rc -// -#define IDI_ICON1 101 -#define IDB_BITMAP1 102 -#define IDD_DIALOG1 103 -#define IDC_EDIT1 1001 -#define IDC_PROPERTYGRID 2000 - diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index 4179c83..7a0d346 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -49,6 +49,7 @@ public: void setVelocity(Vector3); void setRotVelocity(Vector3); void setCFrame(CoordinateFrame); + void setCFrameNoSync(CoordinateFrame); void setSize(Vector3); void setShape(Enum::Shape::Value shape); void setChanged(); diff --git a/src/include/XplicitNgine/XplicitNgine.h b/src/include/XplicitNgine/XplicitNgine.h index b117cda..ac92f66 100644 --- a/src/include/XplicitNgine/XplicitNgine.h +++ b/src/include/XplicitNgine/XplicitNgine.h @@ -3,7 +3,7 @@ #include "DatamodelV2/Instance.h" #include "DatamodelV2/PartInstance.h" -class XplicitNgine : Instance +class XplicitNgine : public Instance { public: XplicitNgine(); @@ -13,4 +13,6 @@ public: dJointGroupID contactgroup; void createBody(PartInstance* partInstance); + void deleteBody(PartInstance* partInstance); + void updateBody(PartInstance* partInstance, CoordinateFrame * cFrame); }; \ No newline at end of file diff --git a/src/include/resource.h b/src/include/resource.h index 1673d3d..8f6e7c3 100644 --- a/src/include/resource.h +++ b/src/include/resource.h @@ -1,7 +1,7 @@ #define IDC_PROPERTYGRID 2000 #define IDC_STATIC 2 -#define IDE_EDIT 105 +#define IDC_EDIT1 105 #define IDI_ICON1 102 #define IDB_BITMAP1 103 #define IDD_DIALOG1 104 diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index a3cfa20..e19c8a4 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -43,6 +43,11 @@ void DataModelInstance::resetEngine() delete xplicitNgine; xplicitNgine = new XplicitNgine(); g_xplicitNgine = xplicitNgine; + for(size_t i = 0; i < getWorkspace()->partObjects.size(); i++) + { + PartInstance* partInstance = getWorkspace()->partObjects[i]; + partInstance->physBody = NULL; + } } XplicitNgine * DataModelInstance::getEngine() @@ -53,6 +58,8 @@ XplicitNgine * DataModelInstance::getEngine() void DataModelInstance::toggleRun() { running = !running; + //if(!running) + //resetEngine(); } bool DataModelInstance::isRunning() { diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index d6c0410..9026210 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -8,6 +8,7 @@ PartInstance::PartInstance(void) { PVInstance::PVInstance(); + physBody = NULL; glList = glGenLists(1); name = "Unnamed PVItem"; className = "Part"; @@ -25,7 +26,6 @@ PartInstance::PartInstance(void) left = Enum::SurfaceType::Smooth; bottom = Enum::SurfaceType::Smooth; shape = Enum::Shape::Block; - physBody = NULL; } @@ -110,6 +110,7 @@ void PartInstance::setSurface(int face, Enum::SurfaceType::Value surface) void PartInstance::setParent(Instance* prnt) { + g_dataModel->getEngine()->deleteBody(this); Instance * cparent = getParent(); while(cparent != NULL) { @@ -144,7 +145,7 @@ PartInstance::PartInstance(const PartInstance &oinst) setParent(oinst.parent); anchored = oinst.anchored; size = oinst.size; - setCFrame(oinst.cFrame); + setCFrameNoSync(oinst.cFrame); color = oinst.color; velocity = oinst.velocity; rotVelocity = oinst.rotVelocity; @@ -156,7 +157,6 @@ PartInstance::PartInstance(const PartInstance &oinst) bottom = oinst.bottom; shape = oinst.shape; changed = true; - physBody = NULL; } void PartInstance::setSize(Vector3 newSize) @@ -222,7 +222,7 @@ void PartInstance::setShape(Enum::Shape::Value shape) void PartInstance::setPosition(Vector3 pos) { position = pos; - cFrame = CoordinateFrame(cFrame.rotation, pos); + setCFrame(CoordinateFrame(cFrame.rotation, pos)); changed = true; } @@ -231,6 +231,12 @@ CoordinateFrame PartInstance::getCFrame() return cFrame; } void PartInstance::setCFrame(CoordinateFrame coordinateFrame) +{ + g_dataModel->getEngine()->updateBody(this, &coordinateFrame); + setCFrameNoSync(coordinateFrame); +} + +void PartInstance::setCFrameNoSync(CoordinateFrame coordinateFrame) { cFrame = coordinateFrame; position = coordinateFrame.translation; diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index 98a86fd..dc504ca 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -66,6 +66,20 @@ void collisionCallback(void *data, dGeomID o1, dGeomID o2) } } +void XplicitNgine::deleteBody(PartInstance* partInstance) +{ + if(partInstance->physBody != NULL) + { + while(dBodyGetNumJoints(partInstance->physBody) > 0) { + dJointDestroy(dBodyGetJoint(partInstance->physBody, 0)); + } + dBodyDestroy(partInstance->physBody); + dGeomDestroy(partInstance->physGeom[0]); + printf("Body should be destroyed"); + partInstance->physBody = NULL; + } +} + void XplicitNgine::createBody(PartInstance* partInstance) { // calculate collisions @@ -131,7 +145,7 @@ void XplicitNgine::createBody(PartInstance* partInstance) // Probably should be done AFTER we get physics KINDA working!!! const dReal* physRotation = dGeomGetRotation(partInstance->physGeom[0]); //partInstance->setPosition(Vector3(physPosition[0], physPosition[1], physPosition[2])); - partInstance->setCFrame(CoordinateFrame( + partInstance->setCFrameNoSync(CoordinateFrame( Matrix3(physRotation[0],physRotation[1],physRotation[2], physRotation[4],physRotation[5],physRotation[6], physRotation[8],physRotation[9],physRotation[10]), @@ -141,4 +155,31 @@ void XplicitNgine::createBody(PartInstance* partInstance) dWorldQuickStep(physWorld,0.05F); dJointGroupEmpty(contactgroup); +} + +void XplicitNgine::updateBody(PartInstance *partInstance, CoordinateFrame * cFrame) +{ + if(partInstance->physBody != NULL) + { + + printf("Position is supposed to be set\n"); + Vector3 position = cFrame->translation; + + dBodySetPosition(partInstance->physBody, + position[0], + position[1], + position[2] + ); + + Matrix3 g3dRot = cFrame->rotation; + float rotation [12] = { g3dRot[0][0], g3dRot[0][1], g3dRot[0][2], 0, + g3dRot[1][0], g3dRot[1][1], g3dRot[1][2], 0, + g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0}; + + dBodySetRotation(partInstance->physBody, rotation); + } + else + { + printf("Null???\n"); + } } \ No newline at end of file