The Industry's Foundation for High Performance Graphics

1. Rotate a vector about a vector

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!

2. Re: Rotate a vector about a vector

one way would be to create a rotation matrix.
example:
Code :
```<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).]

3. Re: Rotate a vector about a vector

Thank you for showing the matrix function of the glRotatef(angle, x, y, z).

Now I know how rotate about a free axis.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•