From df77572fe7930f9bcf9c99a5b26f3266aeb16241 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 16:44:59 -0700 Subject: [PATCH] Made anchoring togglable in play mode --- src/include/DataModelV2/PartInstance.h | 4 +++- src/source/Application.cpp | 2 +- src/source/DataModelV2/DataModelInstance.cpp | 3 +-- src/source/DataModelV2/PartInstance.cpp | 15 +++++++++++++-- src/source/XplicitNgine/XplicitNgine.cpp | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index 06cf62d..c9a21fe 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -29,7 +29,6 @@ public: //Variables Color3 color; bool canCollide; - bool anchored; dBodyID physBody; dGeomID physGeom[3]; @@ -54,6 +53,8 @@ public: void setShape(Enum::Shape::Value shape); void setChanged(); void setSurface(int face, Enum::SurfaceType::Value surface); + void setAnchored(bool anchored); + bool isAnchored(); float getMass(); //Collision @@ -64,6 +65,7 @@ public: virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); private: + bool anchored; Vector3 position; Vector3 size; Vector3 velocity; diff --git a/src/source/Application.cpp b/src/source/Application.cpp index 7591a36..b40c972 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -198,7 +198,7 @@ void Application::onInit() { test->setPosition(Vector3(0,0,0)); test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(0),toRadians(0))); test->setSurface(TOP, Enum::SurfaceType::Bumps); - test->anchored = true; + test->setAnchored(true); test = makePart(); test->setParent(_dataModel->getWorkspace()); diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index 9be2659..3add80d 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -425,8 +425,7 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode) } if(anchoredNode) { - printf("AAAAAAAAAAAAAAAAAAAA %s\n", anchoredNode->value()); - test->anchored = stricmp(anchoredNode->value(), "true") == 0; + test->setAnchored(stricmp(anchoredNode->value(), "true") == 0); } test->setSize(Vector3(sizeX,sizeY+_modY,sizeZ)); test->setName(newName); diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index 1d0a36e..db45cf6 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -230,9 +230,20 @@ void PartInstance::setPosition(Vector3 pos) { position = pos; setCFrame(CoordinateFrame(cFrame.rotation, pos)); - changed = true; } +void PartInstance::setAnchored(bool anchored) +{ + this->anchored = anchored; + g_dataModel->getEngine()->deleteBody(this); +} + +bool PartInstance::isAnchored() +{ + return this->anchored; +} + + CoordinateFrame PartInstance::getCFrame() { return cFrame; @@ -359,7 +370,7 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) } else if(strcmp(item->lpszPropName, "Anchored") == 0) { - anchored= item->lpCurValue == TRUE; + setAnchored(item->lpCurValue == TRUE); } else if(strcmp(item->lpszPropName, "Offset") == 0) { diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index 1121d7b..d167a43 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -141,11 +141,11 @@ void XplicitNgine::createBody(PartInstance* partInstance, float stepSize) //printf("[XplicitNgine] Created Body for PartInstance\n"); - if(!partInstance->anchored) + if(!partInstance->isAnchored()) dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); } else { - if(!partInstance->anchored) + if(!partInstance->isAnchored()) { const dReal* physPosition = dBodyGetPosition(partInstance->physBody);