I'm struggling with a problem, where I want to rotate my character object in the Y-Direction. I have a horizontal angle from the camera and I want to get the Y-rotation of the object parallel to the Y-rotation of the camera.
Firstly, I obtain the quaternion from the object with:
Code: Select all
btTransform tr;
body->getMotionState()->getWorldTransform(tr);
btQuaternion quat = tr.getRotation();
Code: Select all
btVector3 euler;
QuaternionToEulerXYZ(quat, euler);
Code: Select all
btQuaternion quat2;
quat2.setEulerZYX(euler.getZ(), euler.getY(), euler.getX());
tr.setRotation(quat3);
body->setWorldTransform(tr);
But, I need something like this: (I'm passing the horizontalAngle of the camera, instead of the old Y-value)
Code: Select all
quat2.setEulerZYX(euler.getZ(), horizontalAngle, euler.getX());
Code: Select all
quat2.setEulerZYX(0, horizontalAngle, 0);
The problem is, that when the horziontal angle is between 90° and 270° it start's to flip. So if the horziontal angle is 180° the object is rotating every draw call by 180°.
How can I solve this problem? I think I'm misunderstanding something with the Euler degrees. When I'm reading out the degrees, they are always between 0° - 90°.
My basic assumption is, that I just pass the horizontalAngle of the camera to my object, so it always stays parallel.
Best regards,
mathew