







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Computer Science and Electrical Engineering Dept.
West Virginia University
24th September 2007
(^1) The camera frame
(^2) The gluLookAt function
The camera frame
The view matrix transforms points/vectors from world coordinates to camera
coordinates. When the view matrix consists of only rotations and translations,
the matrix has a special interpretation:
rx ry rz v 14
ux uy uz v 24
− lx − ly − lz v 34
0 0 0 1
where r =right, u =up and l =look vector in world coordinates.
Keep in mind that these unit vectors are mutually orthogonal.
r · r = 1 , u · u = 1 , l · l = 1
r · u = 0 , u · l = 0 , l · r = 0
The camera frame
Transforms the world-space right vector to (1,0,0,0).
Vr =
rx ry rz v 14
ux uy uz v 24
− lx − ly − lz v 34
0 0 0 1
rx
ry
rz
0
r · r
u · r
− l · r
0
Transforms the world-space up vector to (0,1,0,0).
Vu =
rx ry rz v 14
ux uy uz v 24
− lx − ly − lz v 34
0 0 0 1
ux
uy
uz
0
r · u
u · u
− l · u
0
The camera frame
While the current transformation matrix contains the view matrix, execute:
float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
float Right[3] = {matrix[0], matrix[4], matrix[8]};
float Up[3] = {matrix[1], matrix[5], matrix[9]};
float Look[3] ={-matrix[2],-matrix[6],-matrix[10]};
Remember: the matrix is stored in column order.
Why would you want these vectors?
The camera frame
While the current transformation matrix contains the view matrix, execute:
float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
float Right[3] = {matrix[0], matrix[4], matrix[8]};
float Up[3] = {matrix[1], matrix[5], matrix[9]};
float Look[3] ={-matrix[2],-matrix[6],-matrix[10]};
Remember: the matrix is stored in column order.
Why would you want these vectors?
Camera control:
Move forward : move in look direction.
Look left/right : rotate about up vector.
Look up/down : rotate about right vector.
Roll or tilt view : rotate about look vector.
The gluLookAt function
gluLookAt constructs the view matrix, V , from look, right and up vectors.
atX − eyeX
atY − eyeY
atZ − eyeZ
(^) , l =
upX
upY
upZ
r = l × U
′ , u = r × l
gluLookAt is equivalent to
glMultMatrixf(V);
glTranslated (-eyex, -eyey, -eyez);
The gluLookAt function
glLoadIdentity();
for(int i = 0, i<10000, 1++)
{
glRotatef(360.0f/10000, 0.0f, 0.0f, 1.0f);
}
What is the resulting transformation matrix?
The gluLookAt function
Goal : Make the rows (or columns) of a rotation matrix orthogonal and
normalized again.
l ←
l || l ||
u ←
u || u ||
r ← l × u
u ← r × l
This is the same process used by gluLookAt().
Also see Gram-Schmidt orthogonalization process in Appendix.