Tutorial 3
Tutorial 3
intuition
o suppose Peye is fixed
o to pan the camera (like shaking your head left and right)
OpenGL
performs these calculations internally with a call to gluLookAt()
code:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(Peye,x, Peye,y, Peye,z, Pref,x, Pref,y, Pref,z, Vup,x, Vup,y, Vup,z );
Example
scene with camera at (4,4,4), pointed at (0,1,4), with up vector (0,1,0)
(4,4,4) - (0,1,4) (4,3,0)
n = --------------------- = ----------- = (4/5,3/5,0)
| (4,4,4) - (0,1,4) | | (4,3,0) |
(0,1,0) (4/5,3/5,0) (0,0,-4/5)
u = ------------------------- = -------------- = (0,0,-1)
| (0,1,0) (4/5,3/5,0) | | (0,0,-4/5) |
v = (4/5,3/5,0) (0,0,-1) = (-3/5,4/5,0)
[ 0 0 -1 0 ] [ 1 0 0 -4 ] [ 0 0 -1 4 ]
Mcam-1 = [ -3/5 4/5 0 0 ] [ 0 1 0 -4 ] = [ -3/5 4/5 0 -4/5 ]
[ 4/5 3/5 0 0 ] [ 0 0 1 -4 ] [ 4/5 3/5 0 -28/5 ]
[ 0 0 0 1 ] [ 0 0 0 1 ] [ 0 0 0 1 ]
check
[ 4 ] [ 0 ] [ 4 ] [ 1 ]
Mcam-1 [ 4 ] = [ 0 ], Mcam-1 [ 4 ] = [ 0 ]
[ 4 ] [ 0 ] [ 3 ] [ 0 ]
[ 1 ] [ 1 ] [ 1 ] [ 1 ]
OpenGL
gluPerspective()
o fovy
field of view in the y-direction, centered about y = 0
in degrees
o aspect
in camera coordinates
glFrustum()
o left, right, bottom, top, near, far
specifies the clipping planes of the view volume explicitly
in camera coordinates