Rotation angle on z axis.

FieryRich
Posts: 3
Joined: Mon Nov 26, 2007 5:37 pm

Rotation angle on z axis.

Post by FieryRich »

How can I get the angle of rotation on the z axis in radians from an object?
i.e. as if it were in 2D so no rotation in x and y axis.
I've tried using the getAngle method but it only ever returns a value between 0 and pi.

Code: Select all

                float angle = bt_body->getWorldTransform().getRotation().getAngle();
hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

Re: Rotation angle on z axis.

Post by hiker »

Hi,

I think you want to do something similar to what I described in http://www.bulletphysics.com/Bullet/php ... f=9&t=1720: getting the current heading. While I couldn't get the quaternion approach to work, using the matrix as described in the thread should work (btw, getAngle returns the angle of the rotation quaternion only, not necessarily the rotation around the Z axis).

Hth
Joerg
FieryRich
Posts: 3
Joined: Mon Nov 26, 2007 5:37 pm

Re: Rotation angle on z axis.

Post by FieryRich »

Yeah that might be better. I'll try it out.

I was zeroing the x and y parts of the quaternion so getAngle() should have been giving the rotation angle in only the z axis? Is that right?? :?
hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

Re: Rotation angle on z axis.

Post by hiker »

Hi,

while I am not an expert on quaternions, I don't think that zeroing out the x/y parts of a quaternion will return the heading - assuming that you did something like q.setX(0.0f), q.setY(0.0); q->getAngle() . If you did something different, e.g. multiplying in an inverse rotation which cancels out the x,y parts, you would have to post your code.
Just imagine a rotation around (1.0, 0.0, 0, PI/2) with X-axis=right, y=forward, z=up. This rotation has no heading component (it's just changing the pitch, i.e. the objects is pointing up), but getAngle() (after zeroing x/y) would still return PI/2 (instead of 0). Even worse: rotating around (1.0, 0, PI) would mean the object is pointing backwards (so heading is changed to 180 degrees), but upside down. So I don't think that your approach would work.

The way I have described work as expected (when using the matrix, not the quaternion, see my question in the thread) to steer a kart around a racing course :)

Best regards,
Joerg