1 / 18

The View Matrix

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.

engles
Download Presentation

The View Matrix

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The View Matrix Lecture 21 Fri, Oct 17, 2003

  2. 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.

  3. 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.

  4. 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).

  5. The Eye Coordinate System • Let E be the eye position, L the look point, and up the up vector. up E L

  6. 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.

  7. The Eye Coordinate System • Form the normalized vector n = (E – L)/|E – L|. up E n L

  8. The Eye Coordinate System • The vector u must be perpendicular (and to the right) of n. • Define u to be the unit vector u = (upn)/|upn|. up E n u L

  9. The Eye Coordinate System • We cannot assume that up is perpendicular to n. • Therefore, let v be the unit vector v = (nu)/|nu| up v E n u L

  10. 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

  11. 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.

  12. 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.

  13. The View Matrix • Therefore, the matrix created by gluLookAt() is V =

  14. 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)

  15. 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.

  16. 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.

  17. Example: Modelview Matrix • Also • e = eye – O = (10, 5, 5). • –eu = -5/6. • –ev = 25/30. • –en = 25/5.

  18. Example: Modelview Matrix • Therefore, the view matrix is

More Related