How to convert relative transform to global transform ?

Post Reply
Blink
Posts: 2
Joined: Mon Oct 13, 2014 3:47 pm

How to convert relative transform to global transform ?

Post by Blink »

I am trying to use bullet to detect collision between two robotic arms with several degree of freedom.

I have setup a btCollisionWorld with btRigidBody for each part of my arms.

I want to update the position of each body according to the commands I receive from the pilot. From what I read, I should use the setWorldTransform() function to do so.
Unfortunately the commands I receive for my arms only contains the transform of each body in the coordinate frame of its parent body whereas setWorldTransform() uses global coordinates.

Is there an easy way to get my local transform into a global transform I can give to bullet ?
I saw that btTransform has a multiplication and a ' *= ' operator but I don't know if this is the right method to use and how should I use them ?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to convert relative transform to global transform ?

Post by drleviathan »

I'm experimenting on something similar: a linked collection of btRigidBody's whose pose is dictated by a set of parent-relative transforms.

When I have a new set of parent-relative transforms what I have to do is start at the root of the linked tree and work up. So suppose I had some struct called "Bone" that has a parent-relative transform which also happens to represent the local center of mass and orientation of the corresponding RigidBody. I would also store there a world-frame transform and other info like this:

Code: Select all

struct Bone {
    btRigidBody* m_body;
    int m_parentIndex;
    btTransform m_localTransform;
    byTransform m_worldTransform;
};
Then after the local transforms are updated I would recompute all world transforms, starting at the root:

Code: Select all

    // update the root's world transform
    Bone* bone = bones[0];
    bone->m_worldTransform = bone->m_localTransform;
    bone->m_body->setWorldTransform(bone->m_worldTransform);

    // update the others
    for (int i = 1; i < numBones; ++i) {
        bone = bones[i];
        Bone* parentBone = bones[bone->m_parentIndex];
        bone->m_worldTransform = parentBone->m_worldTransform * bone->m_localTransform;
        bone->m_body->setWorldTransform(bone->m_worldTransform);
    }
Blink
Posts: 2
Joined: Mon Oct 13, 2014 3:47 pm

Re: How to convert relative transform to global transform ?

Post by Blink »

Thanks for your answer.

I managed to make my model worked yesterday evening following a similar path as yours.

I started at the root body and the through each child first for the left arm and then for the right one:

Code: Select all

btRigidBody * rootBody;
rootBody->setWorldTransform(rootTransform);
btTransform leftTransform;
btTransform rightTransform;

for (int i = 1; i < numBody; ++i)
{
    if (i < 5)
    {
        leftTransform *= localTransform;
        collisionWorld->getCollisionObjectArray()[i]->setWorldTransform(leftTransform);
    }
    else if(i >= 5)
    {
        rightTransform *=localTransform;
        collisionWorld->getCollisionObjectArray()[i]->setWorldTransform(rightTransform);
    }
}
Post Reply