PDA

View Full Version : gluLookAt up Vector cross product



macsam
06-10-2017, 09:04 AM
Hi,

in the example for gluLookAt it has
gluLookAt( 4.0,2.0, 1.0, 2.0, 4.0, -3.0, 2.0, 2.0, -1.0)

The Up vector 2.0, 2.0, -1.0 is the cross product of 4.0,2.0, 1.0, and 2.0, 4.0, -3.0

I get the cross product to be 10, 14, 12

help!

MacSam

Dark Photon
06-10-2017, 09:27 AM
What are you trying to accomplish? What you're doing doesn't make sense.

Check out the man page: gluLookAt (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml)


void gluLookAt( GLdouble eyeX,
GLdouble eyeY,
GLdouble eyeZ,
GLdouble centerX,
GLdouble centerY,
GLdouble centerZ,
GLdouble upX,
GLdouble upY,
GLdouble upZ );


The first 3 parameters define a position (in WORLD space).
The 2nd 3 parameters define a position (in WORLD space).
The 3rd 3 parameters define a vector (in WORLD space).

Take (center - eye), normalize it, and you've defined a unit vector pointing "forward" in EYE-SPACE (i.e. the direction your camera is looking). However, to define a coordinate space transform, this is unconstrained. You need to know what direction is "up" and what is "right". The "up" parameters give you the former, and the right-hand rule (the cross product you mention) implicitly gives you the latter.

If you're determined to apply the cross product here, try:


forward_vec = normalize( center - eye ); // This is the eye-space -Z axis (in WORLD space)
up_vec = normalize( up ); // This is the eye-space +Y axis (in WORLD space)
right_vec = cross( forward_vec, up_vec ); // This is the eye-space +X axis (in WORLD space)