Académique Documents
Professionnel Documents
Culture Documents
OpenGL
1
Coordinate Transforms
You should be quite familiar with the matrix representation of
coordinate transformations:
q = Mp
What is happening when we apply a transformation and why refer
to it as a coordinate transformation ?
Consider the following scene:
In fact we could get the gray system (we will call this the
transformed axes or frame of reference) by rotating the original
black system (the original or global axes or frame) about the x
axis by 45 degrees. 2
Now consider a point p(px, py, pz)…
glScalef(2, 2, 2);
glutWireCube(1);
glTranslatef(1, 1, 0);
glutWireCube(1);
glTranslatef
(0, -2, 0)
createCylinder(0.5, 2, 8, 8);
glRotatef(
theta1, 1, 0, 0);
9
Translate down the length of the upper arm,
apply rotation of theta3 (here theta3 is 30 degrees
about –x axis. And draw a cone (as with the
cylinder the Glut Cone is drawn about the z axis).
10
Coordinate Transforms and the
Camera
glLoadIdentity();
//insert camera transformation here
glutWireCube(1);
eye(position)
gluLookAt Implements a
convenient Camera Model
lookAt(positi
on)
void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble lookAtx, GLdouble lookAty, GLdouble lookAtz,
GLdouble upx, GLdouble upy, GLdouble upz ); 11
Camera Transforms
We need to express our scene in terms of a
new coordinate frame with the viewer at the
origin and looking down the z axis.
N
n
lookAt x eyex N
N lookAt y eyey
u vn
lookAt z eyez
v n UP'
UP
UP (upx , up y , upz ) UP'
UP u x uy uz 0
v vy vz 0
M x
From this we get three unit vectors u, v and n camera
nx ny nz 0
the basis vectors for the viewing coordinate 0 0 0 1
frame
M is applied to correct the orientation, we also need to apply a
translation which will place the camera at the coordinate origin. This
is simply a Translation by (-eyex, -eyey, -eyez); 12
gluLookAt
void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble lookAtx, GLdouble lookAty, GLdouble lookAtz,
GLdouble upx, GLdouble upy, GLdouble upz );
u x uy uz 0
v vy vz 0
where M x
n x ny nz 0
0 0 0 1
13
Camera Transforms The Image
gluLookAt(4, 0, 0, 0, 0, 0, 0, 1, 0);
gluLookAt(0, 0, 4, 0, 1, 1, 1, 1, 0);
gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
14