I'm new working with Bullet Engine.
Actually I'm programing an iPhone game using SIO2 Engine that uses Bullt Engine for physics.
I have a planet (physic object centered in 0,0,0) that I am moving applying torques and I want to put a light that ever iluminate the same face of the planet.
To calculate the position of the light, I obtain the rotations of the planet of this way:
Code: Select all
btTransform _btTransform;
_btTransform.setIdentity();
_btTransform.setFromOpenGLMatrix( _SIO2object->_SIO2transform->mat );
btMatrix3x3 mat = btMatrix3x3(_btTransform.getRotation());
btScalar Yaw, Pitch, Roll;
mat.getEulerYPR(Yaw, Pitch, Roll);
Code: Select all
M1*M2*M3*M4
where
M1 = ( 1, 0, 0, 0
0, cos(Roll), -sin(Roll), 0
0, sin(Roll), cos(Roll), 0
0, 0, 0, 1 )
M2 = ( cos(Pitch), 0, sin(Pitch), 0
0, 1, 0, 0
-sin(Pitch), 0, cos(Pitch), 0
0, 0, 0, 1 )
M3 = ( cos(Yaw), -sin(Yaw), 0, 0
sin(Yaw), cos(Yaw), 0, 0
0, 0, 1, 0
0, 0, 0, 1 )
M4 = ( lightPosition.x
lightPosition.y
lightPosition.z )
The obtained result works great in a lot of cases ever iluminating the same face of the planet, but if I rotate the planet enough to turn it upside down the light goes crazy. When the planet is upside down, when the light should be moving left it's moving right, and when the light should be moving up it's moving down.
I am pretty sure that the matrix are the correct ones (I don't multiply for the position of the planet because it's centered in 0,0,0).
I don't know if the problem is about the transformation matrix, the Roll, Pitch and Yaw values, the sin and cos results or I forbid something.
Anyone have an idea?
Thank you so much!
Sorry for my bad explanation