From ee0ec4d2bdffc2c99bd0d5e02aa243dec6d1b3a6 Mon Sep 17 00:00:00 2001 From: Sam Collier Date: Wed, 3 Jan 2024 12:45:04 +0000 Subject: [PATCH] allow altering transform during simulation if mass is set to zero (static) --- goop/sys/platform/bullet/Physics_Bullet.cpp | 21 +++++++++++++++ lvl.json | 30 ++++++++++----------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/goop/sys/platform/bullet/Physics_Bullet.cpp b/goop/sys/platform/bullet/Physics_Bullet.cpp index 519b0b2..1f8236c 100644 --- a/goop/sys/platform/bullet/Physics_Bullet.cpp +++ b/goop/sys/platform/bullet/Physics_Bullet.cpp @@ -47,9 +47,30 @@ int Physics_Bullet::destroy() void Physics_Bullet::simulate(float dt) { + for (auto& [rbc, rb] : rigidBodies) + { + if (rbc->mass != 0) + { + continue; + } + + auto tc = transforms[rbc]; + + btTransform transform; + transform.setIdentity(); + transform.setOrigin(btVector3(tc->position.x, tc->position.y, tc->position.z)); + auto rot = glm::quat(glm::radians(tc->rotation)); + transform.setRotation(btQuaternion(rot.x, rot.y, rot.z, rot.w)); + rb->setWorldTransform(transform); + } dynamicsWorld->stepSimulation(dt, 10); for (auto& [rbc, rb] : rigidBodies) { + if (rbc->mass == 0) + { + continue; + } + btTransform transform; rb->getMotionState()->getWorldTransform(transform); btVector3 pos = transform.getOrigin(); diff --git a/lvl.json b/lvl.json index 4cde32b..74085c6 100644 --- a/lvl.json +++ b/lvl.json @@ -7,13 +7,13 @@ { "position": { "x": 0.0, - "y": 0.0, - "z": -0.30000001192092896 + "y": 2.0, + "z": 0.0 }, "rotation": { - "x": 0.0, - "y": 25.399999618530273, - "z": -38.20000076293945 + "x": 23.0, + "y": 35.099998474121094, + "z": 0.0 }, "scale": { "x": 1.0, @@ -25,7 +25,7 @@ { "path": "box", "primitive": "box", - "texturePath": "res/viking_room.png", + "texturePath": "res/texture.jpg", "type": "mesh" }, { @@ -38,20 +38,20 @@ "type": "rigidBody" } ], - "name": "Viking Room" + "name": "Cow" }, { "components": [ { "position": { - "x": -1.7000000476837158, - "y": 0.0, + "x": 0.0, + "y": -1.0, "z": 0.0 }, "rotation": { - "x": 0.0, - "y": 35.099998474121094, - "z": 0.0 + "x": 32.0, + "y": -135.1999969482422, + "z": 24.0 }, "scale": { "x": 1.0, @@ -63,7 +63,7 @@ { "path": "box", "primitive": "box", - "texturePath": "res/texture.jpg", + "texturePath": "res/viking_room.png", "type": "mesh" }, { @@ -72,11 +72,11 @@ "y": 1.0, "z": 1.0 }, - "mass": 1.0, + "mass": 0.0, "type": "rigidBody" } ], - "name": "Cow" + "name": "Viking Room" } ], "name": "lvl_1"