Rotation

MrSiggler
Posts: 5
Joined: Thu Aug 02, 2012 1:07 pm

Rotation

Post by MrSiggler »

I apologize if this is a bit newbish, but I'm having trouble with my rotation.

I'm integrating bullet into a game engine that uses euler XYZ rotation for it's objects..

What I'm trying to do, is write code that fetches the rotation from a bullet body in the world, to update the display object in the engine. And another bit of code, that can update the rotation of the bullet body, if the display object is changed directly.

Here's what I'm doing to fetch the rotation from the body...

Code: Select all

    btTransform t=_rigidBody->getWorldTransform();    
    btMatrix3x3 m=btMatrix3x3(t.getRotation());
    btScalar rot[3];
    m.getEulerZYX(rot[0], rot[1], rot[2]);
    
    return glm::vec3(glm::degrees(rot[2]), glm::degrees(rot[1]), glm::degrees(rot[0]));
And to change the rotation,

Code: Select all

    btTransform t;
    _motionState->getWorldTransform(t);
    t.setRotation(btQuaternion(glm::radians(z), glm::radians(y), glm::radians(x)));
    _motionState->setWorldTransform(t);
Is there anything obviously wrong with this? What happens, is that when I change the rotation, it seems to "jump", and never quite end up what I'm expecting.