Rigidbody rotation angle.

Andrey
Posts: 3
Joined: Sun May 29, 2016 12:50 am

Rigidbody rotation angle.

Post by Andrey »

I rotating a body (btRigidBody) with torque and need to know body's angle:

Code: Select all

body.applyTorque(new Vector3(0, 0, -10));
float rotationZ = body.getWorldTransform().getRotation(new Quaternion()).getAngleAround(0, 0, 1);
Clockwise and counterclockwise rotation returns the same angle, which is greater than null. And angle also can't be greater than 239.9.
Is there any way to obtain correct angle from the body?
Andrey
Posts: 3
Joined: Sun May 29, 2016 12:50 am

Re: Rigidbody rotation angle.

Post by Andrey »

I found that a roll is very close to what I need:

Code: Select all

float rotation = body.getWorldTransform().getRotation(new Quaternion()).getRoll();
But it had a holes at (85, 95) and (-95, -85). On those holes, rotation angle can be obtained through method from my previews post. But for correct angle I need to know the sign (+/-). Any ideas?
Last edited by Andrey on Sun May 29, 2016 4:17 am, edited 1 time in total.
Andrey
Posts: 3
Joined: Sun May 29, 2016 12:50 am

Re: Rigidbody rotation angle.

Post by Andrey »

I found a sign. It called 'gimbalPole'. Finally, the rotation angle can be obtained from quanterion (mRotation) in this way:

Code: Select all

body.getWorldTransform().getRotation(mRotation);
float roll = mRotation.getRoll();
float angle = mRotation.getAngleAround(0, 0, 1);
int gimbalPole = mRotation.getGimbalPole();
float rotation = (gimbalPole == 0) ? roll : angle * gimbalPole;
Obtained rotation will be in range (-180, 180).