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

Thread: vector rotation

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2003
    Location
    Melbourne,VIC,Australia
    Posts
    23

    vector rotation

    I tried this post in the math/algo forum but I think its down.

    how do I calculate these three vectors:

    x,y,z

    1,0,0
    0,1,0
    0,0,1

    to align with a rotated modelmatrix to allow for relative movement?

    This might help with understanding of question

    I can look around with the mouse:

    void LookAround(float x,float y)//x,y from mouse
    {
    GLfloat MMatrix[16];

    glGetFloatv(GL_MODELVIEW_MATRIX,MMatrix);
    glLoadIdentity();
    glRotatef(sqrt(x*x+y*y)*magicnumber,-y,x,0.0);
    glMultMatrixf(MMatrix);
    }

    multiple LookAround() Functions leads to rotations in all directions not just x and y

    Now I want a funtion that makes me move relative to the new rotation:

    void MoveAround(float x,float y,float z)//get a velocity vector eg: (0,0,1)=1 forward
    {
    GLfloat MMatrix[16];
    float rotatedX,rotatedY,RotatedZ;

    glGetFloatv(GL_MODELVIEW_MATRIX,MMatrix);
    //switch(explanation){
    //case abstract_math:
    //vector matrix math that i don't know, likely full of sin()'s and cos()'s
    //break;
    //case simpler_fuctions:
    //translation manipulation with opengl fuctions such as glRotate() and glMultMatrixf()

    glTranslate(rotatedX,rotatedY,RotatedZ);
    }

    I will probably need those vectors for collision response and rotational bounce or something anyway.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Location
    Belgium
    Posts
    857

    Re: vector rotation

    Math & algorithms is up, I'll move your thread there.

    -- Tom

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2003
    Location
    Melbourne,VIC,Australia
    Posts
    23

    Re: vector rotation

    cheers

    I use:
    void MoveAround(float x,float y,float z)
    {
    GLfloat MMatrix[16];

    glGetFloatv(GL_MODELVIEW_MATRIX,MMatrix);
    glLoadIdentity();
    glTranslatef(x,y,z);
    glMultMatrixf(ModelViewMatrix);
    }

    should I do collision detection from the modelmatrix where collidable things have their own rotation and translation or should I have a geometry thing or a combo?
    should I have object attributes such as location and rotation and then gltranslate()/glrotate() or should I get those attributes from the matrix

  4. #4
    Intern Contributor
    Join Date
    Nov 2000
    Location
    Thuringia, Germany
    Posts
    89

    Re: vector rotation

    if you "just want to move arround":
    why don't you write your own camera-class or something to keep track of the position you are, the look-at and the up-vector?
    you can calculate everything....

    I have my own cam class.

    it has 3 vectors (Position, Look-At and Up)
    and a SetCam-function which calls gluLookAt(pos.x.y.z,look.x.y.z,up.x.y.z)

    to move in the direction you're "looking" calculate:

    I assume:
    p - position, l - lookat, both vectors
    void pseudocode_mode(float distance)
    {
    vector d;
    float distance; // the distance, how far you'll move

    d = l - p;
    d.Normalize()

    d = d*distance;

    p = p+d;
    l = l+d;

    }

    normalisation of vector d:

    float n = d.Length();

    d.x = d.x / n;
    d.y = d.y / n;
    d.z = d.z / n;

    length m of a vector:

    float m = sqrt ( d.x*d.x + d.y*d.y + d.z*d.z );

    hope this helps.

    Greetings
    Bastian

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Hannover, Germany
    Posts
    1,258

    Re: vector rotation

    The rotation matrices contain a rotated coordinate system in the columns if i remember correctly. First column represents current x-Axis in respect to the identity coordinaten system and so on...
    - Michael Steinberg

Posting Permissions

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