• Advertisement
Sign in to follow this  

Converting vectors to rotation angles

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

If you intended to correct an error in the post then please contact us.

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.

Thanks for reading.

Share this post


Link to post
Share on other sites
Advertisement

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.

Thanks for reading.



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


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement