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 4 of 4

Thread: Help! Converting Angles to Vectors

  1. #1
    Intern Contributor
    Join Date
    Jun 2000
    Posts
    67

    Help! Converting Angles to Vectors

    I'm trying to get a set of normalized vectors ( forward, right, up ) from the current camera angles ( yaw, pitch, roll ) and am having some problems. I found some code to do this in the Quake I source code, but it doesn't quite seem to work because the Y and Z axis are swapped in Quake ( Z is up ) relative to how they would be in OpenGL ( Y is up ) My math skills aren't great, so perhaps the solution is easy??

    Here's the Quake code if that will help:

    void AngleVectors( vec3_t ang, vec3_t fwd, vec3_t right, vec3_t up) {
    float angle;
    float sr, sp, sy, cr, cp, cy;

    angle = ang[YAW] * (M_PI*2/360);
    sy = sin(angle);
    cy = cos(angle);
    angle = ang[PITCH] * (M_PI*2/360);
    sp = sin(angle);
    cp = cos(angle);
    angle = ang[ROLL] * (M_PI*2/360);
    sr = sin(angle);
    cr = cos(angle);

    if( fwd ) {
    forward[0] = cp*cy;
    forward[1] = cp*sy;
    forward[2] = -sp;
    }
    if( right ) {
    right[0] = (-1*sr*sp*cy+-1*cr*-sy);
    right[1] = (-1*sr*sp*sy+-1*cr*cy);
    right[2] = -1*sr*cp;
    }
    if( up ) {
    up[0] = (cr*sp*cy+-sr*-sy);
    up[1] = (cr*sp*sy+-sr*cy);
    up[2] = cr*cp;
    }
    }


    Thanks in advance.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Help! Converting Angles to Vectors

    Just look up an Euler-to-matrix conversion algo; I think there's one in the Hexapod FAQ. The first three columns of the result matrix are the normalized positive X, Y, Z axes.

  3. #3
    Intern Contributor
    Join Date
    Jun 2000
    Posts
    67

    Re: Help! Converting Angles to Vectors

    Thanks, I did a search for hexapod, but didn't exactly find the site you are refering to. Do you happen to have the URL?

    Thanks much.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2000
    Posts
    20

    Re: Help! Converting Angles to Vectors

    Many thanks to anyone who offered tips on how to solve this problem.
    I found the Euler Angles rotation matrix at: http://cadd.cern.ch/cad_geant_int/ddt_long/node11.html

    but I had to do some reworking for it to work?? Anyway, if anyone would like the solution I used, I guess let me know?

    Thanks again!
    El Jefe

Posting Permissions

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