Title: CG for Vision Research
1CG for Vision Research
- Lecture 1
- Winter Term 05-06
- Quoc Vuong, Franck Caniard, MPI
2OpenGL Projections Transformations Graphics
Primitives Textures Lighting Material Properties
Vision Research Viewpoint Effect Structure from X
(Motion, Shading, Stereo) Active
Exploration Navigation
GLUT Window Management Input Devices Event
Loop Timing
Fun/Advanced Modeling Animations Mapping (bumps,
terrains) Physics Simulation Sound (OpenAL)
3Viewing Objects
The Ambassadors, Hans Holbein, 1533
4Setting the SceneThe Camera Analogy
5Coordinate Systems
- Three coordinate systems
- World (Fixed)
- Camera/Eye
- Object
- Relative position and orientation of eye and
objects within world space inter-related - Modelview transformation
- Eye also has projection
- Projection transformation
6Projections
- Define viewing volume
- Determines how an object is projected onto screen
(2-D image plane) - Determines what is visible (view clipping)
top
left
viewing volume
right
bottom
near
far
7Perspective glFrustum() gluPerspective()
Orthographic glOrtho() gluOrtho2D()
8- Perspective
- Parallel lines in 3-D not parallel in 2-D
(foreshortening) - Distortions larger at closer distances
- VP vanishing point
- Orthographic
- Parallel lines in 3-D remain parallel in 2-D
- Approximated by very distant objects
- Vanishing point at infinity
PlaneView3D www.mtsu.edu/csjudy/planeview3D/tuto
rial.html
9Transformations
- Three classes of model transformations
- Translation glTranslate()
- Rotation glRotate()
- Scaling glScale()
- gluLookAt()
- Combines all 3 transformations
10Move eye or object?
11Which transformation first? (matrix
multiplication is non-commutative AM ? MA)
123-D Object Geometry
- 3-D object collection of vertices
- Position
- Surface Normal
- Normal is
- Object-centered
- Specifies orientation of points on surface, with
respect to object coordinate system
13Surface Normals
- Vector perpendicular to tangent plane
- Has a direction (sign)!
- Used for calculating
- Shading angle between light ray and surface
normal - Visibility sign of direction with respect to eye
- Two methods to calculate normals (Appendix E in
Redbook) - Analytic solution If you know the surface
function, you can calculate the normal exactly - Polygonal approximation Calculate normal of
polygon from 3 vertices
14Ballard Brown 82, Chap 3
15Projections and Transformations in OpenGL
16Enter the Matrix
- Projections and transformations are implemented
as 4 x 4 matrices - Eye and object transformations combined into
modelview matrix - Only one active current matrix
- Must switch between projection matrix and
modelview matrix - OpenGL functions to set current matrix
- Calls to glRotate(), glTranslate(), glScale(),
etc. change values of active matrix - Can directly change values of current matrix
- Can save and restore current matrix using Matrix
Stack
17Transformation Matrix Multiplication
18Matrix Commands
19Modelview Matrix
Redbook, Appendix F
20Modelview Matrix
Scaling
glScalef(x,y,z)
Translation
glTranslatef(x,y,z)
Redbook, Appendix F
21Projection Matrix
Perspective
glFrustum()
Orthographic
glOrtho()
Redbook, Appendix F
22Matrix Stack
glPushMatrix()
glPopMatrix()
Top (current matrix)
- Keep track of matrix states (undoes)
- Hierarchical transformations
Bottom 2 projection 32 modelview
23Look At That!
gluLookAt(x, y, z, 0, 0, 0, 0, 1, 0)
24Rendering Pipeline(2nd pass)
3D Vertex Data
Vertex Evaluation
Frame Buffer
2D Pixel Data
Pixel Operation
25Translate Rotate Scale
3D Vertex Data
Vertex Evaluation
Modelview Matrix
(x, y, z)
Projection Matrix
Viewport Transf.
Frame Buffer
Perspective Orthographic
26Rendering Pipeline
MV
Pro
View port
3D Vertex Data
Vertex Evaluation
Frame Buffer
2D Pixel Data
Pixel Operation
27Template Code 1
28Basic Structure
Add libraries
Model Reader
Own/other libraries
Global variables Function prototypes
Initialization functions
Lighting
OpenGL States
Your functions here!
Model Renderer
Main function Infinite loop
29Header Files
- Interface between your program and libraries
- Data structures
- Functions
- Copies code in header file at include point
- Be careful not to duplicate variables or function
names - Standard directory paths for standard header
files - Accessed with ltgt (triangle brackets)
- Local directory for header files
- Accessed with (double-quotes)
30More on OpenGL States
- OpenGL states can be changed any where in your
program - Remember that states have default values!
- Sometimes comes in pairs
- glBegin() glEnd()
- glEnable() glDisable()
- glPushMatrix() glPopMatrix()
- Rule of thumb
- If you explicitly change a state, change it back
- If a state only needs to be changed once (e.g.,
lighting), then set the state once in OpenGL
initialization
31www.opengl.org/resources/code/basics/redbook/index
.html
- Add hand with additional fingers
- Animate robotic arm
32This slide left intentionally blank