View Full Version : Camera - calculating direction, up and right vectors

Achilles4689

06-02-2011, 02:37 AM

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

SteveBaker

06-03-2011, 08:04 AM

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)

Achilles4689

06-03-2011, 08:53 PM

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?

SteveBaker

06-05-2011, 05:45 PM

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!

bloodtoes

10-13-2011, 03:56 PM

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.

Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.