PDA

View Full Version : Rotate a vector about a vector



Terl_JV
01-11-2004, 09:23 PM
A simpel flight simulator using roll, pitch and yaw.

I need to rotate an object in its locale coordinates (local space).

Then I must rotate a vector about a perpendicular vector:
Maybe using glRotatef(angle, u1, u2, u3)
Where u1,u2,u3 is the local Y axis of an object, its initial values are u=(0, 1, 0).
Then somehow extract the rotated vector from
the current matrix?

Do you have an idea?
Thanks!

jebus
01-14-2004, 04:44 AM
one way would be to create a rotation matrix.
example:


<xyz> is the rotation axis
angle is the rotation amount in radians
c = cos(angle);
s = sin(angle);
t = 1.0 - c;

| (tx + c) (txy - sz) (txz + sy) |
M = | (txy + sz) (ty + c) (tyz - sx) |
| (txz - sy) (tyz + sx) (tz + c) |

in the above example, the rotation matrix M is built using the rotation axis <xyz> and the rotation angle. to rotate a vector around <xyz> by the angle given just multiply that vector by this matrix.

this technique has it's roots in quaternions. this implementation can be wrapped up nicely in a function that takes in the angle and vector and outputs the rotation matrix. we use this technique to rotate the objects in our engine.

[This message has been edited by jebus (edited 01-14-2004).]

Terl_JV
01-15-2004, 07:40 AM
Thank you for showing the matrix function of the glRotatef(angle, x, y, z).

Now I know how rotate about a free axis.