Hello every bodies.
My application is :
a simple box turning around the Y axe. ( setAngularVelocity )
My problem is when i get the orientation or the rotation of the body, normaly the rotation is 1 to 360.
When i rotate it around x or z axe. there is no problem.
But with the Y axe, it just arrive 90 and come back to 0 or jump to 270 ( it is disordered ), and the axes x and z became 180.
The question is : why , and how can i avoid it.
rotation in bullet
-
- Posts: 2
- Joined: Tue May 19, 2009 7:22 am
- Location: Pretoria
Re: rotation in bullet
Hi. Did you manage to find out the cause because I happen to be experiencing the same problem?
-
- Posts: 47
- Joined: Tue Dec 09, 2008 10:12 am
Re: rotation in bullet
My code is not the cause of the probleme. I am sure that my code is 100% correct, However, I créated a simple function whiwh can normalize the rotation.
rotfrom must be in radians. And rotto will be in degrees.
I am not sure that the function will run with your probleme, because this function needs a body who only rotate around the Y axe.
Code: Select all
void normalizeRotation(vector3df rotfrom, vector3df &rotto )
{
if (rotto.Y<180 && rotfrom.X*180/3.14159<170) rotto.Y = rotfrom.Y*180/3.14159;
if (rotfrom.X*180/3.14159>90) rotto.Y = 90 + (90-rotfrom.Y*180/3.14159) ;
if (rotto.Y>=269 && rotto.Y<=360) rotto.Y = 270+(90+rotfrom.Y*180/3.14159) ;
if (rotto.Y>=360) rotto.Y-=360;
if (rotto.Y<0) rotto.Y+=360;
}
I am not sure that the function will run with your probleme, because this function needs a body who only rotate around the Y axe.
-
- Posts: 2
- Joined: Tue May 19, 2009 7:22 am
- Location: Pretoria
Re: rotation in bullet
Ok, thank you. Actually, my problem was that I was getting the Euler angles representing the rotation of the object using the btMatrix3x3::getEulerZYX where the 3x3 matrix is the basis/rotation/direction cosine matrix of the object’s world transform. Something along the lines of the following:
This results in the jumps you mentioned.
I actually wanted the Euler angles in ZXY order. It is possible to use the direction cosine matrix to get the Euler angles in whatever order you require (XYZ, XZY, ZXY e.t.c). In my case this can be achieved as follows:
This should also work in your case and the y rotation will range from -pi to pi radians. Different orders of rotation require different calculations.
I am experimenting with bullet by integrating it in a framework that uses a left hand coordinate system and bullet uses a right hand coordinate system so I have to convert all positions/rotations/transformation matrices between the two.
Code: Select all
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
btMatrix3x3 rot;
rot.setIdentity();
rot = trans.getBasis();
rot.getEulerZYX(fAngZ, fAngY, fAngX);
I actually wanted the Euler angles in ZXY order. It is possible to use the direction cosine matrix to get the Euler angles in whatever order you require (XYZ, XZY, ZXY e.t.c). In my case this can be achieved as follows:
Code: Select all
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
btScalar m[16];
trans.getOpenGLMatrix(m);
fAngZ = atan2f(m[1], m[5]);
fAngY = atan2f(m[8], m[10]);
fAngX = -asinf(m[9]);
I am experimenting with bullet by integrating it in a framework that uses a left hand coordinate system and bullet uses a right hand coordinate system so I have to convert all positions/rotations/transformation matrices between the two.