Lecture 7 Three dimensional graphics
Lecture 7 Three dimensional graphics
GRAPHICS
CCS 2208 COMPUTER GRAPHICS
3D Modeling Transformations
• Methods for object modeling transformation in three
dimensions are extended from two dimensional methods
by including consideration for the z coordinate.
• Straightforward for translation and scale, rotation more
difficult
• Homogeneous coordinates: 4 components
a b c tx
d e f ty
g h i tz
0 0 0 1
3D Translation
• P is translated to P' by:
x 1 0 0 tx x
y 0 1 0 t y y
z 0 0 1 tz z
1 0 0 0 1 1
P T P
3D Translation
Very similar to 2D. Using 4x4 matrices rather than 3x3.
y x x t x
y y t y
z z t z
x, y, z x 1 0 0 tx x
x, y , z y 0
1 0 ty y
z x z 0 0 1 tz z
1 0 0 0 1 1
3D Rotation
Rotations are specified by a rotation axis and an angle
The easiest rotation axes are those that are parallel to
the coordinate axis.
Positive rotation angles produce counterclockwise
rotations about a coordinate axis, if we are looking along
the positive half of the axis toward the coordinate origin.
Coordinate Axis Rotations
Z-axis rotation: For z axis same as 2D rotation:
x' cos sin 0 0 x
P R z ( ) P y ' sin cos 0 0 y
z' 0 0 1 0 z
1 0 0 0 1 1
Coordinate Axis Rotations
X-axis rotation:
x' 1 0 0 0 x
P R x ( ) P y ' 0 cos sin 0 y
z ' 0 sin cos 0 z
1 0 0 0 1 1
Coordinate Axis Rotations
Y-axis rotation:
x' cos 0 sin 0 x
P R y ( ) P y ' 0 1 0 0 y
z ' sin 0 cos 0 z
1 0 0 0 1 1
General 3D Rotation
1. Translate the object such that rotation axis passes
through the origin.
2. Rotate the object such that rotation axis coincides with
one of Cartesian axes.
3. Perform specified rotation about the Cartesian axis.
4. Apply inverse rotation to return rotation axis to original
direction.
5. Apply inverse translation to return rotation axis to
original position.
General 3D Rotation
y y S y
z x S z
z x z x
Changes the size of the object and repositions the object
relative to the coordinate origin.
x S x 0 0 0 x
y 0 Sy 0 0 y
P S P
z 0 0 Sz 0 z
1 0 0 0 1 1
3D Rendering Pipeline
3D Geometric Primitives
Modeling
Modeling
Transformation
Transformation Transform into 3D world coordinate system
Lighting
Transform into 3D camera coordinate system
Lighting
Done with modeling transformation
Viewing
Viewing Illuminate according to lighting and reflectance
Transformation
Transformation Apply texture maps
Projection
Projection Transform into 2D screen coordinate system
Transformation
Transformation
Clipping
Clipping Clip primitives outside camera’s view
Scan
Scan
Conversion
Conversion Draw pixels (includes texturing, hidden surface, ...)
Modeling
Modeling
Transformation
Transformation glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
Viewing
Viewing
Transformation
Transformation glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 1.0);
Lighting
Lighting &
& glVertex3f(0.0, 1.0, 1.0);
Texturing
Texturing glEnd();
Projection
Projection
Transformation
Transformation
OpenGL executes steps
Clipping
Clipping
of 3D rendering pipeline
for each polygon
Scan
Scan Conversion
Conversion
Image
Camera Coordinates
• Canonical coordinate system
• Convention is right-handed (looking down -z axis)
• Convenient for projection, clipping, etc.
Camera up vector
y maps to Y axis
y
View
plane
Camera
z
World
Viewing Transformations
p(x,y,z)
3D Object Coordinates
Modeling
Modeling
Transformation
Transformation
3D World Coordinates
Viewing
Viewing
Transformation
Transformation
3D Camera Coordinates Viewing Transformations
Projection
Projection
Transformation
Transformation
2D Screen Coordinates
Window-to-Viewport
Window-to-Viewport
Transformation
Transformation
2D Image Coordinates
p’(x’,y’)
Projection
• General definition: Transform points in n-space to m-space
(m<n)
DOP
View
Plane
Orthographic Projections
• DOP perpendicular to view plane
Front
Top Side
Oblique Projections
• DOP not perpendicular to view plane
45 45
Cavalier Cabinet
o
(DOP = 45 ) o
(DOP = 63.4 )
Properties of parallel projection
• Properties of parallel projection:
• Are actually a kind of affine transformation
• Parallel lines remain parallel
• Ratios are preserved
• Angles not (in general) preserved
• Not realistic looking
• Good for exact measurements,
Most often used in
• CAD,
• architectural drawings,
• etc.,
where taking exact measurement
is important
Perspective projections
Properties of perspective projections
• Properties of projective transformations:
• Lines map to lines
• Parallel lines do not necessarily remain parallel
• Ratios are not preserved
Usually d = near
Perspective Parameters
• There are three different ways to describe a perspective
camera
• Clipping planes, Field of View, Focal distance ,
• The most general is clipping planes – they directly
describe the region of space you are viewing
• For most graphics applications, field of view is the most
convenient
• You can convert one thing to another
Clipping Planes
The left/right/top/bottom planes are defined according to
where they cut the near clip plane Left Clip
Near Clip Plane
xv
Plane
Far Clip
View Plane
l Volume
n
f -zv
r
Right Clip
Plane
Need 6 parameters,
Or, define the left/right and top/bottom clip
planes by the field of view
Field of View
Assumes a symmetric view volume
Left Clip
Near Clip Plane
xv
Plane
Far Clip
View Plane
Volume
FOV
f -zv
Right Clip
Plane
Need 4 parameters,
Or, define the near, far, fov, aspect ratio
Focal Distance to FOV
• You must have the image size to do this conversion
• Why? Same d, different image size, different FOV
height/2
d FOV/2
d FOV height
tan
2 2d
1 height
FOV 2 tan
2d