Results 1 to 4 of 4

Thread: Drawing object with orientation vector

  1. #1
    Member Contributor
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    93

    Drawing object with orientation vector

    Hi all;
    I have an object (a projectile) that has only a vector as its orientation (no euller angles or quaternions). How can i get the eullers angles to rotate it (i think the Z axis could be 0)? Is there any way to draw it without having to convert that vector? (sorry about my english)
    Thanx

  2. #2
    Guest

    Re: Drawing object with orientation vector

    i dunno if my compute is good but you can
    try this to rotate your vector

    you should use a quaternion and transform it into a 4x4 matrix.
    After multiply the vector by the matrix and the job is done (probably)
    i have posted a stuff about vector*matrix
    have a look on this forum


    if something is wrong correct me.
    see y

    to convert a quaternion into a 4x4 matrix use this

    typedef struct
    {
    GLfloat qx,qy,qz,qw;
    }
    QUAT ;


    //euler to quaternion
    void qAxisToQuat(QUAT *q,float _x,float _y,float _z,float _angle);

    STD void qNormalize(QUAT *q)
    {
    double norm = sqrt((q->qx*q->qx) + (q->qy*q->qy) + (q->qz*q->qz) + (q->qw*q->qw) );

    if (norm==0) return;

    q->qx = (float)q->qx / norm;
    q->qy = (float)q->qy / norm;
    q->qz = (float)q->qz / norm;
    q->qw = (float)q->qw / norm;
    }
    //
    void qAxisToQuat(QUAT *q,float _x,float _y,float _z,float _angle) {
    double rad, scale;

    if (_x==0 && _y==0 && _z==0)
    {
    q->qw= 1.0f;
    q->qx = 0.0f;
    q->qy = 0.0f;
    q->qz = 0.0f;
    return;
    }

    _angle=DEGTORAD(_angle);
    rad = _angle / 2;

    q->qw = (float)cos(rad);

    scale = sin(rad);

    q->qx = (float)_x * scale;
    q->qy = (float)_y * scale;
    q->qz = (float)_z * scale;

    qNormalize(q);
    }
    //quaternion to 4x4 OpenGL matrix
    void qGetMatrix(QUAT *q,float _m[16]) ;

    void qGetMatrix(QUAT *q,float _m[16])
    {
    int i;
    double w2,x2, y2, z2, xy, xz, yz, wx, wy, wz;

    for (i=0;i<16;i++)
    _m[i]=0.0;
    _m[15] = 1;

    x2 = q->qx* q->qx;
    y2 = q->qy*q->qy;
    z2 = q->qz* q->qz;
    w2 = q->qw* q->qw;

    xy = q->qx * q->qy;
    xz = q->qx * q->qz;
    yz = q->qy * q->qz;
    wx = q->qw * q->qx;
    wy = q->qw * q->qy;
    wz = q->qw * q->qz;

    _m[0] = (float)1 - 2*(y2 + z2);
    _m[1] = (float)2 * (xy + wz);
    _m[2] = (float)2 * (xz - wy);

    _m[4] = (float)2 * (xy - wz);
    _m[5] = (float)1 - 2*(x2 + z2);
    _m[6] = (float)2 * (yz + wx);

    _m[8] = (float)2 * (xz + wy);
    _m[9] = (float)2 * (yz - wx);
    _m[10] =(float)1 - 2*(x2 + y2);
    }

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2003
    Location
    Toulouse, France
    Posts
    133

    Re: Drawing object with orientation vector

    from the orientation X, you can compute two orthogonal vectors Y,Z.
    X^Y=Z, Y^Z=X, Z^X=Y
    from X, Y, Z, you can create a rotation matrix (like glu does in gluLookAt) and concatenate it to the modelview matrix.

    to compute Y and Z you can do:
    - choose a temporary vector A (non colinear with X)
    - Z = X ^ A
    - Y = Z ^ X
    - normalize Y and Z

    if X=(x0,x1,x2), Y=(y0,y1,y2), Z=(z0,z1,z2) then the rotation matrix is:

    x0 y0 z0
    x1 y1 z1
    x2 y2 z2

  4. #4
    Member Contributor
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    93

    Re: Drawing object with orientation vector

    Thanx .. it solved my problem...

Similar Threads

  1. Modification of the orientation of normal vector
    By iggBerlin in forum COLLADA
    Replies: 1
    Last Post: 12-02-2009, 10:27 AM
  2. orientation vector
    By qiz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-21-2002, 08:35 AM
  3. data structure for object orientation
    By satan in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-20-2002, 03:21 PM
  4. How to find object orientation?
    By ChrisT in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 05-09-2001, 05:02 AM
  5. How to know the orientation of an object?
    By ChrisT in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-07-2001, 11:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean