Skip to content

Commit

Permalink
allow altering transform during simulation if mass is set to zero (st…
Browse files Browse the repository at this point in the history
…atic)
  • Loading branch information
goopey7 committed Jan 3, 2024
1 parent 0cf3c97 commit ee0ec4d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
21 changes: 21 additions & 0 deletions goop/sys/platform/bullet/Physics_Bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 15 additions & 15 deletions lvl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,7 +25,7 @@
{
"path": "box",
"primitive": "box",
"texturePath": "res/viking_room.png",
"texturePath": "res/texture.jpg",
"type": "mesh"
},
{
Expand All @@ -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,
Expand All @@ -63,7 +63,7 @@
{
"path": "box",
"primitive": "box",
"texturePath": "res/texture.jpg",
"texturePath": "res/viking_room.png",
"type": "mesh"
},
{
Expand All @@ -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"
Expand Down

0 comments on commit ee0ec4d

Please sign in to comment.