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

Thread: Pointing your model in the correct direction?

  1. #1
    Member Regular Contributor
    Join Date
    Nov 2000
    Posts
    409

    Pointing your model in the correct direction?

    I am using a matrix (m[16]) to hold all data, and my problem is I don't know how to point the model in the correct direction. In this case, I have a missile, which has 6DOF, and it was fired from a ship that also has 6 DOF.

    Is there a simple way to point the missile in the direction it is heading? At first I tried to use m[2],m[6],m[10], since that is dirX,dirY,dirZ, but that didn't work all the time, that only works when the missile is fired down the Z axsis.

    Any pointers to this?

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Karlsruhe, Germany
    Posts
    486

    Re: Pointing your model in the correct direction?

    try using euler angles!

    given the desired rotation for the current frame in angles, you convert these angles to a matrix. Then you multiply this newly created matrix by the object's matrix.

    Additionally you can create a new identity matrix and set it's 12, 13 and 14th elements to the x, y and z position change for the frame and multiply this matrix by the object's matrix. This will change the object's translation in the object space.

    If you want i can send you some code(just mail me), while its not exactly what you want (I have a camera class) it does the same thing, except that it puts the inverted matrix on an opengl's modelview matrix stack.

    -Lev
    levp@gmx.net

  3. #3
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Damascus, Syria
    Posts
    147

    Re: Pointing your model in the correct direction?

    Are you sure m[2],m[6],m[10] is the direction of your missle. I'm using m[4],m[5],m[6] and I think it's working.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: Pointing your model in the correct direction?

    It depends upon the type of matrix being used, and the orientation of the object in object space.

  5. #5
    Member Regular Contributor
    Join Date
    Nov 2000
    Posts
    409

    Re: Pointing your model in the correct direction?

    I just noticed something, I was looking at this:
    Code :
     Xx Yx Zx Tx
     Xy Yy Zy Ty
     Xz Yz Zz Tz
     0   0   0   1
    and then I have seen this:
    Code :
    Xx Xy Xz Tx
    Yx Yy Yz Ty
    Zx Zy Zz Tz
    0  0  0  1
    Which both map to
    Code :
    0 4 8  12
    1 5 9  13
    2 6 10 14
    3 7 11 15
    The first matrix is correct right?

    As for euler angles, the problem is the gimbal lock, so I switched to quaternion + matrix, which doesn't have gimbal lock.

    I am checking out the source code now Lev, thanks again.




    [This message has been edited by Elixer (edited 01-22-2001).]

  6. #6
    Member Regular Contributor
    Join Date
    Oct 2000
    Location
    USA
    Posts
    322

    Re: Pointing your model in the correct direction?

    As far as I know, the reason it does work to simply set the "front" vector portion of the matrix is because you also need a correct "up" vector and "right" vector to go with it. Get the vector to what you're wanting the missile to look at (destinationPosition - missilePosition) then nomralise it and stick it in your "front" vector portion of your matrix. If you set the front vector, then make an assumption about the "up" vector (like up the positive Y axis - 0,1,0 or get it from whatever launched the missile), then get the crossproduct of these two to get a vector that is at a right angle to both of these to obtain your "right" vector. Then, go back and do a crossproduct on your front and right vectors to get the correct up vector. That should complete your matrix. It should now be pointing in the desired direction.

Posting Permissions

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