180 likes | 199 Views
Learn how the gluLookAt() function creates the view matrix for transforming world coordinates to eye coordinates. Discover the importance of calling gluLookAt() before model transformations to impact the scene. Dive into the Eye Coordinate System and the mathematical calculations involved in determining u, v, and n vectors. Explore how the view matrix transforms the camera's coordinate system using u, v, and n vectors.
E N D
The View Matrix Lecture 21 Fri, Oct 17, 2003
The View Matrix • The function gluLookAt() creates a matrix representing the transformation from world coordinates to eye coordinates. • This is called the view matrix. • The model matrix is the one that places the objects in position in world coordinates.
The View Matrix • The current transformation is post-multiplied by the matrix created by gluLookAt(). • For this reason, gluLookAt() should be called before the model transformations, such as rotating or translating individual objects. • Thus, it will affect the entire scene.
The Eye Coordinate System • The matrix created by the gluLookAt() function transforms world coordinates system into eye, or camera, coordinates. • Let the vectors u, v, n be the unit vectors of the eye coordinate system (corresponding to i, j, k in the world coordinate system).
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 • We will base our calculations on the facts that • i j = k • j k = i • k i = j • |i| = |j| = |k| = 1. • Therefore, we should end up with • u v = n • v n = u • n u = v • |u| = |v| = |n| = 1.
The Eye Coordinate System • Form the normalized vector n = (E – L)/|E – L|. up E n L
The Eye Coordinate System • The vector u must be perpendicular (and to the right) of n. • Define u to be the unit vector u = (upn)/|upn|. up E n u L
The Eye Coordinate System • We cannot assume that up is perpendicular to n. • Therefore, let v be the unit vector v = (nu)/|nu| up v E n u L
The View Matrix • The coordinate system of the camera is determined by u, v, n. • The view matrix V must transform u, v, n into i, j, k. • Vu = i • Vv = j • Vn = k
The View Matrix • We know from an earlier discussion that this means that the view matrix will be of the form 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) = –ue • b = –(vxex + vyey + vzez) = –ve • c = –(nxex + nyey + nzez) = –ne where e = E – O.
The View Matrix • Therefore, the matrix created by gluLookAt() is V =
The View Matrix • Verify that V transforms the points • E (0, 0, 0) • E + u (1, 0, 0) • E + v (0, 1, 0) • E + n (0, 0, 1)
Example • LookMover.cpp • mesh.cpp • Remove the call to gluLookAt(). • Translate the cone 5 units in the negative z-direction. • Reinstate gluLookAt(). • Change the up vector.
Example: Modelview Matrix • Let eye = (10, 5, 5), look = (0, 5, 0), up = (1, 1, 0). • Then • eye – look = (10, 0, 5). • n = (2, 0, 1)/5. • up n = (1, -1, -2)/5. • u = (1, -1, -2)/6. • v = n u = (1, 5, -2)/30.
Example: Modelview Matrix • Also • e = eye – O = (10, 5, 5). • –eu = -5/6. • –ev = 25/30. • –en = 25/5.
Example: Modelview Matrix • Therefore, the view matrix is