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: Newbie Question - Direction

  1. #1
    Junior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Newbie Question - Direction

    I have been searching everywhere for this but just cannot get it.

    I need to get the direction vector that my view is facing.

    I know my current x, y and z position and the angles of rotation on the x and y axis.

    But I just cannot get the vector of which way I am facing. I need the vector in x,y,z form so that I can simulate throwing an object.

    Thankyou

  2. #2
    Junior Member Regular Contributor
    Join Date
    Sep 2003
    Location
    Ireland
    Posts
    136

    Re: Newbie Question - Direction

    In this thread,

    http://www.opengl.org/discussion_boa...327;p=1#000006

    I posted the following code,

    void cj3DMTO_CSystemToCameraMatrix(cj3DMTO_cSystem4v *subject, cj3DMTO_OGLMatrix result)
    {
    result[0]=(subject->X).x;
    result[1]=(subject->Y).x;
    result[2]=(subject->Z).x;
    result[3]=0.0;

    result[4]=(subject->X).y;
    result[5]=(subject->Y).y;
    result[6]=(subject->Z).y;
    result[7]=0.0;

    result[8]=(subject->X).z;
    result[9]=(subject->Y).z;
    result[10]=(subject->Z).z;
    result[11]=0.0;

    result[12]=-dotProduct(subject->X,subject->O);
    result[13]=-dotProduct(subject->Y,subject->O);
    result[14]=-dotProduct(subject->Z,subject->O);
    result[15]=1.0;
    }

    which is a function that takes a camera class (an origin and three axes at right angles to each other) and creates a modelview transform so that the world is seen from the point of view of the camera.

    This works fine.

    I'd suggest that you could treat the modelview matrix as your viewing transform, and simply do the reverse of the above code, ie. obtain a copy of the matrix into an array of floats, and then treat entries {2,6,10} as a vector describing your view direction.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2003
    Location
    Ireland
    Posts
    136

    Re: Newbie Question - Direction

    PS -

    1) I'm assuming that you set up the modelview matrix with standard opengl commands, instead of slotting in your own as I do.

    2) You might need to normalize, and/or negate, the resulting view vector, before it's useful.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Sep 2003
    Location
    Ireland
    Posts
    136

    Re: Newbie Question - Direction

    PPS - if you have a camera that isn't allowed to rotate around z (like in Quake, ie yaw around world Y axis, then pitch around camera's yawed X axis), then there's a simpler way, involving trigonometry.

  5. #5
    Junior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Re: Newbie Question - Direction

    Thanks, I had looked into using the Modelview Matrix, but was using the wrong entries

Posting Permissions

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