Difference between Motion State and World Transform

Post Reply
karnivaurus
Posts: 9
Joined: Thu Nov 19, 2015 2:18 pm

Difference between Motion State and World Transform

Post by karnivaurus »

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:

Code: Select all

    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:

Code: Select all

    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?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Difference between Motion State and World Transform

Post by drleviathan »

btMotionState is a pure virtual class. Hence it defines an API that you must implement for your own derived class. In particular there are two methods to be implemented:

Code: Select all

virtual void getWorldTransform(btTransform& worldTrans ) const = 0;
virtual void    setWorldTransform(const btTransform& worldTrans) = 0;
Whenever the btDiscreteDynamicsWorld wants to know what the position of the object should be it calls getWorldTransform() on its btMotionState (if it has one). There are two places where this happens:

(1) When the bRigidBody is first added to the world.
(2) Once per substep IFF the btRigidBody is KINEMATIC.

The btDiscreteDynamicsWorld is guaranteed to call setWorldTransform() once per substep for every btRigidBody that: has a MotionState AND is active AND is not KINEMATIC or STATIC.
Post Reply