I don't use Bullet, but looking at the documentation, I think this should work: btQuaternion diffQuat = (currentQuat.inverse() * FinalQuat).nearest(btQuaternion(1.0, 0.0, 0.0, 0.0)); if (diffQuat.getAngle() > max_angle)) diffQuat.setRotation(diffQuat.getAxis(),max_angle); btQuaternion newQuat = currentQuat * diffQuat;
That code uses a couple of trigonometric functions more than strictly necessary, but given the interface of btQuaternion, it seems to be the easiest way to do it.
It's not working, basically I want to animate the rotation of a tank cannon, the tank cannon should rotate with certain speed, so the method can look like that: // Every call will rotate the cannon according to 'rotationSpeed' bool lookAt(float x, float y, float z, float rotationSpeed, float elapsedTime);
Here is the idea: 1. The tank see the enemy 2. The tank rotate it's cannon towards the enemy lookAt(enemy.x, enemy.y, enemy.z, 0.1f, elapsedTime); 3. Keep calling lookAt() each frame until lookAt() return true, when lookAt() return true, fire a missile towards the enemy.