Page 1 of 1

change position static object... SOLVED

Posted: Wed Mar 20, 2019 6:17 am
by LastBlow
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);

Re: change position static object...

Posted: Wed Mar 20, 2019 3:54 pm
by drleviathan
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.

Re: change position static object...

Posted: Wed Mar 20, 2019 4:56 pm
by LastBlow
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. ;-)))

Re: change position static object...

Posted: Wed Mar 20, 2019 8:34 pm
by LastBlow
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.