change position static object... SOLVED

Post Reply
LastBlow
Posts: 18
Joined: Mon Jul 11, 2016 10:36 am
Location: SAN DIEGO

change position static object... SOLVED

Post by LastBlow » Wed Mar 20, 2019 6:17 am

Hi, what would be the best way to change the position of a static object, such as a house when the height of the terrain changes without...
getting this "out of body experience", see pic?

Beside deleting and recreating the static object which obviously works, tried removing, updating the world transform and adding back the rigid
body/collision shape, even getting the object dynamic, then static again.

Only the world transform seems to remain the same, so when I query it, it renders under the collusion shape.

Any ideas, please? Thank you! ;-)))

Code: Select all

                        m_dynamicsWorld->removeRigidBody(rigidBody);

                        btTransform transform;
                        transform.setIdentity();

                        transform.setOrigin(btVector3(positionObject.x(), heightTerrain, positionObject.z()));
                        transform.setRotation(rigidBody->getWorldTransform().getRotation());

                        rigidBody->setWorldTransform(transform);

                        m_dynamicsWorld->addRigidBody(rigidBody);
Attachments
out of body experience 2.jpg
out of body experience 2.jpg (200.06 KiB) Viewed 639 times
Last edited by LastBlow on Thu Mar 21, 2019 6:39 pm, edited 2 times in total.

User avatar
drleviathan
Posts: 545
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: change position static object...

Post by drleviathan » Wed Mar 20, 2019 3:54 pm

In my experience slamming the static RigidBody's WorldTransform just works. It is puzzling that it isn't working for you. However, if you've called world->setForceUpdateAllAabbs(false) for runtime optimization then you have to remember to world->updateSingleAabb(rigidBody) after moving it for collisions to work properly. That is, after slamming the body's transform it's Shape would be in the correct location for the narrow phase but the corresponding Aabb in the btDbvtBroadphase would be stale.

You shouldn't need to world->updateSingleAabb(rigidBody) right after adding it to the world. That looks like wasted work.

LastBlow
Posts: 18
Joined: Mon Jul 11, 2016 10:36 am
Location: SAN DIEGO

Re: change position static object...

Post by LastBlow » Wed Mar 20, 2019 4:56 pm

Good to hear from you and know it's possible to move static objects, thank you!

In fact, the above code effectively updates the height of all objects but the static ones. The house being a compound object,
I just tried with a cylinder: its rendition appeared again under its AABB frame.

I had m_dynamicsWorld->updateSingleAabb(rigidBody) at the end because the rigid body needs to first be added to the
world before updating its AABB, did remove it.

And, no, I am not using m_dynamicsWorld->setForceUpdateAllAabbs(false) for runtime optimization.

Please, post the code that moves static objects for you. ;-)))
Last edited by LastBlow on Thu Mar 21, 2019 6:40 pm, edited 2 times in total.

LastBlow
Posts: 18
Joined: Mon Jul 11, 2016 10:36 am
Location: SAN DIEGO

Re: change position static object...

Post by LastBlow » Wed Mar 20, 2019 8:34 pm

For rendering, I happened to be using m_motionState->getWorldTransform(transform), rather than m_rigidBody->getWorldTransform().

By definition, the motion state for a static object is not updated, so the copy of the world transform in its motion state was apparently not
changed when the world transform of the corresponding rigid body was changed, while both should have been changed for consistency.
Attachments
Flying Dutchman.jpg
Flying Dutchman.jpg (124.14 KiB) Viewed 603 times

Post Reply