Docsity

Understanding the Camera Frame and View Matrix in Computer Graphics, Study notes of Computer Graphics

Partial preview of the text

Download Understanding the Camera Frame and View Matrix in Computer Graphics and more Study notes Computer Graphics in PDF only on Docsity!

Computer Graphics

CS 470

Computer Science and Electrical Engineering Dept.

West Virginia University

24th September 2007

Outline

(^1) The camera frame

(^2) The gluLookAt function

The camera frame

The view matrix

The view matrix transforms points/vectors from world coordinates to camera

coordinates. When the view matrix consists of only rotations and translations,

the matrix has a special interpretation:

V =

rx ry rz v 14

ux uy uz v 24

− lx − ly − lz v 34

0 0 0 1

where r =right, u =up and l =look vector in world coordinates.

Keep in mind that these unit vectors are mutually orthogonal.

r · r = 1 , u · u = 1 , l · l = 1

r · u = 0 , u · l = 0 , l · r = 0

The camera frame

The view matrix

Transforms the world-space right vector to (1,0,0,0).

Vr =

rx ry rz v 14

ux uy uz v 24

− lx − ly − lz v 34

0 0 0 1

rx

ry

rz

0

r · r

u · r

− l · r

0

Transforms the world-space up vector to (0,1,0,0).

Vu =

rx ry rz v 14

ux uy uz v 24

− lx − ly − lz v 34

0 0 0 1

ux

uy

uz

0

r · u

u · u

− l · u

0

The camera frame

Getting the look, right and up vectors from OpenGL

While the current transformation matrix contains the view matrix, execute:

float matrix[16];

glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

float Right[3] = {matrix[0], matrix[4], matrix[8]};

float Up[3] = {matrix[1], matrix[5], matrix[9]};

float Look[3] ={-matrix[2],-matrix[6],-matrix[10]};

Remember: the matrix is stored in column order.

Why would you want these vectors?

The camera frame

Getting the look, right and up vectors from OpenGL

While the current transformation matrix contains the view matrix, execute:

float matrix[16];

glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

float Right[3] = {matrix[0], matrix[4], matrix[8]};

float Up[3] = {matrix[1], matrix[5], matrix[9]};

float Look[3] ={-matrix[2],-matrix[6],-matrix[10]};

Remember: the matrix is stored in column order.

Why would you want these vectors?

Camera control:

Move forward : move in look direction.

Look left/right : rotate about up vector.

Look up/down : rotate about right vector.

Roll or tilt view : rotate about look vector.

The gluLookAt function

gluLookAt

gluLookAt constructs the view matrix, V , from look, right and up vectors.

F =

atX − eyeX

atY − eyeY

atZ − eyeZ

 (^) , l =

F

|| F ||

U =

upX

upY

upZ

 , U ′^ =

U

|| U ||

r = l × U

′ , u = r × l

gluLookAt is equivalent to

glMultMatrixf(V);

glTranslated (-eyex, -eyey, -eyez);

The gluLookAt function

Incremental rotations

glLoadIdentity();

for(int i = 0, i<10000, 1++)

{

glRotatef(360.0f/10000, 0.0f, 0.0f, 1.0f);

}

What is the resulting transformation matrix?

The gluLookAt function

Matrix orthogonalization

Goal : Make the rows (or columns) of a rotation matrix orthogonal and

normalized again.

l ←

l || l ||

u ←

u || u ||

r ← l × u

u ← r × l

This is the same process used by gluLookAt().

Also see Gram-Schmidt orthogonalization process in Appendix.