Quaternion local rotations

prasoc
Posts: 3
Joined: Mon Aug 29, 2011 9:24 pm

Quaternion local rotations

Post by prasoc »

Code: Select all

Physics::allRigidBodies[0]->setWorldTransform(btTransform(btQuaternion(btVector3(0,1,0),btRadians(rotation.Y)),btVector3(0.0,0,0)));
	Physics::allRigidBodies[0]->setWorldTransform(btTransform(btQuaternion(btVector3(0,0,1),btRadians(rotation.X)),btVector3(0.0,0,0)));
	Physics::allRigidBodies[0]->setWorldTransform(btTransform(btQuaternion(btVector3(1,0,0),btRadians(rotation.Z)),btVector3(0,0,0)));
Basically, as I change rotation.X,Y and Z, it still only rotates along the world axis after rotation. Is there an easier way of being able to rotate thru local space?


edit: that code doesn't work at all :/ Any easy way of rotating an object? (this is with no gravity)
User avatar
Yann
Posts: 52
Joined: Wed Sep 28, 2011 8:36 am
Location: France

Re: Quaternion local rotations

Post by Yann »

Depends what you want to do exactly ;)
Your object may be working in kinematic mode only (which mean physic will have no effect on the object, but the object may have effects on other physic objects). In this case, your have to initialize it as a kinematic object:

Code: Select all

_dynamicRigidBody->setCollisionFlags( _dynamicRigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
_dynamicRigidBody->setActivationState(DISABLE_DEACTIVATION);
And at runtime, set the correct orientation using the motion state:

Code: Select all

btTransform transform;
transform.setOrigin(convert(touchEntity().getPosition()));
transform.setRotation(convert(touchEntity().getEntityRole()->touchTransformation().getQuaternion()));
_motionState->setWorldTransform(transform);
Or you may want to apply an impulse torque on your body, that's if you don't need to precisely control your object's rotation. You may have a look at the btRigidBody::applyTorque (const btVector3 &torque) method.

An other option is to use a constraint to precisely control the orientation of your body, as it's done in the bullet samples with the mouse right click (have a look at them).