ComputerGraphics 3D Part1
ComputerGraphics 3D Part1
ComputerGraphics 3D Part1
Computer Graphics
Module: 3D Graphics
P. J. Narayanan
Spring 2004
CS3500
1
3D Graphics: Objectives
Representation and manipulation of 3D objects built using
3D primitives.
2D Graphics
Draw on a 2D canvas using 2D primitives.
View it frontally from a certain distance away.
Only scaling and translation between canvas coordinates
and frame buffer coordinates.
A window on the canvas is mapped to a window on
screen or frame buffer using the (window-to-)viewport
transformation.
Translate to origin, scale to new size, translate to new
position.
CS3500 December 11, 2003
3
Perspective Effects
Perspective distortion is relevant for 3D points.
Different Coordinates
Object Reference: Object is described in an internal
coordinate frame called ORC.
World: Common reference frame to describe different
objects, called WC.
Camera/View Reference: Describe with respect to the
current camera position/orientation, called VRC.
Normalized Projection: A standard space from which
projection is easy, called NPC.
Screen: Coordinates in the output device space.
CS3500 December 11, 2003
6
A Single Table
A table defined in its own coordinate system.
Transformations
Modelling: Convert from object coordinates to world
coordinates (ORC to WC).
3D Coordinates
ρ
θ
φ
z
Z
X
.
Cartesian:
Polar:
CS3500
10
Homogeneous Representation
Convert to a 4-vector with a scale factor as fourth.
T
for any .
Translation, rotation, scaling, shearing, etc. become
linear operations represented by matrices.
What does T
mean?
CCW +ve; orthonormal; length preserving; rows give
direction vectors that rotate onto each axis; columns ....
CS3500 December 11, 2003
12
A sequence of transforms can be represented using a
composite matrix:
Commutativity
Translations are commutative: .
Scaling is commutative: .
Rotations are NOT commutative: .
Consider the effect on Z-axis of and
!
Also, etc....
End of Class 6
3D Graphics: Recap
Rotation, translation, scaling, etc.
forms.
What is ?
3-step process:
Net result:
β
α Y
γ
X P
Computing
First rotate by about X axis. Vector
would lie in the
XY plane, with tip at point P.
Also, and
if .
Overall: and .
Could have aligned with Y or Z axis with same results.
(0, 1, 1)
(1, 0, 1) (1, 1, 1)
(1, 1, 0) (1, 2 , 0)
: First Method
Computing
about X.
Rotate by
CS3500
22
After rotation, will align with X-axis. Hence that is the
first row .
an arbitrary vector (not parallel to ). Now, .
Lastly, and
Many possibilities, all with the same result!
CS3500 January 06, 2004
23
: Second Method
.
.
will lie on X-axis. First row
Computing
Second row
Thus,
CS3500
24
Second : Picture
(1, 0, 2) (0, 1, 1)
(1, 0, 1) (1, 1, 1)
(1, 1, 0)
Apply .
Composite transformation: .
End of Class 7
3D Transformations
Many ways to think about a given transform.
Another Example
Z Z
B
A
C
B’
Y A’ Y
C’
X X
Transforming Lines
A composite transformation can be seen as changing
points in the coordinate system.
These transformations preserve collinearity. Thus, points
on a line remain on a (transformed) line.
Take two points on the line, transform them, and compute
the line between new points.
Lines are defined as a join of 2 points or intersection of 2
planes in 3D. The same holds for transformed lines using
transformed points or planes!
Transforming Planes
A plane is defined by a 4-vector in homogeneous
coordinates.
is the normal to the plane. The plane consists of points
such that T .
True when T
, or T
.
Modelling
Place the object coordinate frame in the world coordinate
frame.
Apply yaw, pitch, and roll in that order.
Coordinate axes undergoing transformation!
Net effect: .
.
End of Class 8
Apply yaw, pitch, and roll in that order.
Coordinate axes undergoing transformation!
Net effect: .
.
Hierarchy of Transformations
A hierarchy of transformations needed to setup the world
and the camera.
In the example of the train and churkha and the ant, the
transformations were in 3D!
A humanoid robot could have a coordinate frame on its
body, another one on the shoulder, a third on the shoulder
that moves with the upper arm, a fourth on the elbow, a
fifth on the elbow that moves with the forearm, etc.
captures the composite transform as
Humanoid Robot
Scene Graph
T T
T T T
T T T T
Viewing Specification
Camera center specified in world coordinates.
n
Z Up
C
Look
u
WC Y
X
Transformation Steps
How do we align WC to VRC?
Translate to .
Align Z axis to -(Look Vector).
Rotate about Z to match Up vector and Y.
Translation is easy. How do we get the rotation matrix?
Remember columns of the matrix give directions to which
the axes rotate!!
Rotation
Let and be the unit vectors in those
directions.
Up vector needn’t be orthogonal to the look vector. The
and vectors define the Up plane.
First column:
Second column: .
T
We have achieved: .
CS3500 January 13, 2004
49
yaw roll
Y
Pilot’s view is from aircraft! pitch
X
ρ θ
steps?
Y’
φ X’
Apply yaw, pitch, and roll in that order.
Coordinate axes undergoing transformation!
Net effect: .
But, we want to get camera coordinates given world
coordinates!
Viewing transform: .
vector on start when ModelView matrix is identity.
v
u X
n
End of Class 9
2 P
aligns Blue to
Green. 2
2
.
Polar View
twist about camera’s own axis ( ), and elevation
measured from the horizontal (X-Z) plane ( ).
How do we align WC to VRC? (We want the inverse!)
CS3500 January 20, 2004
58
el
az
(ii) Rotate by about X
glRotate( , 0, 0, 1);
glRotate( , 1, 0, 0); el
az
glRotate( , 0, 1, 0);
VRC ORC
Projections
Projection involves projectors starting from 3D points and
hitting the 2D projection plane, forming the image of the
point.
Parallel Projections
Orthographic: Projection plane is perpendicular to the
direction of projection.
If direction of projection parallel to the axes:
plan, elevation, side elevation.
If DoP : isometric projection.
Oblique: Otherwise.
Cabinet when projectors make 45 degrees with the
projection plane.
Cavalier when they make arctan(2) degrees with the
projection plane.
CS3500 January 20, 2004
63
Oblique Projections
Projector angle and angle
with horizontal .
degrees.
Orthographic when .
Orthographic Projections
If uniform scaling is involved, the top two 1’s should be
the scale factor.
Perspective Projections
Can be characterized by
the number of vanishing
points. (projections of points
at infinity).
Depends on the number of
axes the projection plane
intersects.
1-point, 2-point, and 3-point
perspective projections.
In matrix form,
x
xp
z
d
values.
Another View
If we shift the origin to lie on the projection plane, with the
CoP at , we get the matrix:
We can now think of the Orthographic Projection matrix
as the special case when .
End of Class 10
of
projection
case
Orthographic
special
perspective
A
Perspective
CS3500
72
Volume of Visibility
Cameras have finite fields of view in horizontal and
vertical directions.
View Volume
f
b
l
n
r
Orthographic View Volume
CS3500 January 22, 2004
75
f
b
l
r
n
Perspective View Volume
Needn’t be symmetric!
Alternate Specification
Horizontal and vertical fields of view:
For symmetric perspective view volumes:
In matrix form,
x
xp
z
d
values.
Why?
Easier to eliminate objects outside the view volume.
Orthographic & perspective aren’t different.
The -coordinates not thrown away. (Used later!)
.
OpenGL:
.
Matrix??
Matrix:
CS3500
84
with
with
Composite Matrix :
The near plane is now at .
it into a cube.
Need also to send near plane to 0 and far plane to -1.
Scale by and add a a translation to do this.
Actual Projection
We have already performed the perspective division.
scaling x-y to the viewport.
values can be used for visibility determination.
End of Class 11
Programming Assignment 2
by TA (Soumyajit Deb)
End of Class 12
Graphics Accelerators
by TA (Soumyajit Deb)
End of Class 13
3D Module: Recapitulation
3D Graphics additionally involves projecting the 3D world
to the 2D image plane of the camera.