The View Matrix Lecture 20 Mon, Oct 24, 2005
The View Matrix The view matrix is the matrix that transforms the world coordinates into the camera coordinates. For this reason, gluLookAt() should be called before the model transformations, such as rotating or translating individual objects, so that it will affect the entire scene.
The View Matrix The function gluLookAt() creates the view matrix and multiplies it by the current matrix on the modelview stack. The parameters to gluLookAt() are The eye point E, The look point L, The up vector up.
The uvn Camera Coordinate System In the camera coordinate system, the camera is Located at the origin Looking in the negative z-direction. Let the vectors u, v, and n be unit vectors in the x-, y-, and z-directions in the camera coordinate system. We will calculate u, v, and n from E, L, and up.
The Eye Coordinate System Let E be the eye position, L the look point, and up the up vector. up E L
The Eye Coordinate System Define N = E – L and n = N/|N|. E L up n N
The Eye Coordinate System The vector u must be perpendicular (and to the right) of n. Define U = up n and u = U/|U|. up E L n u
The Eye Coordinate System We cannot assume that up is perpendicular to n. Therefore, let v be the unit vector v = n u. up E L n u v
The View Matrix The coordinate system of the camera is determined by u, v, and n. The view matrix V must transform u, v, n into i, j, k: Vu = i Vv = j Vn = k
The View Matrix Therefore, the view matrix will be of the form ux uy uz a vx vy vz b nx ny nz c 1 V = for some values of a, b, and c.
The View Matrix To determine a, b, and c, use that fact that V also transforms E to the origin: VE = O. Thus, a = -(uxex + uyey + uzez) = -u e b = -(vxex + vyey + vzez) = -v e c = -(nxex + nyey + nzez) = -n e where e = E – O.
The View Matrix Therefore, the matrix created by gluLookAt() is ux uy uz -u e vx vy vz -v e nx ny nz -n e 1 V =
The View Matrix Verify that V transforms the points E (0, 0, 0) = O E + u (1, 0, 0) = i E + v (0, 1, 0) = j E + n (0, 0, 1) = k
Example Let E = (10, 5, 5), L = (0, 5, 0), and up = (1, 1, 0). Then N = E – L = (10, 0, 5). n = N/|N| = (2, 0, 1)/5. U = up n = (1, -1, -2)/5. u = U/|U| = (1, -1, -2)/6. v = n u = (1, 5, -2)/30.
Example Also e = E – O = (10, 5, 5). -e u = -5/6. -e v = 25/30. -e n = 25/5.
Example Therefore, the view matrix is V = 1/6 -1/6 -2/6 -5/6 1/30 5/30 -2/30 25/30 2/5 0/5 1/5 25/5 1 V =
Example Read Run
Flying the Camera – Constant Speed Read Run
Flying the Camera – Acceleration Read Run
The Camera Class camera.h camera.cpp