# 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

Maybe this old FAQ of mine will help:

`` [http://www.sjbaker.org/steve/omniv/matr ... iends.html](http://www.sjbaker.org/steve/omniv/matrices_can_be_your_friends.html)``

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?

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!

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.