Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Rotate a vector about a vector

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2004
    Location
    Humlebaek, Zealand, Denmark
    Posts
    2

    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. #2
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    King George, Virginia
    Posts
    132

    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. #3
    Junior Member Newbie
    Join Date
    Jan 2004
    Location
    Humlebaek, Zealand, Denmark
    Posts
    2

    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
  •