Download presentation
Presentation is loading. Please wait.
1
The View Matrix Lecture 20 Mon, Oct 24, 2005
2
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.
3
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.
4
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.
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
Define N = E – L and n = N/|N|. E L up n N
7
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
8
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
9
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
10
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.
11
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.
12
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 =
13
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
14
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.
15
Example Also e = E – O = (10, 5, 5). -e u = -5/6. -e v = 25/30.
-e n = 25/5.
16
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 =
17
Example Read Run
18
Flying the Camera – Constant Speed
Read Run
19
Flying the Camera – Acceleration
Read Run
20
The Camera Class camera.h camera.cpp
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.