Results 1 to 5 of 5

Thread: Camera - calculating direction, up and right vectors

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    13

    Camera - calculating direction, up and right vectors

    I find myself in need of calculating the direction, up and right vectors of a camera. I need the actual vectors and not just use a gluLookat function. Does anyone know how to calculate these?

    Thanks,
    Achilles

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Camera - calculating direction, up and right vectors

    Maybe this old FAQ of mine will help:

    http://www.sjbaker.org/steve/omniv/matr ... iends.html

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    13

    Re: Camera - calculating direction, up and right vectors

    Thanks Steve. Part of my problem may come from the fact that my matrix library (glMatrix-0.9.6) defines matrices to be of the form

    m0 m1 m2 m3
    m4 m5 m6 m7
    m8 m9 m10 m11
    m12 m13 m14 m15

    Where m12 = x position m13 = y position and m14 = z position.

    So if I wanted to pull out my direction, up and right vectors from the view matrix how would I do this?

  4. #4
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Camera - calculating direction, up and right vectors

    For a simple rotate/translate matrix:

    m12/13/14 is the XYZ of the translation.
    m0/1/2 is the X vector
    m4/5/6 is the Y vector
    m8/9/10 is the Z vector

    ...if you have scales or shears or perspective in your matrix - then you have a bigger problem!

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    2

    Re: Camera - calculating direction, up and right vectors

    CameraUp = CameraMatrix * vec4(0,1,0,0)
    CameraRight = CameraMatrix * vec4(1,0,0,0)
    CameraForward = CameraMatrix * vec4(0,0,-1,0)

    Not the most efficient method, but it works. If you worked out the math, shortcuts could probably be found.

Similar Threads

  1. [Camera] Can't make the camera move appropriately
    By onion_bread in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 12-01-2011, 07:36 PM
  2. Replies: 1
    Last Post: 11-30-2011, 03:49 PM

Posting Permissions

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