Twitchy Rotation

Post Reply
Posts: 6
Joined: Sat Nov 20, 2010 5:14 pm

Twitchy Rotation

Post by InsertWittyName » Fri Jul 20, 2012 12:02 pm

I've spent hours debugging my project, and it turns out that it just boils down to the following:

I manually set rotations of a part, to mimic an angular velocity.

For each frame:

Code: Select all

btVector3 angularVelocityLocalCoord(0.,0.,1.5);

// Convert to world coordinates
btVector3 angVWorld = m_bodies[0]->getWorldTransform().getBasis() * (angularVelocityLocalCoord); 
btMatrix3x3 w_cross = btMatrix3x3( 0., -angVWorld.z(),	angVWorld.y()
                                 , angVWorld.z(),	0., -angVWorld.x()
                                 , -angVWorld.y(),	angVWorld.x(),	0.);
// Step the rotation

// This line works fine
//btMatrix3x3 newRot = m_bodies[0]->getWorldTransform().getBasis() + (w_cross * m_bodies[0]->getWorldTransform().getBasis()) * timestep;
// This line causes twitchy rotation
btMatrix3x3 newRot = partRotation + (w_cross * partRotation) * timestep;

partRotation = newRot;

There are two ways to calculate the rotation for the next frame. One accesses the rigid body current rotation directly, the other uses a stored btMatrix3x3 that is initialized with the intial rotation, and is subsequently updated in the code above. The former causes smooth rotation. The latter does not.

Would someone explain what the difference is between the two rotations please? I've attached a modified demo that demonstrates the problem. The lines in question are in RagDoll::Rotate()


(6.65 KiB) Downloaded 131 times

Post Reply