Download presentation
Presentation is loading. Please wait.
Published byJerome Anderson Modified over 9 years ago
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. E L up
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|. E L up n
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 L n u
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 E L n u v
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 uxux uyuy uzuz a vxvx vyvy vzvz b nxnx nyny nznz c 0001 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 = –(u x e x + u y e y + u z e z ) = –u e b = –(v x e x + v y e y + v z e z ) = –v e c = –(n x e x + n y e y + n z e z ) = –n e where e = E – O.
13
The View Matrix Therefore, the matrix created by gluLookAt() is uxux uyuy uzuz –u e–u e vxvx vyvy vzvz –v e–v e nxnx nyny nznz –n e–n e 0001 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 1/ 6-1/ 6-2/ 6-5/ 6 1 305/ 30-2/ 3025/ 30 2/52/50/50/51/51/525/ 5 0001
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.