Trouble with rotation

Started by
1 comment, last by alvaro 11 years, 5 months ago
I'm trying to rotate RigidBody but having trouble, it's rotating correctly for few seconds and then I see the rotation stop (like it's restricted).

Here is the code I'm using:

btTransform worldTrans;
body->getMotionState()->getWorldTransform(worldTrans);
float x, y, z;
worldTrans.getBasis().getEulerZYX(x, y, z);
// Rotate
y+=0.1f;
worldTrans.getBasis().setEulerZYX(x, y, z);
body->setWorldTransform(worldTrans);
Advertisement
When using euler for rotation you most likely encounter a gimbal lock. Try to fix two axis and rotate only one or avoid euler.
You don't want to go through Euler angles at all. Your world transform contains a rotation, which is probably represented as a 3x3 matrix. You seem to want to "add" (the technical term is "compose") an extra rotation of 0.1 radians along some axis. You can do that by creating a 3x3 matrix corresponding to the rotation around the axis and then multiplying the world transform by it.

I have never used Bullet before, so I can't write that in code, but hopefully you can understand it.

This topic is closed to new replies.

Advertisement