Public Group

# Converting vectors to rotation angles

This topic is 2475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everybody.

I'm trying to create a game where objects can freely rotate, but direction must still be kept track of.
So the abstract object has three vectors: position, up and direction.
To display the actual model I'm using Euler angles, and the three glRotate() calls.

My question is, how do I convert the vectors I'm using to the right angles for the X, Y, and Z rotation axes?
I read a bit about Gimbal lock but I'm too dumb to make sense of it. Same goes for Quaternions.

##### Share on other sites

Hello everybody.

I'm trying to create a game where objects can freely rotate, but direction must still be kept track of.
So the abstract object has three vectors: position, up and direction.
To display the actual model I'm using Euler angles, and the three glRotate() calls.

My question is, how do I convert the vectors I'm using to the right angles for the X, Y, and Z rotation axes?
I read a bit about Gimbal lock but I'm too dumb to make sense of it. Same goes for Quaternions.

 angle= atan2(y, x); // Returns angle on z axis 

just substitute x,y with x,z and y,z for other axes.

##### Share on other sites
 angle= atan2(y, x); // Returns angle on z axis just substitute x,y with x,z and y,z for other axes.

Thanks!

One note, the result from atan2 must be multiplied by 180/PI because the function returns radians not degrees.
And then there are the special cases.

##### Share on other sites

Hello everybody.

I'm trying to create a game where objects can freely rotate, but direction must still be kept track of.
So the abstract object has three vectors: position, up and direction.

a.k.a. a matrix. (although you'll need to use the cross product to create the 3rd rotation axis).

To display the actual model I'm using Euler angles, and the three glRotate() calls.

Which is a mistake. You have a matrix, so use glMultMatrixf instead.

My question is, how do I convert the vectors I'm using to the right angles for the X, Y, and Z rotation axes?

Don't do that. Use the matrix you've already defined. Simply accumulate additional rotations via matrix multiplication. Rotating the object globally/locally depends on whether you pre/post multiply.

I read a bit about Gimbal lock but I'm too dumb to make sense of it.

The premise is simple: Euler angle (triplets) don't work.

You don't need them though. You already have a matrix....

[color="#000000"]angle = atan2(y, x);// Returns angle on z axis
just substitute x,y with x,z and y,z for other axes.
[/quote]

That does not take into account the changing coordinate frame caused by accumulating 3 rotations. For a correct code sample, have a hunt for the Ken Shoemake code that converts from quats to eulers (which goes via a matrix). I wouldn't recommend that for this specific example though.....

##### Share on other sites

[quote name='ypsilon' timestamp='1320658872' post='4881330']
My question is, how do I convert the vectors I'm using to the right angles for the X, Y, and Z rotation axes?

Don't do that. Use the matrix you've already defined. Simply accumulate additional rotations via matrix multiplication. Rotating the object globally/locally depends on whether you pre/post multiply.
[/quote]

Well I do have an OpenGL-compatible Matrix class but it is part of "stolen" code, so I underestimated its worth.

Could you please post a schematic piece of code which shows how to use the matrix to rotate an object, if the object's vectors are known?

##### Share on other sites
For ready C++ code for 3x3 matrix <-> Euler triplet conversions in different Euler conventions, see MathGeolib's source code. These snippets follow Dave Eberly's formulations at GeometricTools.com.

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 14
• ### Forum Statistics

• Total Topics
632155
• Total Posts
3004477

×