views:

261

answers:

3

hello, i have an object in 3d space that i want to align according to a vector. i already got the Y-rotation out by doing an atan2 on the x and z component of the vector. but i would also like to have an X-rotation to make the object look downwards or upwards.

imagine a plane that does it's pitch yaw roll, just without the roll.

i am using openGL to set the rotations so i will need an Y-angle and an X-angle.

+1  A: 

Actually...take a look at this article. It describes Euler Angles which I believe is what you want here.

Pace
yep, i have already found that article too. i will study it more deeply. thanks!
clamp
+1  A: 

I would not use Euler angles, but rather a Euler axis/angle. For that matter, this is what Opengl glRotate uses as input.

If all you want is to map a vector to another vector, there are an infinite number of rotations to do that. For the shortest one, (the one with the smallest angle of rotation), you can use the vector found by the cross product of your from and to unit vectors.

axis = from X to

from there, the angle of rotation can be found from from.to = cos(theta) (assuming unit vectors)

theta = arccos(from.to)

glRotate(axis, theta) will then transform from to to.

But as I said, this is only one of many rotations that can do the job. You need a full referencial to define better how you want the transform done.

Bahbar
+3  A: 

You should use some form of quaternion interpolation (Spherical Linear Interpolation) to animate your object going from its current orientation to this new orientation.

If you store the orientations using Quaternions (vector space math), then you can get the shortest path between two orientations very easily. For a great article, please read Understanding Slerp, Then Not Using It.

If you use Euler angles, you will be subject to gimbal lock and some really weird edge cases.

Frank Krueger