4
\$\begingroup\$

In Bullet Physics, when I create a new btRigidBody, one of the parameters passed to the constructor is the btMotionState, which defines the initial pose of the body. However, if I then later want to change the pose of the body manually (for example, if it is a kinematic body), how can I do this?

What I have tried so far, is to use the body's setWorldTransform() function. For example:

glm::mat4 pose;
pose[3][0] = 0.5;
pose[3][1] = 2.0;
pose[3][2] = 1.0;
btTransform new_transform;
new_transform.setFromOpenGLMatrix((float*)&pose[0]);
my_body->setWorldTransform(new_transform);

However, when I then try to read the pose of the object again:

btTransform trans = my_body->getWorldTransform();
std::cout << "Y = " << trans.getOrigin().getY() << std::endl;

It returns the value set in the body's constructor, not the value set in setWorldTransform().

Please can somebody explain the different between the motion state, and the world transform, and how I should go about manually updating the pose of a kinematic object?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I guess you are using the initial world transformation of the body. you should get the current motionState transformation of the body to get the current position. Also make sure you are not stepping the dynamicworld or you will get the values after applying physics.

I am usually using the below trick:

Instead of using my_body->getWorldTransform(), try using the below code:

btTransform trans;
my_body->getMotionState()->getWorldTransform(trans);
float matrix[16] ;
trans.getOpenGLMatrix(matrix);
\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .