Title: Reminder
1Reminder
- Any sequence of matrix operations can be composed
into a single matrix - Well always use an extra dimension for all
vertices (x,y,w)
2Extending to 3D
- Homogeneous coordinates in 3D
- x,y,z,1T (x,y,z,w)
- Matrices of this form
- 4x4 Matrices instead of 3x3 for 3D
3Translation
4OpenGL
Post-multiplies translation matrix onto currently
selected matrix
5Example
glTranslated(tox, toy, toz) DrawBox()
6Scaling
How do I do auniform scale?
glScaled(x, y, z)
7What about Rotation?
- How can we convert this to 3D?
8Rotation about Z axis
Just keep z constant.
9The 3 Rotation Matrices
10OpenGL general glRotated
- glRotated(angle, x, y, z)
- Rotates by angle (in degrees) around the vector
(x, y, z)
11Skew or Shear
12Example Rotating around a point
- Suppose we have an object centered on (12, 17,
32) - We want to spin the object around that center
point - What will be the operations?
13Homogenous Coordinates and Vectors
- It is convention that
- Points in space are indicated with w1
- Vectors are indicated with w0
- 12, 13, 5, 1T is a point
- 45, 13, 2, 0T is a vector (point point?)
- We often want unit-length vectors
14OpenGL Transformation Composition
- A global modeling transformation matrix
- (GL_MODELVIEW, called it M here)
- glMatrixMode(GL_MODELVIEW)
- The user is responsible to reset it if necessary
- glLoadIdentity()
- -gt M 1 0 0
- 0 1 0
- 0 0 1
15OpenGL Transformation Composition
- Matrices for performing user-specified
transformations are multiplied to the current
matrix - For example,
-
1 0 1 - glTranslated(1,1 0) M M x 0 1
1 -
0 0 1 - All the vertices defined within glBegin() /
glEnd() will first go through the transformation
(modeling transformation) - P M x P
-
-
16Transformation Pipeline
Modeling transformation
17Frames
- Frame A center and three coordinate axes
- A coordinate system
World Frame and Camera Frame
18World to Camera
- What does gluLookAt do mathematically?
void gluLookAt( GLdouble eyex, GLdouble eyey,
GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble
centerz, GLdouble upx,
GLdouble upy, GLdouble upz )
19Defining a Frame(relative to another frame)
- Need
- Origin
- Vectors for X, Y, and Z axis of frame
20Adding Orthogonal Constraint
- We can get by with
- Origin
- One axis direction and which way is up
Z direction is negative of look direction. X is
at right angles to Z and Up
21Computing the Axis
- Z (eye center) / eye center
- X (up ? Z) / up ? Z
- Y Z ? X
z
x
y
Right-hand rule?
22Making a frame the reference coordinate system
- Move the center to the origin
- Rotate the frame axis onto (1,0,0), (0,1,0),
(0,0,1)
23Moving the center to the origin
glTranslated(-eyex, -eyey, -eyez)
24Rotating arbitrary axes v1,v2,v3 onto (1,0,0),
(0,1,0), (0,0,1)
- Notice v1,v2,v3 must be orthogonal to each
other
25Suppose we have three ortho-normal vectors
- v1,v2,v3
- Lets build a matrix like this
- This will rotate v1 onto the x axis, v2 onto
the y axis, v3 onto the z axis
26Introduction to 3D viewing
- 3D is just like taking a photograph!
27Viewing Transformation
- Position and orient your camera
28Projection Transformation
- Control the lens of the camera
- Project the object from 3D world to 2D screen
29Viewing Transformation (2)
- Important camera parameters to specify
- Camera (eye) position (Ex,Ey,Ez) in world
coordinate system - Center of interest (coi) (cx, cy, cz)
- Orientation (which way is up?) View-up vector
(Up_x, Up_y, Up_z)
30Viewing Transformation (3)
- Transformation?
- Form a camera (eye) coordinate frame
- Transform objects from world to eye space
31Viewing Transformation (4)
- Eye space?
- Transform to eye space can simplify many
downstream operations (such as projection) in the
pipeline
(1,0,0)
(0,1,0)
u
v
(0,0,1)
n
y
(0,0,0)
coi
x
z
32Viewing Transformation (5)
- In OpenGL
- - gluLookAt (Ex, Ey, Ez, cx, cy, cz,
- Up_x, Up_y, Up_z)
- - The view up vector is usually (0,1,0)
- - Remember to set the OpenGL matrix mode
to - GL_MODELVIEW first
33Viewing Transformation (6)
void display() glClear(GL_COLOR_BUFFER_
BIT) glMatrixMode(GL_MODELVIEW)
glLoadIdentity() gluLookAt(0,0,1,0,0,0,0,1
,0) display_all() // your display
routine
34Suppose we have three orthogonal vectors
- v1,v2,v3
- Lets build a matrix like this
- This will rotate v1 onto the x axis, v2 onto
the y axis, v3 onto the z axis
35My Version of gluLookAt()
void mygluLookAt(Point3 eye, Point3 center,
Point3 up) Point3 cameraZ Normalize( eye
center ) // v3 Point3 cameraX Normalize(
Cross(up, cameraZ) ) // v1 Point3 cameraY
Cross( cameraZ, cameraX ) // v2 GLdouble
m16 // Fill the matrix in row by row
m0 cameraX.X m4 cameraX.Y m8
cameraX.Z m12 0.0 m1 cameraY.X
m5 cameraY.Y m9 cameraY.Z m13
0.0 m2 cameraZ.X m6 cameraZ.Y
m10 cameraZ.Z m14 0.0 m3 m7
m11 0.0 m15 1.0 glMultMatrixd( m
) glTranslated( -eye.X, -eye.Y, -eye.Z )
Order of transformations!
36Messing with the camera
- What if I want to PAN the camera?
- We need to define PAN
- There are two possibilities
- Crab
- Pan
37Panning
- Suppose we pan around the camera Y axis
- This is NOT up in world space.
- We need to change the lookAt point.
38Operations on Points in Space
- LookAt is a point in space
- Need these transformation
- Translate by eye
- Rotate frame onto axis (using some M)
- Rotate around Y by pan angle
- Inverse rotate M
- Translate by eye
- PPT(eye) MT RY(q) M T(-eye)
39Easier 1
- Just replace the matrix using gluLookAt.
- Problems?
40Easier 2
- The first 2 operations are already what is done
to set the camera up - M T(-eye)
- We just need to add a rotate after this is done.
- Implies we want to pre-multiply by a rotation
matrix.
41Easier 2
- Steps
- Read out the current matrix.
- Set the matrix to the identity matrix.
- Rotate about the y-axis the amount we want to
pan. - Post-multiply by the matrix read out in step 1.
42Camera Controls
- Tilt
- Roll
- Dolly
- Boom
- Zoom (same as dolly?)
- General camera (or entity) movement and the user
interface / control.
43Camera Controls
- Stationary
- 2 degrees of freedom zoom
- QuicktimeVR
44Examiner
- Mimic holding an object in your hand.
- OpenInventors Examiner Viewer
- Used in IRIS Explorer
- Used in modeling and scientific visualization.
Image courtesy of NAG
45Flying
- Camera specified using Euler angles and position.
- Many possible control strategies
- Acceleration / Deceleration
46Camera models in games
- Many different approaches
- Flying model, with a camera pan, tilt according
to the mouse position. - Orthographic view with simple translations
(occasionally a examiner) - Cinematic camera with view-oriented dolly (look
with mouse, move in camera look-at direction with
keyboard).
47Software Engineering
- Define a well-encapsulated Camera class or base
class. - Separate the control of the camera from the
camera object. - Separate the mouse / keyboard handling from the
control as much as possible. - I will share my Camera classes next week.