The View Matrix Lecture 21 Fri, Oct 17, 2003. The View Matrix The function gluLookAt() creates a...

Post on 13-Dec-2015

216 views 4 download

Transcript of The View Matrix Lecture 21 Fri, Oct 17, 2003. The View Matrix The function gluLookAt() creates a...

The View Matrix

Lecture 21Fri, 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.

E

L

up

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 vectorn = (E – L)/|E – L|.

E

L

up

n

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

nu

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

Lnu

v

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

ux uy uz a

vx vy vz b

nx ny nz c

0 0 0 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

0 0 0 1

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.cppmesh.cppRemove 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). –e u = -5/6. –e v = 25/30. –e n = 25/5.

Example: Modelview Matrix

Therefore, the view matrix is

1/ 6 -1/ 6 -2/ 6 -5/ 6

1 30 5/30 -2/30 25/30

2/5 0/5 1/5 25/5

0 0 0 1