computer graphics lecture 7: 3d viewing - m5zn · computer graphics lecture 7: 3d viewing ......
TRANSCRIPT
COMPUTER GRAPHICS
LECTURE 7: 3D VIEWING
Dr. Abdallah Namoun
Computer Graphics - CPCS 391
Plan
Synthetic Camera Model
3D Coordinate Spaces / Systems
Steps in 3D Viewing
Types of 3D Viewing
Orthographic / Parallel
Perspective
OpenGL Viewing Functions
Learning Outcomes
Learn about requirements of a ComputerGraphics camera
Explore various coordinate systems Eye (Camera) Coordinate System3D Normalized Device Coordinate System
Learn about different types of visible volumesPerspective vs Orthorgraphics
3D to 2D Perspective Projection Learn about OpenGL viewing functions
Synthetic Camera Model
The process is similar to ‘making a photo’
Viewing in Computer Graphics requires
One or more objects
A viewer / camera with a projection surface
Projectors that go from the object(s) to the projection surface
Light source(s)
Rendering Pipeline
The viewing process involves mainly Transformation of world into screen (i.e. 3D into 2D)
Clipping: removing parts outside screen
3D Viewing Pipeline
MC: Modeling / Object Coordinates
WC: World Coordinates
VC: Viewing Coordinates
PC: Projection Coordinates
NC: Normalized Coordinates
DC: Device Coordinates
Apply model transformations
To camera coordinates
Project
To standard coordinates
Clip and convert to pixels
Coordinate Systems in 3D Graphics
There exist multiple ‘coordinate systems’ in 3DGraphics
1. Object space (i.e. Local)
2. World space (i.e. Model)
3. Camera space (i.e. Eye or View)
4. Screen space (i.e. Clip)
It is useful to understand how these coordinatesystems interact with each other.
A 3D Coordinate System
Objects In Scenes (Object Space)
Graphics primitives are specified in their own localcoordinate systems
Object Coordinate System: each object is modelled inits absolute local space; it stands alone for itself
Object often centred around the origin
The scene is specified in a World Coordinate System
Objects In Scenes (World Space)
World Space: is the space where everything is positioned
Each object is transformed into the World Coordinate Systemvia its ‘model transform’ at runtime
Each object has a transformation matrix (TM) associated with it
Object vertices are multiplied by TM to compute newposition/orientation in WS
World SpaceObject Space
Rendering Pipeline
View transform: once the scene is defined, specify howit will be observed?
Steps of 3D Viewing
Everything is positioned in World Space now, so wewant to look at it.
There are three aspects of the viewing process, allof which should be / are implemented in thepipeline:1. Positioning the camera
Setting the model-view matrix
2. Selecting a lens Setting the projection matrix
3. Clipping Setting the view volume
The View Transform
Once the scene is defined, we specify how it will be viewed / observed? (i.e what to render?)
We need to model the camera
Define camera space (e.g. eye space, view space)
Change vertices from World Space into Camera space
Camera Space
By convention (assumptions)1. Right-handed coordinate system
2. Camera is placed at the origin of camera space (x’, y’, z’) = (0, 0, 0)
3. Camera looks down the negative z-axis of camera space
The View Transform
View Transform maps/ transforms points fromWorld Space to Camera Space
Usually consists of rotations and translations
The look-at Transform
A convenient way to specify the view transform: 1. The eye point in world coordinates
Where is the camera located in World Space?
2. The look-at point in world coordinates (central axis of view space)
Where is the camera looking at?
3. An up vector
Defines upward
orientation
The look-at Transform to Position Camera The view transform puts the camera at the origin looking down
the negative z-axis of a right-handed coordinate system
The GLU library contained the function ‘gluLookAt’ to form the required ‘model-view matrix’ through a simple interface
Note the need for setting an up direction
Should not be parallel to look-at direction
The LookAt Function in OpenGL
gluLookAt(eye, at, up)
1. eye – position of camera
2. at – look-at point of interest
3. up – up vector
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
A Computer Graphics Camera
Camera position: eye
Look at position: at
Up direction: up
Related terms: Image Plane
Viewing Direction
View Vector
The Up Direction (Up Vector):
Also referred to as: “Twist Angle” Cannot be parallel to viewing direction
Does not need to be normalized
Does not need to be perpendicular toviewing direction
Moving the Camera Frame
Initially the object and camera frames are the same
If we want to visualize object with both positive andnegative z values we can either:1. Move the camera in the positive z direction
Translate the camera frame
2. Move the objects in the negative z direction Translate the world frame
Moving the camera or the world are equivalent (sameresults) and are determined by the model-view matrix Want a translation (Translate(0.0, 0.0, -d);)
d > 0
Moving Camera back from Origin
frames after translation by –d
d > 0
default frames
Moving the Camera
We can move the camera to any desired position by a sequence of rotations and translations
Example: side view
1. Rotate the camera
2. Move it away from origin
Model-view matrix C = TR
OpenGL Code
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -d);
glRotatef(90.0, 0.0, 1.0, 0.0);
Rendering Pipeline (Cont)
Projection transform (Camera projection): once the camerais positioned correctly in the scene, specify which lens to use(type of projection) and clip the image?
Position the camera
The Visible (View) Volume
Only geometries (primitives) inside the volume arevisible
All geometries (primitives) outside are ignored
Primitives that overlap the volume are clipped
There are two types of view volumes
1. Rectangle
2. Frustum
Projections
Projection: is the process of combining objects andcamera to produce an image (from 3D into 2D images)
Projectors are lines drawn from each point on an imageand pass through the center of the camera lens (COP orcenter of projection).
The projection plane (film plane) holds what is shown on thescreen.
Projectors are lines that either converge at a centre ofprojection or are parallel
Types of ProjectionsA. Orthographic projection
B. Perspective projection
Orthographic vs Perspective Projection
1. Orthographic Projection Parallel projection (transforms objects along parallel lines) Preserves size
Good for determining relative size of objects
Does not provide a realistic view
2. Perspective (Frustum) Projection Projection along rays (converge at centre of projection) Closer objects appears larger Similar to human vision (gives a realistic view)
Projections transform camera/view coordinates (3D)into projection coordinates (2D)
This is achieved using ‘a projection transformation’
Projection Transformations
P1
P2
P’1
P’2
View plane
Orthographic Projection
P1
P2
P’1
P’2
View plane
Perspective Projection
Centre of Projection
OpenGL Orthographic Viewing
Default projection in OpenGL is orthographic
MatrixMode(GL_PROJECTION);
glOrtho(left, right, bottom, top, near, far);
Projection lines are parallel
near and far are distances measured from camera
Model fits between clipping planes (objects outside are clipped)
Orthographic Projection
The Rectangular Visible (Viewing) Volume
Volume is defined by: Near Plane (n)
Far Plane (f)
Width (W)
Height (H)
Orthographic Projection
OpenGL Perspective Viewing
Volume is defined by field of view (fov)
gluPerspective(fovy, aspect, near, far);
The aspect ratio = w/h near and far are Z coordinates
The Viewing Frustum Volume
Viewing Volume defined by:
Near Plane (n)
Far Plane (f)
Fields of view (fov)
Projection lines are
not parallel; they converge
at eye of camera
Perspective Projection
Coordinate Transformation Pipeline
Transforms
World / Model Transform (MW) Object Space (OC) To World Space (WC)
View Transform (MV) World Space to Eye (Camera) Space (EC)
Projection Transform (MP)
Camera Space To Screen Space (~NDC (Normalized Device Coordinates))
View Frustum to NDC Cube
3D NDC to 2D Image (Near) Plane
Resulting image on the near plane
Screen Space
Clipping window:
What do we want to see?
xwmin xwmax
ywmax
ywmin
Viewport:
Where do we want to see it?
Clipping window
World:
xvmin xvmax
yvmax
yvmin
Viewport
Screen:
Clipping: removing parts outside clipping window.
Normalize coordinates
Screen Space
Finally, specify the viewport (just like in 2D):
glViewport(xvmin, yvmin, vpWidth, vpHeight);
xvmin, yvmin: coordinates lower left corner (in pixel coordinates);
vpWidth, vpHeight: width and height (in pixel coordinates);
(xvmin, yvmin)
vpWidth
vpHeight Viewport
Location Size
OpenGL 2D Perspective Viewing
In short:
glMatrixMode(GL_PROJECTION);
glFrustrum(xwmin, xwmax, ywmin, ywmax, dnear, dfar);
glViewport(xvmin, yvmin, vpWidth, vpHeight);
glMatrixMode(GL_MODELVIEW);
gluLookAt(x0,y0,z0, xref,yref,zref, Vx,Vy,Vz);
To prevent distortion, make sure that:(ywmax – ywmin)/(xwmax – xwmin) = vpWidth/vpHeight
Summary
We have learnt in this chapter:
Different Types of Coordinate Systems in 3D Graphics
Types of Projections
Orthographic
Perspective
OpenGL Viewing Functions
Next Week: Revision 1
Glossary – Key Terms
Object Coordinates: ……………………. World Coordinates: ……………………. View Coordinates: ……………………. Device Coordinates: ……………………. Projection: ……………………. Orthographic: ……………………. Perspective: ……………………. Parallel: ……………………. Frustum: ……………………. Viewing: ……………………. Screen: …………………….