SlideShare uma empresa Scribd logo
1 de 137
UNIT III
THREE-DIMENSIONAL
GRAPHICS
Three dimensional concepts; Three dimensional object
representations — Polygon surfaces- Polygon tables- Plane
equations — Polygon meshes; Curved Lines and surfaces,
Quadratic surfaces; Blobby objects; Spline representations —
Bezier curves and surfaces -B-Spline curves and surfaces.
TRANSFORMATION AND VIEWING: Three dimensional
geometric and modeling transformations — Translation,
Rotation, Scaling, composite transformations; Three
dimensional viewing — viewing pipeline, viewing coordinates,
Projections, Clipping; Visible surface detection methods.
1
3D Object Representation
• A surface can be analytically
generated using its function involving
the coordinates.
• An object can be represented in
terms of its vertices, edges and
polygons. (Wire Frame, Polygonal
Mesh etc.)
• Curves and surfaces can also be
designed using splines by specifying
a set of few control points.
2
y = f(x,z)
x y z . . .
Solid Modeling - Polyhedron
• A polyhedron is a connected mesh of simple planar polygons
that encloses a finite amount of space.
• A polyhedron is a special case of a polygon mesh that satisfies
the following properties:
• Every edge is shared by exactly two faces.
• At least three edges meet at each vertex.
• Faces do not interpenetrate. Faces at most touch along a
common edge.
• Euler’s formula : If F, E, V represent the number of faces,
vertices and edges of a polyhedron, then
V + F  E = 2.
3
3D Object Representation
• The data for polygonal meshes can be represented
in two ways.
• Method 1:
• Vertex List
• Normal List
• Face List (Polygon List)
• Method 2:
• Vertex List
• Edge List
• Face List (Polygon List)
4
5
0
1
2 3
4
5
6
7
Vertices and Faces - E.g. Cube
0
1
2
3
4
5
Face Index
Vertex Index
6
Data representation using vertex, face and normal lists:
Vertex List Normal List Polygon List
30 30 30 0.0 0.0 1.0 0 1 2 3
-30 30 30 0.0 0.0 -1.0 4 7 6 5
-30 -30 30 0.0 1.0 0.0 0 4 5 1
30 -30 30 -1.0 0.0 0.0 1 5 6 2
30 30 -30 0.0 -1.0 0.0 2 6 7 3
-30 30 -30 1.0 0.0 0.0 3 7 4 0
-30 -30 -30
30 -30 -30
7
Vertex List Edge List Polygon List
x[i] y[i] z[i] L[j] M[j] P[k] Q[k] R[k] S[k]
30 30 30 0 1 0 1 2 3
-30 30 30 1 2 4 7 6 5
-30 -30 30 2 3 0 4 5 1
30 -30 30 3 0 1 5 6 2
30 30 -30 4 5 2 6 7 3
-30 30 -30 5 6 3 7 4 0
-30 -30 -30 6 7
30 -30 -30 7 4
0 4
1 5
2 6
3 7
Data representation using vertex, face and edge lists:
Normal Vectors (OpenGL)
8
Assigning a normal vector to a polygon:
glBegin(GL_POLYGON);
glNormal3f(xn,yn,zn);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glVertex3f(x3,y3,z3);
glVertex3f(x4,y4,z4);
glEnd();
Enabling automatic conversion of normal vectors to unit vectors:
glEnable(GL_NORMALIZE);
Regular Polyhedra (Platonic Solids)
• If all the faces of a polyhedron are identical, and
each is a regular polygon, then the object is
called a platonic solid.
• Only five such objects exist.
9
Wire-Frame Models
• If the object is defined only by a set of nodes
(vertices), and a set of lines connecting the
nodes, then the resulting object representation is
called a wire-frame model.
• Very suitable for engineering applications.
• Simplest 3D Model - easy to construct.
• Easy to clip and manipulate.
• Not suitable for building realistic models.
10
Wire Frame Models - OpenGL
11
Some Wireframe Models in OpenGL:
Cube: glutWireCube(Gldouble size);
Sphere: glutWireSphere(…);
Torus: glutWireTorus(…);
Teapot: glutWireTeapot(Gldouble size);
Cone: glutWireCone(…);
(…) Refer text for list of arguments.
Wire Frame Model - The Teapot
12
Polygonal Mesh
• Three-dimensional surfaces and solids can be
approximated by a set of polygonal and line elements.
Such surfaces are called polygonal meshes.
• The set of polygons or faces, together form the “skin”
of the object.
• This method can be used to represent a broad class of
solids/surfaces in graphics.
• A polygonal mesh can be rendered using hidden
surface removal algorithms.
13
Polygonal Mesh - Example
14
Solid Modeling
• Polygonal meshes can be used in solid modeling.
• An object is considered solid if the polygons fit together to
enclose a space.
• In solid models, it is necessary to incorporate directional
information on each face by using the normal vector to the
plane of the face, and it is used in the shading process.
15
Solid Modeling - Example
16
Solid Modeling - OpenGL
17
Some predefined Solid Models in OpenGL:
Cube: glutSolidCube(Gldouble size);
Sphere: glutSolidSphere(…);
Torus: glutSolidTorus(…);
Teapot: glutSolidTeapot(Gldouble size);
Cone: glutSolidCone(…);
(…) Arguments same as wire-frame models.
18
Z
X
Y
y = f(x, z)
Surface Modeling
Many surfaces can be represented by an explicit function of
two independent variables, such as y = f(x, z).
Surface Modeling - Example
19
Sweep Representations
• Sweep representations are useful for both surface modeling
and solid modeling.
• A large class of shapes (both surfaces and solid models) can
be formed by sweeping or extruding a 2D shape through
space.
• Sweep representations are useful for constructing 3-D
objects that posses translational or rotational symmetries.
20
Extruded Shapes - Examples
21
A polyhedron obtained
by sweeping (extruding)
a polygon along a
straight line is called a
prism.
Surface of Revolution
• A surface of revolution is obtained by revolving a curve
(known as the base curve or profile curve) about an axis.
• In other words, a surface of revolution is generated by a
rotational sweep of a 2D curve.
• The symmetry of the surface of revolution makes it a very
useful object in presentation graphics.
22
23
Z
X
Y
y = f(x)
r
y y
(x, z)
y = f(r)
x
2
2
z
x
r 

Surface of Revolution
24
The three-dimensional surface obtained by
revolving the curve y = f(x) about the y-axis is
obtained by replacing x with sqrt(x*x + z*z).
The surface of revolution is thus given by
 
y f x z
 
2 2
Surface of Revolution
25
Surface of Revolution
x
x
y
)
sin(

2
2
2
2
sin
z
x
z
x
y






 

Quad trees
Quad trees are generated by successively dividing
a 2-D region(usually a square) into quadrants.
Each node in the quadtree has 4 data elements,
one for each of the quadrants in the region. If all
the pixels within a quadrant have the same
color (a homogeneous quadrant), the
corresponding data element in the node stores
that color. For a heterogeneous region of space,
the successive divisions into quadrants
continues until all quadrants are homogeneous.
26
Octrees
• An octree encoding scheme divide regions of 3-D
space(usually a cube) in to octants and stores 8
data elements in each node of the tree.
• Individual elements of a 3-D space are called
volume elements or voxels.
• When all voxels in an octant are of the same type,
this type value is stored in the corresponding data
element of the node. Any heterogeneous octant is
subdivided into octants and the corresponding
data element in the node points to the next node
in the octree.
27
Octrees
28
29
Bezier Curves
The Bezier curve only approximates the control points
and doesn’t actually pass through all of them.
30
Inputs: n control points (xi, yi), i = 0, 1,2, …n-1
 
,
0
,
0
,
( ) ( )
( ) ( )
0 1
!
( ) (1 )
! !
m
b m i i
i
m
b m i i
i
i m i
m i
x u Bez u x
y u Bez u y
u
m m m
Bez u u u and
i i i m i





 
   
  
   

   


m = n1
Bezier Curves
31
Inputs: n control points (xi, yi), i = 0, 1,2, …m
0
( ) ( ) , 0 1
( ) ( ( ), ( ))
( , )
m
m i i
i i
i i i
r u Bez u r u
where
r u x u y u
r x y

  



Bezier Curves
Properties of Bezier Curve
• Bezier curve is a polynomial of degree one less than
the number of control points
32
p0
p2
p1
p0
p2
p1
p3
Quadratic Curve Cubic Curve
Properties of Bezier Curve (cont.)
• Bezier curve always passes through the first and
last points; i.e.
and
33
0
(0)
x x

,
0
(0)
y y

(1) m
x x
 (1) m
y y

Properties of Bezier Curve (cont)
• The slop at the beginning of the curve is along the line
joining the first two control points, and the slope at the end
of the curve is along the line joining the last two points.
34
p0
p2
p1
p0
p2
p1
Properties of Bezier Curve (cont)
• Bezier blending functions are all positive and the sum is
always 1.
• This means that the curve is the weighted sum of the
control points.
35
,
0
( ) 1
m
m i
i
Bez u



Design Technique using Bezier Curves:
• A closed Bezier curve can be generated by specifying the
first and last control points at the same location
36
p4
p0=p5
p1
p2
p3
Design Technique (Cont)
• A Bezier curve can be made to pass closer to a
given coordinate position by assigning multiple
control points to that position.
37
p0
p1 = p2 p3
p4
• Bezier curve can be form by piecing of several
Bezier section with lower degree.
38
p0
p1
p2= p’0
p’2
p’3
p’1
39
(Not Important!)
,
0 0
( , ) ( ) ( ) ,
0 1, 0 1
( , ) ( ( , ), ( , ), ( , ))
( , , )
m l
m i l j i j
i j
ij ij ij ij
r u v Bez u Bez v r
u v
where
r u v x u v y u v z u v
r x y z
 

   



Bezier Surfaces
40
A set of 16 control points The Bezier Patch
Bezier Patch
41
Utah Teapot Defined Using Control Points
Bezier Patch
42
Utah Teapot Generated Using Bezier Patches
Bezier Patch
3D Translation 1
Translate over vector (tx, ty, tz ):
x’=x+ tx, y’=y+ ty , z’=z+ tz
or
x
y
P
P+T
T
z



































z
y
x
t
t
t
z
y
x
z
y
x
T
P
P
T
P
P'
en
,
'
'
'
'
met
,
3D Translation 2
In 4D homogeneous coordinates:
x
y
P
P+T
T
z
1
1
0
0
0
1
0
0
0
1
0
0
0
1
1
'
'
'
or
,












































z
y
x
t
t
t
z
y
x
z
y
x
MP
P'
3D Rotation 1
z
P
x
y
P’
a
1
0
0
0
0
1
0
0
0
0
cos
sin
0
0
sin
cos
)
(
with
,
)
(
Or
'
cos
sin
'
sin
cos
'
:
as
-
around
angle
over
Rotate













 







a
a
a
a
a
a
a
a
a
a
a
z
z
z
z
y
x
y
y
x
x
z
R
P
R
P'
3D Rotation 2
z
x
y
Rotation around axis:
• Counterclockwise, viewed from rotation axis
z
x
y z
x
y
3D Rotation 3
z
x
y
z
x
y z
x
y
z
y
y
x
x
z



x
z
z
y
y
x



Rotation around axes:
Cyclic permutation coordinate axes
x
z
y
x 


3D Rotatie 4
z
y
y
x
x
z



1
0
0
0
0
1
0
0
0
0
cos
sin
0
0
sin
cos
)
(
with
,
)
(
Or
'
cos
sin
'
sin
cos
'
:
as
-
around
angle
over
Rotate













 







a
a
a
a
a
a
a
a
a
a
a
z
z
z
z
y
x
y
y
x
x
z
R
P
R
P'
1
0
0
0
0
cos
sin
0
0
sin
cos
0
0
0
0
1
)
(
with
,
)
(
Or
'
cos
sin
'
sin
cos
'
:
as
-
around
angle
over
Rotate






















a
a
a
a
a
a
a
a
a
a
a
x
x
x
x
z
y
z
z
y
y
x
R
P
R
P'
1
3D Rotation around arbitrary axis 1
z
P
x
y
P’
a
Q
2
3
Q)P
)T(
(
T(Q)R
P'
Q
Q
Q
z 
 a
:
Or
.
over
back
Translate
3.
axis;
-
around
Rotate
2.
;
over
Translate
1.
:
rotation
2D
as
Similar
as.
-
the
example.
For
.
point
through
axis,
coordinate
to
parallel
axis,
around
Rotation
z
-
z
z x
y
1
P
2
P
3D Rotation around arbitrary axis 2
Rotation around axis through two points P1 and P1 .
More complex:
1. Translate such that axis goes through origin;
2. Rotate…
3. Translate back again.
3D Rotation around arbitrary axis 3
z x
y
1
P
2
P
Initial
z x
y
'
1
P
1. translate axis
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
z x
y
3. rotate around
z-axis
'
1
P
'
'
P2
4. rotate back
z x
y
'
1
P
'
P2
z x
y
1
P
2
P
5. translate back
3D Rotation around arbitrary axis 3
z x
y
1
P
2
P
Initial
z x
y
'
1
P
1. translate axis
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
z x
y
3. rotate around
z-axis
'
1
P
'
'
P2
4. rotate back
z x
y
'
1
P
'
P2
z x
y
1
P
2
P
5. translate back
T(P1) R
Rz(a)
R1
T(P1)
3D Rotation around arbitrary axis 3
z x
y
1
P
2
P
Initial
z x
y
'
1
P
1. translate axis
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
z x
y
3. rotate around
z-axis
'
1
P
'
'
P2
4. rotate back
z x
y
'
1
P
'
P2
z x
y
1
P
2
P
5. translate back
T(P1) R
Rz(a)
R1
T(P1)
M = T(P1) R1Rz(a) RT(P1)
3D Rotation around arbitrary axis 4
z x
y
'
1
P
'
P2
z x
y
2. rotate axis
'
1
P
'
'
P2
Difficult step:
Find rotation such that rotation axis aligns with z-axis.
Two options:
1. Step by step by step (see H&B, 309-312)
2. Direct derivation of matrix
R
3D Rotation around arbitrary axis 5
z
x
y
u
v
w
1. Construct orthonormal axis frame u, v, w;
2. Invent rotation matrix R, such that:
u is mapped to z-axis;
v is mapped to y-axis;
w is mapped to x-axis.
3D Rotation around arbitrary axis 6
z
x
y
u
v
w
Construct orthonormal axis frame u, v, w:
u = (P2P1) / |P2P1|
v = u  (1,0,0) / | u  (1,0,0) |
w = v  u
(If u = (a, 0, 0), then use (0, 1, 0))
This frame is orthonormal:
Unit length axes: u.u = v.v = w.w = 1
All axes perpendicular: u.v = v.w = w.u = 0
3D Rotation around arbitrary axis 7
z
x
y
u
v
w






































































































1
0
0
1
1
and
,
1
0
1
0
1
,
1
1
0
0
1
such that
in
Fill
1
0
0
0
0
0
0
:
matrix
rotation
Generic
33
32
31
23
22
21
13
12
11
z
y
x
z
y
x
z
y
x
w
w
w
v
v
v
u
u
u
r
r
r
r
r
r
r
r
r
R
R
R
R
R
3D Rotation around arbitrary axis 8
z
x
y
u
v
w
Done! But how to find R1 ?
1
0
0
0
0
0
0
:
Solution
1
0
0
1
1
and
,
1
0
1
0
1
,
1
1
0
0
1
such that
,
Fill






































































































z
y
x
z
y
x
z
y
x
z
y
x
z
y
x
z
y
x
u
u
u
v
v
v
w
w
w
w
w
w
v
v
v
u
u
u
R
R
R
R
R
 












z
z
z
y
y
y
x
x
x
w
v
u
w
v
u
w
v
u
w
v
u
M
Each rotation matrix is an orthonormal matrix M:
The frame u, v, w is orthonormal:
Unit length axes: u.u = v.v = w.w = 1
All axes perpendicular: u.v = v.w = w.u = 0.
Requested: M-1 such that M-1M = I
Inverse of rotation matrix 1
z
x
y
u
v
w
Requested: M-1 such that M-1M = I
Solution:
In words:
The inverse of a rotation matrix is the transpose.
(For a rotation around the origin).




























z
y
x
z
y
x
z
y
x
T
T
T
T
w
w
w
v
v
v
u
u
u
1
w
v
u
M
M
Inverse of rotation matrix 2
  I
w
w
v
w
u
w
w
v
v
v
u
v
w
u
v
u
u
u
w
v
u
w
v
u
M
M 












































1
0
0
0
1
0
0
0
1
T
T
T
T
Requested: M-1 such that M-1M = I
Solution: M-1 = M-T
Check:
Inverse of rotation matrix 3
1
1
0
0
0
0
0
0
0
0
0
0
0
0
1
'
'
'
or
,












































z
y
x
s
s
s
z
y
x
z
y
x
SP
P'
3D scaling
Scale with factors sx, sy,sz :
x’= sx x, y’= sy y, z’= sz z
or
More 3D transformations
+/- same as in 2D:
• Matrix concatenation by multiplication
• Reflection
• Shearing
• Transformations between coordinate systems
z
zz
zy
zx
y
yz
yy
yx
x
xz
xy
xx
b
z
a
y
a
x
a
z
b
z
a
y
a
x
a
y
b
z
a
y
a
x
a
x












'
'
'
Affine transformations 1
Generic name for these transformations:
affine transformations
Affine transformations 2
Properties:
1. Transformed coordinates x’,y’ and z’ are linearly
dependent on original coordinates x, y en z.
2. Parameters aij en bk are constant and determine type
of transformation;
3. Examples: translation, rotation, scaling, reflection
4. Parallel lines remain parallel
5. Only translation, rotation reflection: angles and
lengths are maintained
3D Viewing
• Viewing: virtual camera
• Projection
• Depth
• Visible lines and surfaces
• Surface rendering
3D Viewing pipeline 1
• Similar to making a photo
– Position and point virtuele camera, press button;
Projection plane aka
Viewing plane
• Pipeline has +/ same structure as in 2D
3D Viewing pipeline 2
MC: Modeling 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
3D viewing coordinates 1
Specification of projection:
P0 : View or eye point
Pref : Center or look-at point
V: View-up vector
(projection along vertical
axis)
zvp : positie view plane
P0
zw
yw
xw
Pref
N
V
P0, Pref , V: define viewing coordinate system
Several variants possible
3D viewing coordinates 2
P0
zw
yw
xw
Pref
N
V
zview
yview
xview
P0, Pref , V: define viewing coordinate system
Several variants possible
3D view coordinates 3
P0
zw
yw
xw
Pref
N
V
zview
yview
xview
u
)
,
,
(
:
and
lar to
perpendicu
z
y
x u
u
u



V
n
V
u
n
V
u
v
)
,
,
(
:
and
lar to
perpendicu
z
y
x v
v
v


 u
n
v
u
n
v
)
,
,
(
:
frame
axis
Derivation
ref
0
z
y
x n
n
n




N
N
n
P
P
N
n
3D viewing coördinaten 4
P0
zw
yw
xw
Pref
N
V
zview
yview
xview
n
u
v
RT
M
R
R
P
T 0


















W C,VC
z
y
x
z
y
x
z
y
x
n
n
n
v
v
v
u
u
u
:
Or
1
0
0
0
0
0
0
:
with
rotate
Next,
)
(
with
translate
First,
:
view
tion world
Transforma
Projection transformations
P1
P2
P’1
P’2
View plane
Parallel projection
P1
P2
P’1
P’2
View plane
Perspective projection
Orthogonal projections 1
P’1
P’2
Parallell projection:
Projection lines are parallel
Orthogonal projection:
Projection lines are parallel and
perpendicular to projection plane
Isometric projection:
Projection lines are parallel,
perpendicular to projection plane,
and have the same angle with axes.
P1
P2
P’1
P’2
P1
P2
x
y
z
Orthogonal projections 2
Orthogonal projection:
P’1
P’2
P1
P2
Trivial!
:
s)
coordinate
projection
to
s
coordinate
view
(from
)
,
,
(
of
Projection
z
z
y
y
x
x
z
y
x
p
p
p



Orthogonal projections 3
Clipping
window
zview
xview
yview
Near plane
Far plane
View volume
Orthogonal projections 4
zview
xview
yview
View volume
(xwmin, ywmin, znear)
(xwmax, ywmax, zfar)
Orthogonal projections 4
zview
xview
yview
View volume
(xwmin, ywmin, znear)
(xwmax, ywmax, zfar)
znorm
xnorm
ynorm
Normalized View volume
(1,1,1)
(-1,-1,-1)
Translation
Scaling
From right- to left handed
Perspective projection 1
P1
P2
P’1
P’2
View plane: z = zvp
Projection reference point
zview
xview
yview
View plane: orthogonal to zview axis.
Perspective projection 2
P = (x, y, z) R: Projection reference point
zview
xview
yview
(xr, yr, zr)
(xp, yp, zp)
To simplify,
Assume R in origin
View plane: z = zvp
Question: What is the projection of P
on the view plane?
Perspective projection 3
P = (x, y, z)
zview
xview
yview
(xp, yp, zp)
(0,0, 0)
R=
.
'
and
;
'
;
'
or
,
1
0
with
,
'
:
to
(origin)
from
Line
uz
z
uy
y
ux
x
u
u





 P
X
P
R
.
hence
'
:
plane
with
crossing
At
z
z
u
z
z
vp
vp 

y
z
z
y
x
z
z
x
vp
p
vp
p 
 and
gives
on
Substituti
View plane: z = zvp
Perspective projection 4
P = (x, y, z) View plane
zview
yview
Viewed from the side
R
z
y
zvp
yp
y
z
z
y
z
y
z
y
vp
p
vp
p


hence
:
that
see
can
We
Perspective projection 5
P = (x, y, z)
Clipping window
in View plane
zview
yview
R
zvp
W
wmax
wmin
Ratio between
W=wmaxwmin and zvp
determines strenght perspective
Viewed from the side
Viewed from the side
Perspective projection 6
Clipping window
in View plane
zview
yview
R

Ratio between
W=wmaxwmin and zvp
determines strenght perspective.
This ratio is 2tan(/2),
with  the view angle.
Perspective projection 7
zview
yview
R
Perspective projection 7
zview
yview
R
Perspective projection 7
R
Perspective projection 8
zview
yview
R
zvp
W
How to specify the ratio between W en zvp?
How to specify ‘how much’ perspective I want to see?
Option 1: Specify view angle .

Perspective projection 9
zview
yview
R
zvp
W
Use camera as metaphor. User specifies focal length f .
(20 mm – wide angle, 50 mm – normal, 100 mm – tele).
Application adjusts W and/or zvp, such that W/zvp = 24/f.
For x: W/zvp = 36/f.
f (mm)
24 mm
View volume orthogonal…
Clipping
window
zview
xview
yview
Near
clipping plane
Far
clipping plane
View volume
View volume perspective
Clipping
window
zview
xview
yview
Near
clipping plane
Far
clipping plane
View volume
R
To Normalized Coordinates…
zview
xview
yview
R
znorm
xnorm
ynorm
Normalized View volume
(1,1,1)
(1, 1, 1)
Rectangular frustum
View Volume
Side view Front view
Perspective projection 10
yview
R
zview
znorm
ynorm
Perspective transformation:
Distort space, such that perpendicular projection gives
an image in perspective.
Perspective projection 10
yview
R
2r
zn
zf
zview
znorm
ynorm
Simplest case:
Square window,
clipping plane coincides with view plane: zn=zvp
Perspective projection 11
yview
R
zn
zf
zview
znorm
ynorm
(-r, -r, zn)
((zf /zn)r, (zf /zn)r, zf )
2r
(-1,-1,-1)
(1,1,1)
(r,  r, zn)
(rzf /zn, rzf /zn, zf )
Perspective projection 11
yview
R
zview
znorm
ynorm
(1, 1, 1)
(1,1,1)
How to put this transformation in the pipeline?
How to process division by z?
Earlier: y
z
z
y
x
z
z
x
vp
p
vp
p 
 ,
Homogeneous coordinates (reprise)
• Add extra coordinate:
P = (px , py , pz , ph) or
x = (x, y, z, h)
• Cartesian coordinates: divide by h
x = (x/h, y/h, z/h)
• Points: h = 1 (temporary…)perspective: h = z !
.
/
/
/
:
by
given
are
s
coordinate
projected
such that
1
0
1
0
0
:
by
described
be
can
ation
transform
e
Perspectiv



































































h
z
h
y
h
x
z
y
x
z
y
x
t
s
s
s
t
s
s
s
t
s
s
s
h
z
y
x
h
h
h
p
p
p
v
v
v
z
zz
zy
zx
y
yz
yy
yx
x
xz
xy
xx
h
h
h
Homogeneous coordinates (reprise)
Perspective projection 12
xview
R
zview
znorm
ynorm
(r, r, zn)
(rzf /zn, rzf /zn, zf )
(1, 1, 1)
(1,1,1)
(r, r, zn)
.
0
,
/
:
gives
n
Elaboratio
.
1
also
then
,
and
/
If
.
1
then
,
and
If
.
/
)
(
is
form
Generic
.
First
















x
xz
xy
n
xx
p
f
n
f
p
n
x
xz
xy
xx
p
t
s
s
r
z
s
x
z
z
z
rz
x
x
z
z
r
x
z
t
z
s
y
s
x
s
x
x
Perspective projection 13
yview
R
zview
znorm
ynorm
(r, r, zn)
(rzf /zn, rzf /zn, zf )
(1, 1, 1)
(1,1,1)
.
0
),
/
(
:
Or
.
/
)
/
(
:
gives
,
as
Same
.
Next the








y
yz
yx
n
yy
n
p
t
s
s
r
z
s
z
y
r
z
y
x
y
Perspective projection 14
yview
R
zview
znorm
ynorm
(r, r, zn)
(rzf /zn, rzf /zn, zf )
(1, 1, 1)
(1,1,1)
.
0
,
2
,
gives
n
Elaboratio
.
1
then
,
If
.
1
then
,
If
.
/
)
(
:
is
form
Generic
.
:
Finally


















zy
zx
f
n
f
n
z
f
n
f
n
zz
f
f
p
n
z
zz
zy
zx
p
s
s
z
z
z
z
t
z
z
z
z
s
z
z
z
z
z
z
z
t
z
s
y
s
x
s
z
z
Perspective projection 15
.
/
/
/
:
from
follow
s
coordinate
projected
the
where
1
0
1
0
0
2
0
0
0
0
/
0
0
0
0
/
:
by
described
be
hence
can
ation
transform
e
Perspectiv











































































h
z
h
y
h
x
z
y
x
z
y
x
z
z
z
z
z
z
z
z
r
z
r
z
h
z
y
x
v
v
v
p
p
p
v
v
v
f
n
f
n
f
n
f
n
n
n
h
h
h
3D Viewport coordinates 1
znorm
xnorm
ynorm
Normalized View volume
(1,1,1)
(1, 1, 1)
zv xv
yv
3D screen
(xvmin, yvmin, 0)
(xvmax, yvvmax, 1)
scaling
translation
3D Viewport coordinaten 2

















































1
1
0
0
0
2
1
2
1
0
0
0
0
2
0
0
0
0
2
:
s
coordinate
screen
3D
to
s
coordinate
view
normalized
from
tion
Transforma
min
max
min
max
p
p
p
s
s
s
z
y
x
yv
yv
xv
xv
h
z
y
x
OpenGL 3D Viewing 1
3D Viewing in OpenGL:
• Position camera;
• Specify projection.
OpenGL 3D Viewing 2
z
x
y
View volume
Camera always in origin, in direction of negative z-axis.
Convenient for 2D, but not for 3D.
OpenGL 3D Viewing 3
Solution for view transform: Transform your model
such that you look at it in a convenient way.
Approach 1: Do it yourself. Apply rotations,
translations, scaling, etc., before rendering the
model. Surprisingly difficult and error-prone.
Approach 2: Use gluLookAt();
OpenGL 3D Viewing 4
MatrixMode(GL_MODELVIEW);
gluLookAt(x0,y0,z0, xref,yref,zref, Vx,Vy,Vz);
x0,y0,z0: P0, viewpoint, location of camera;
xref,yref,zref: Pref, centerpoint;
Vx,Vy,Vz: V, view-up vector.
Default: P0 = (0, 0, 0); Pref = (0, 0, 1); V=(0, 1, 0).
OpenGL 3D Viewing 5
z
x
y
Orthogonal projection:
MatrixMode(GL_PROJECTION);
glOrtho(xwmin, xwmax, ywmin, ywmax, dnear, dfar);
xwmin
xwmax
ywmin
ywmax
xwmin, xwmax, ywmin,ywmax:
specification window
dnear: distance to near clipping plane
dfar : distance to far clipping plane
Select dnear and dfar right:
dnear < dfar,
model fits between clipping planes.
OpenGL 3D Viewing 6
Perspective projection:
MatrixMode(GL_PROJECTION);
glFrustrum(xwmin, xwmax, ywmin, ywmax, dnear, dfar);
xwmin
xwmax
ywmin
ywmax
xwmin, xwmax, ywmin,ywmax:
specification window
dnear: distance to near clipping plane
dfar : distance to far clipping plane
z
x
y
Standard projection: xwmin = -xwmax,
ywmin = -ywmax
Select dnear and dfar right:
0 < dnear < dfar,
model fits between clipping planes.
OpenGL 3D Viewing 7
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
Visible surface detection
methods
Visibility
 Assumption: All polygons are opaque
 What polygons are visible with respect to your view frustum?
 Outside: View Frustum Clipping
 Remove polygons outside of the view volume
 For example, Liang-Barsky 3D Clipping
 Inside: Hidden Surface Removal
 Backface culling
 Polygons facing away from the viewer
 Occlusion
 Polygons farther away are obscured by closer polygons
 Full or partially occluded portions
 Why should we remove these polygons?
 Avoid unnecessary expensive operations on these polygons later
No Lines Removed
Hidden Lines Removed
Hidden Surfaces Removed
Occlusion: Full, Partial, None
Full Partial None
l The rectangle is closer than the triangle
l Should appear in front of the triangle
Backface Culling
 Avoid drawing polygons facing away from the viewer
 Front-facing polygons occlude these polygons in a closed
polyhedron
 Test if a polygon is front- or back-facing?
front-facing
back-facing
Ideas?
Detecting Back-face Polygons
 The polygon normal of a …
 front-facing polygon points towards the viewer
 back-facing polygon points away from the viewer
If (n  v) > 0  “back-face”
If (n  v) ≤ 0  “front-face”
v = view vector
 Eye-space test … EASY!
 “back-face” if nz < 0
 glCullFace(GL_BACK)
back
front
Polygon Normals
 Let polygon vertices v0, v1, v2,..., vn - 1 be in
counterclockwise order and co-planar
 Calculate normal with cross product:
n = (v1 - v0) X (vn - 1 - v0)
 Normalize to unit vector with n/║n║
v0
v1
v2
v3
v4
n
Normal Direction
 Vertices counterclockwise  Front-facing
 Vertices clockwise  Back-facing
0
1
2
0
2
1
Front facing Back facing
Painter’s Algorithm (1)
 Assumption: Later projected polygons overwrite earlier
projected polygons
Graphics Pipeline
1 1
2 2
3 3
Oops! The red polygon
Should be obscured by
the blue polygon
Painter’s Algorithm (2)
 Main Idea
 A painter creates a picture
by drawing background
scene elemens before
foreground ones
 Requirements
 Draw polygons in back-to-
front order
 Need to sort the polygons
by depth order to get a
correct image
from Shirley
Painter’s Algorithm (3)
 Sort by the depth of each polygon
Graphics Pipeline
1 1
2 2
3 3
depth
Painter’s Algorithm (4)
 Compute zmin ranges for each polygon
 Project polygons with furthest zmin first
(z) depth
zmin
zmin
zmin
zmin
Painter’s Algorithm (5)
 Problem: Can you get a total sorting?
zmin
zmin
zmin
zmin
Correct?
Painter’s Algorithm (6)
 Cyclic Overlap
 How do we sort these three polygons?
 Sorting is nontrivial
 Split polygons in order to get a total ordering
 Not easy to do in general
Visibility
 How do we ensure that closer polygons
overwrite further ones in general?
Z-Buffer
 Depth buffer (Z-Buffer)
 A secondary image buffer that holds depth values
 Same pixel resolution as the color buffer
 Why is it called a Z-Buffer?
 After eye space, depth is simply the z-coordinate
 Sorting is done at the pixel level
 Rule: Only draw a polygon at a pixel if it is closer
than a polygon that has already been drawn to
this pixel
Z-Buffer Algorithm
 Visibility testing is done during rasterization
Z-buffer: A Secondary Buffer
DAM Entertainment
Color buffer Depth buffer
Z-Buffer
 How do we calculate the depth values on the polygon interior?
P1
P2
P3
P4
ys za zp zb
Scanline order
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
)
(
b
a
p
a
a
b
a
p
s
b
s
a
x
x
x
x
z
z
z
z
y
y
y
y
z
z
z
z
y
y
y
y
z
z
z
z















2
1
1
1
2
1
4
1
1
1
4
1
Bilinear Interpolation
Z-buffer - Example
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
Z-buffer
Screen

 
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
  
 

  
 

Parallel with
the image plane



   
   
   
  
 

 

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
Not Parallel
Z-Buffer Algorithm
 Algorithm easily handles this case
Z-buffering in OpenGL
 Create depth buffer by setting GLUT_DEPTH flag in
glutInitDisplayMode()or the appropriate
flag in the PIXELFORMATDESCRIPTOR.
 Enable per-pixel depth testing with
glEnable(GL_DEPTH_TEST)
 Clear depth buffer by setting GL_DEPTH_BUFFER_BIT
in glClear()

Mais conteúdo relacionado

Mais procurados

Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformationAnkit Garg
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformationsMohd Arif
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmrajivagarwal23dei
 
2 d viewing computer graphics
2 d viewing computer graphics2 d viewing computer graphics
2 d viewing computer graphicsKALESHWAR KUMAR
 
Overview of 2D and 3D Transformation
Overview of 2D and 3D TransformationOverview of 2D and 3D Transformation
Overview of 2D and 3D TransformationDheeraj Sadawarte
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)Timbal Mayank
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphicsSafayet Hossain
 
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPTHOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPTAhtesham Ullah khan
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalAnkit Garg
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in GraphicsRajani Thite
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalPunyajoy Saha
 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
 

Mais procurados (20)

Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
2 d viewing computer graphics
2 d viewing computer graphics2 d viewing computer graphics
2 d viewing computer graphics
 
Overview of 2D and 3D Transformation
Overview of 2D and 3D TransformationOverview of 2D and 3D Transformation
Overview of 2D and 3D Transformation
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Bezier curve computer graphics
Bezier curve computer graphics Bezier curve computer graphics
Bezier curve computer graphics
 
Spline representations
Spline representationsSpline representations
Spline representations
 
Shading
ShadingShading
Shading
 
Curves and surfaces
Curves and surfacesCurves and surfaces
Curves and surfaces
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
 
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPTHOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
Halftoning in Computer Graphics
Halftoning  in Computer GraphicsHalftoning  in Computer Graphics
Halftoning in Computer Graphics
 

Semelhante a Cs8092 computer graphics and multimedia unit 3

3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphicssabbirantor
 
From Polygons to Quadratics.pptx
From Polygons to Quadratics.pptxFrom Polygons to Quadratics.pptx
From Polygons to Quadratics.pptxyaswanthnaik27
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)RohitK71
 
5_6221983039971394498.pptx
5_6221983039971394498.pptx5_6221983039971394498.pptx
5_6221983039971394498.pptxNachiketKadlag1
 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics FundamentalsMuhammed Afsal Villan
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEThiyagarajan G
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics PipelineMark Kilgard
 
Surface models
Surface modelsSurface models
Surface modelsnmahi96
 
Implicit Interpolation Analytical Curves
Implicit Interpolation Analytical CurvesImplicit Interpolation Analytical Curves
Implicit Interpolation Analytical CurvesSharath Kumar
 
Saad alsheekh multi view
Saad alsheekh  multi viewSaad alsheekh  multi view
Saad alsheekh multi viewSaadAlSheekh1
 

Semelhante a Cs8092 computer graphics and multimedia unit 3 (20)

1422798749.2779lecture 5
1422798749.2779lecture 51422798749.2779lecture 5
1422798749.2779lecture 5
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
From Polygons to Quadratics.pptx
From Polygons to Quadratics.pptxFrom Polygons to Quadratics.pptx
From Polygons to Quadratics.pptx
 
Virtual reality
Virtual realityVirtual reality
Virtual reality
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)
 
testpang
testpangtestpang
testpang
 
Geometric model & curve
Geometric model & curveGeometric model & curve
Geometric model & curve
 
5_6221983039971394498.pptx
5_6221983039971394498.pptx5_6221983039971394498.pptx
5_6221983039971394498.pptx
 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals
 
Elhabian_curves10.pdf
Elhabian_curves10.pdfElhabian_curves10.pdf
Elhabian_curves10.pdf
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
 
curve one
curve onecurve one
curve one
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics Pipeline
 
Surface models
Surface modelsSurface models
Surface models
 
3D Transformation
3D Transformation 3D Transformation
3D Transformation
 
Implicit Interpolation Analytical Curves
Implicit Interpolation Analytical CurvesImplicit Interpolation Analytical Curves
Implicit Interpolation Analytical Curves
 
1533 game mathematics
1533 game mathematics1533 game mathematics
1533 game mathematics
 
Saad alsheekh multi view
Saad alsheekh  multi viewSaad alsheekh  multi view
Saad alsheekh multi view
 
Curves
CurvesCurves
Curves
 

Mais de SIMONTHOMAS S

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1SIMONTHOMAS S
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5SIMONTHOMAS S
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4SIMONTHOMAS S
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3SIMONTHOMAS S
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2SIMONTHOMAS S
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1SIMONTHOMAS S
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5SIMONTHOMAS S
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4SIMONTHOMAS S
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3SIMONTHOMAS S
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2SIMONTHOMAS S
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1SIMONTHOMAS S
 

Mais de SIMONTHOMAS S (20)

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1
 
Mg6088 spm unit-5
Mg6088 spm unit-5Mg6088 spm unit-5
Mg6088 spm unit-5
 
Mg6088 spm unit-4
Mg6088 spm unit-4Mg6088 spm unit-4
Mg6088 spm unit-4
 
Mg6088 spm unit-3
Mg6088 spm unit-3Mg6088 spm unit-3
Mg6088 spm unit-3
 
Mg6088 spm unit-2
Mg6088 spm unit-2Mg6088 spm unit-2
Mg6088 spm unit-2
 
Mg6088 spm unit-1
Mg6088 spm unit-1Mg6088 spm unit-1
Mg6088 spm unit-1
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
 

Último

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 

Último (20)

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 

Cs8092 computer graphics and multimedia unit 3

  • 1. UNIT III THREE-DIMENSIONAL GRAPHICS Three dimensional concepts; Three dimensional object representations — Polygon surfaces- Polygon tables- Plane equations — Polygon meshes; Curved Lines and surfaces, Quadratic surfaces; Blobby objects; Spline representations — Bezier curves and surfaces -B-Spline curves and surfaces. TRANSFORMATION AND VIEWING: Three dimensional geometric and modeling transformations — Translation, Rotation, Scaling, composite transformations; Three dimensional viewing — viewing pipeline, viewing coordinates, Projections, Clipping; Visible surface detection methods. 1
  • 2. 3D Object Representation • A surface can be analytically generated using its function involving the coordinates. • An object can be represented in terms of its vertices, edges and polygons. (Wire Frame, Polygonal Mesh etc.) • Curves and surfaces can also be designed using splines by specifying a set of few control points. 2 y = f(x,z) x y z . . .
  • 3. Solid Modeling - Polyhedron • A polyhedron is a connected mesh of simple planar polygons that encloses a finite amount of space. • A polyhedron is a special case of a polygon mesh that satisfies the following properties: • Every edge is shared by exactly two faces. • At least three edges meet at each vertex. • Faces do not interpenetrate. Faces at most touch along a common edge. • Euler’s formula : If F, E, V represent the number of faces, vertices and edges of a polyhedron, then V + F  E = 2. 3
  • 4. 3D Object Representation • The data for polygonal meshes can be represented in two ways. • Method 1: • Vertex List • Normal List • Face List (Polygon List) • Method 2: • Vertex List • Edge List • Face List (Polygon List) 4
  • 5. 5 0 1 2 3 4 5 6 7 Vertices and Faces - E.g. Cube 0 1 2 3 4 5 Face Index Vertex Index
  • 6. 6 Data representation using vertex, face and normal lists: Vertex List Normal List Polygon List 30 30 30 0.0 0.0 1.0 0 1 2 3 -30 30 30 0.0 0.0 -1.0 4 7 6 5 -30 -30 30 0.0 1.0 0.0 0 4 5 1 30 -30 30 -1.0 0.0 0.0 1 5 6 2 30 30 -30 0.0 -1.0 0.0 2 6 7 3 -30 30 -30 1.0 0.0 0.0 3 7 4 0 -30 -30 -30 30 -30 -30
  • 7. 7 Vertex List Edge List Polygon List x[i] y[i] z[i] L[j] M[j] P[k] Q[k] R[k] S[k] 30 30 30 0 1 0 1 2 3 -30 30 30 1 2 4 7 6 5 -30 -30 30 2 3 0 4 5 1 30 -30 30 3 0 1 5 6 2 30 30 -30 4 5 2 6 7 3 -30 30 -30 5 6 3 7 4 0 -30 -30 -30 6 7 30 -30 -30 7 4 0 4 1 5 2 6 3 7 Data representation using vertex, face and edge lists:
  • 8. Normal Vectors (OpenGL) 8 Assigning a normal vector to a polygon: glBegin(GL_POLYGON); glNormal3f(xn,yn,zn); glVertex3f(x1,y1,z1); glVertex3f(x2,y2,z2); glVertex3f(x3,y3,z3); glVertex3f(x4,y4,z4); glEnd(); Enabling automatic conversion of normal vectors to unit vectors: glEnable(GL_NORMALIZE);
  • 9. Regular Polyhedra (Platonic Solids) • If all the faces of a polyhedron are identical, and each is a regular polygon, then the object is called a platonic solid. • Only five such objects exist. 9
  • 10. Wire-Frame Models • If the object is defined only by a set of nodes (vertices), and a set of lines connecting the nodes, then the resulting object representation is called a wire-frame model. • Very suitable for engineering applications. • Simplest 3D Model - easy to construct. • Easy to clip and manipulate. • Not suitable for building realistic models. 10
  • 11. Wire Frame Models - OpenGL 11 Some Wireframe Models in OpenGL: Cube: glutWireCube(Gldouble size); Sphere: glutWireSphere(…); Torus: glutWireTorus(…); Teapot: glutWireTeapot(Gldouble size); Cone: glutWireCone(…); (…) Refer text for list of arguments.
  • 12. Wire Frame Model - The Teapot 12
  • 13. Polygonal Mesh • Three-dimensional surfaces and solids can be approximated by a set of polygonal and line elements. Such surfaces are called polygonal meshes. • The set of polygons or faces, together form the “skin” of the object. • This method can be used to represent a broad class of solids/surfaces in graphics. • A polygonal mesh can be rendered using hidden surface removal algorithms. 13
  • 14. Polygonal Mesh - Example 14
  • 15. Solid Modeling • Polygonal meshes can be used in solid modeling. • An object is considered solid if the polygons fit together to enclose a space. • In solid models, it is necessary to incorporate directional information on each face by using the normal vector to the plane of the face, and it is used in the shading process. 15
  • 16. Solid Modeling - Example 16
  • 17. Solid Modeling - OpenGL 17 Some predefined Solid Models in OpenGL: Cube: glutSolidCube(Gldouble size); Sphere: glutSolidSphere(…); Torus: glutSolidTorus(…); Teapot: glutSolidTeapot(Gldouble size); Cone: glutSolidCone(…); (…) Arguments same as wire-frame models.
  • 18. 18 Z X Y y = f(x, z) Surface Modeling Many surfaces can be represented by an explicit function of two independent variables, such as y = f(x, z).
  • 19. Surface Modeling - Example 19
  • 20. Sweep Representations • Sweep representations are useful for both surface modeling and solid modeling. • A large class of shapes (both surfaces and solid models) can be formed by sweeping or extruding a 2D shape through space. • Sweep representations are useful for constructing 3-D objects that posses translational or rotational symmetries. 20
  • 21. Extruded Shapes - Examples 21 A polyhedron obtained by sweeping (extruding) a polygon along a straight line is called a prism.
  • 22. Surface of Revolution • A surface of revolution is obtained by revolving a curve (known as the base curve or profile curve) about an axis. • In other words, a surface of revolution is generated by a rotational sweep of a 2D curve. • The symmetry of the surface of revolution makes it a very useful object in presentation graphics. 22
  • 23. 23 Z X Y y = f(x) r y y (x, z) y = f(r) x 2 2 z x r   Surface of Revolution
  • 24. 24 The three-dimensional surface obtained by revolving the curve y = f(x) about the y-axis is obtained by replacing x with sqrt(x*x + z*z). The surface of revolution is thus given by   y f x z   2 2 Surface of Revolution
  • 26. Quad trees Quad trees are generated by successively dividing a 2-D region(usually a square) into quadrants. Each node in the quadtree has 4 data elements, one for each of the quadrants in the region. If all the pixels within a quadrant have the same color (a homogeneous quadrant), the corresponding data element in the node stores that color. For a heterogeneous region of space, the successive divisions into quadrants continues until all quadrants are homogeneous. 26
  • 27. Octrees • An octree encoding scheme divide regions of 3-D space(usually a cube) in to octants and stores 8 data elements in each node of the tree. • Individual elements of a 3-D space are called volume elements or voxels. • When all voxels in an octant are of the same type, this type value is stored in the corresponding data element of the node. Any heterogeneous octant is subdivided into octants and the corresponding data element in the node points to the next node in the octree. 27
  • 29. 29 Bezier Curves The Bezier curve only approximates the control points and doesn’t actually pass through all of them.
  • 30. 30 Inputs: n control points (xi, yi), i = 0, 1,2, …n-1   , 0 , 0 , ( ) ( ) ( ) ( ) 0 1 ! ( ) (1 ) ! ! m b m i i i m b m i i i i m i m i x u Bez u x y u Bez u y u m m m Bez u u u and i i i m i                          m = n1 Bezier Curves
  • 31. 31 Inputs: n control points (xi, yi), i = 0, 1,2, …m 0 ( ) ( ) , 0 1 ( ) ( ( ), ( )) ( , ) m m i i i i i i i r u Bez u r u where r u x u y u r x y        Bezier Curves
  • 32. Properties of Bezier Curve • Bezier curve is a polynomial of degree one less than the number of control points 32 p0 p2 p1 p0 p2 p1 p3 Quadratic Curve Cubic Curve
  • 33. Properties of Bezier Curve (cont.) • Bezier curve always passes through the first and last points; i.e. and 33 0 (0) x x  , 0 (0) y y  (1) m x x  (1) m y y 
  • 34. Properties of Bezier Curve (cont) • The slop at the beginning of the curve is along the line joining the first two control points, and the slope at the end of the curve is along the line joining the last two points. 34 p0 p2 p1 p0 p2 p1
  • 35. Properties of Bezier Curve (cont) • Bezier blending functions are all positive and the sum is always 1. • This means that the curve is the weighted sum of the control points. 35 , 0 ( ) 1 m m i i Bez u   
  • 36. Design Technique using Bezier Curves: • A closed Bezier curve can be generated by specifying the first and last control points at the same location 36 p4 p0=p5 p1 p2 p3
  • 37. Design Technique (Cont) • A Bezier curve can be made to pass closer to a given coordinate position by assigning multiple control points to that position. 37 p0 p1 = p2 p3 p4
  • 38. • Bezier curve can be form by piecing of several Bezier section with lower degree. 38 p0 p1 p2= p’0 p’2 p’3 p’1
  • 39. 39 (Not Important!) , 0 0 ( , ) ( ) ( ) , 0 1, 0 1 ( , ) ( ( , ), ( , ), ( , )) ( , , ) m l m i l j i j i j ij ij ij ij r u v Bez u Bez v r u v where r u v x u v y u v z u v r x y z           Bezier Surfaces
  • 40. 40 A set of 16 control points The Bezier Patch Bezier Patch
  • 41. 41 Utah Teapot Defined Using Control Points Bezier Patch
  • 42. 42 Utah Teapot Generated Using Bezier Patches Bezier Patch
  • 43. 3D Translation 1 Translate over vector (tx, ty, tz ): x’=x+ tx, y’=y+ ty , z’=z+ tz or x y P P+T T z                                    z y x t t t z y x z y x T P P T P P' en , ' ' ' ' met ,
  • 44. 3D Translation 2 In 4D homogeneous coordinates: x y P P+T T z 1 1 0 0 0 1 0 0 0 1 0 0 0 1 1 ' ' ' or ,                                             z y x t t t z y x z y x MP P'
  • 46. 3D Rotation 2 z x y Rotation around axis: • Counterclockwise, viewed from rotation axis z x y z x y
  • 47. 3D Rotation 3 z x y z x y z x y z y y x x z    x z z y y x    Rotation around axes: Cyclic permutation coordinate axes x z y x   
  • 48. 3D Rotatie 4 z y y x x z    1 0 0 0 0 1 0 0 0 0 cos sin 0 0 sin cos ) ( with , ) ( Or ' cos sin ' sin cos ' : as - around angle over Rotate                       a a a a a a a a a a a z z z z y x y y x x z R P R P' 1 0 0 0 0 cos sin 0 0 sin cos 0 0 0 0 1 ) ( with , ) ( Or ' cos sin ' sin cos ' : as - around angle over Rotate                       a a a a a a a a a a a x x x x z y z z y y x R P R P'
  • 49. 1 3D Rotation around arbitrary axis 1 z P x y P’ a Q 2 3 Q)P )T( ( T(Q)R P' Q Q Q z   a : Or . over back Translate 3. axis; - around Rotate 2. ; over Translate 1. : rotation 2D as Similar as. - the example. For . point through axis, coordinate to parallel axis, around Rotation z - z
  • 50. z x y 1 P 2 P 3D Rotation around arbitrary axis 2 Rotation around axis through two points P1 and P1 . More complex: 1. Translate such that axis goes through origin; 2. Rotate… 3. Translate back again.
  • 51. 3D Rotation around arbitrary axis 3 z x y 1 P 2 P Initial z x y ' 1 P 1. translate axis ' P2 z x y 2. rotate axis ' 1 P ' ' P2 z x y 3. rotate around z-axis ' 1 P ' ' P2 4. rotate back z x y ' 1 P ' P2 z x y 1 P 2 P 5. translate back
  • 52. 3D Rotation around arbitrary axis 3 z x y 1 P 2 P Initial z x y ' 1 P 1. translate axis ' P2 z x y 2. rotate axis ' 1 P ' ' P2 z x y 3. rotate around z-axis ' 1 P ' ' P2 4. rotate back z x y ' 1 P ' P2 z x y 1 P 2 P 5. translate back T(P1) R Rz(a) R1 T(P1)
  • 53. 3D Rotation around arbitrary axis 3 z x y 1 P 2 P Initial z x y ' 1 P 1. translate axis ' P2 z x y 2. rotate axis ' 1 P ' ' P2 z x y 3. rotate around z-axis ' 1 P ' ' P2 4. rotate back z x y ' 1 P ' P2 z x y 1 P 2 P 5. translate back T(P1) R Rz(a) R1 T(P1) M = T(P1) R1Rz(a) RT(P1)
  • 54. 3D Rotation around arbitrary axis 4 z x y ' 1 P ' P2 z x y 2. rotate axis ' 1 P ' ' P2 Difficult step: Find rotation such that rotation axis aligns with z-axis. Two options: 1. Step by step by step (see H&B, 309-312) 2. Direct derivation of matrix R
  • 55. 3D Rotation around arbitrary axis 5 z x y u v w 1. Construct orthonormal axis frame u, v, w; 2. Invent rotation matrix R, such that: u is mapped to z-axis; v is mapped to y-axis; w is mapped to x-axis.
  • 56. 3D Rotation around arbitrary axis 6 z x y u v w Construct orthonormal axis frame u, v, w: u = (P2P1) / |P2P1| v = u  (1,0,0) / | u  (1,0,0) | w = v  u (If u = (a, 0, 0), then use (0, 1, 0)) This frame is orthonormal: Unit length axes: u.u = v.v = w.w = 1 All axes perpendicular: u.v = v.w = w.u = 0
  • 57. 3D Rotation around arbitrary axis 7 z x y u v w                                                                                                       1 0 0 1 1 and , 1 0 1 0 1 , 1 1 0 0 1 such that in Fill 1 0 0 0 0 0 0 : matrix rotation Generic 33 32 31 23 22 21 13 12 11 z y x z y x z y x w w w v v v u u u r r r r r r r r r R R R R R
  • 58. 3D Rotation around arbitrary axis 8 z x y u v w Done! But how to find R1 ? 1 0 0 0 0 0 0 : Solution 1 0 0 1 1 and , 1 0 1 0 1 , 1 1 0 0 1 such that , Fill                                                                                                       z y x z y x z y x z y x z y x z y x u u u v v v w w w w w w v v v u u u R R R R R
  • 59.               z z z y y y x x x w v u w v u w v u w v u M Each rotation matrix is an orthonormal matrix M: The frame u, v, w is orthonormal: Unit length axes: u.u = v.v = w.w = 1 All axes perpendicular: u.v = v.w = w.u = 0. Requested: M-1 such that M-1M = I Inverse of rotation matrix 1 z x y u v w
  • 60. Requested: M-1 such that M-1M = I Solution: In words: The inverse of a rotation matrix is the transpose. (For a rotation around the origin).                             z y x z y x z y x T T T T w w w v v v u u u 1 w v u M M Inverse of rotation matrix 2
  • 61.   I w w v w u w w v v v u v w u v u u u w v u w v u M M                                              1 0 0 0 1 0 0 0 1 T T T T Requested: M-1 such that M-1M = I Solution: M-1 = M-T Check: Inverse of rotation matrix 3
  • 63. More 3D transformations +/- same as in 2D: • Matrix concatenation by multiplication • Reflection • Shearing • Transformations between coordinate systems
  • 65. Affine transformations 2 Properties: 1. Transformed coordinates x’,y’ and z’ are linearly dependent on original coordinates x, y en z. 2. Parameters aij en bk are constant and determine type of transformation; 3. Examples: translation, rotation, scaling, reflection 4. Parallel lines remain parallel 5. Only translation, rotation reflection: angles and lengths are maintained
  • 66. 3D Viewing • Viewing: virtual camera • Projection • Depth • Visible lines and surfaces • Surface rendering
  • 67. 3D Viewing pipeline 1 • Similar to making a photo – Position and point virtuele camera, press button; Projection plane aka Viewing plane • Pipeline has +/ same structure as in 2D
  • 68. 3D Viewing pipeline 2 MC: Modeling 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
  • 69. 3D viewing coordinates 1 Specification of projection: P0 : View or eye point Pref : Center or look-at point V: View-up vector (projection along vertical axis) zvp : positie view plane P0 zw yw xw Pref N V P0, Pref , V: define viewing coordinate system Several variants possible
  • 70. 3D viewing coordinates 2 P0 zw yw xw Pref N V zview yview xview P0, Pref , V: define viewing coordinate system Several variants possible
  • 71. 3D view coordinates 3 P0 zw yw xw Pref N V zview yview xview u ) , , ( : and lar to perpendicu z y x u u u    V n V u n V u v ) , , ( : and lar to perpendicu z y x v v v    u n v u n v ) , , ( : frame axis Derivation ref 0 z y x n n n     N N n P P N n
  • 72. 3D viewing coördinaten 4 P0 zw yw xw Pref N V zview yview xview n u v RT M R R P T 0                   W C,VC z y x z y x z y x n n n v v v u u u : Or 1 0 0 0 0 0 0 : with rotate Next, ) ( with translate First, : view tion world Transforma
  • 73. Projection transformations P1 P2 P’1 P’2 View plane Parallel projection P1 P2 P’1 P’2 View plane Perspective projection
  • 74. Orthogonal projections 1 P’1 P’2 Parallell projection: Projection lines are parallel Orthogonal projection: Projection lines are parallel and perpendicular to projection plane Isometric projection: Projection lines are parallel, perpendicular to projection plane, and have the same angle with axes. P1 P2 P’1 P’2 P1 P2 x y z
  • 75. Orthogonal projections 2 Orthogonal projection: P’1 P’2 P1 P2 Trivial! : s) coordinate projection to s coordinate view (from ) , , ( of Projection z z y y x x z y x p p p   
  • 77. Orthogonal projections 4 zview xview yview View volume (xwmin, ywmin, znear) (xwmax, ywmax, zfar)
  • 78. Orthogonal projections 4 zview xview yview View volume (xwmin, ywmin, znear) (xwmax, ywmax, zfar) znorm xnorm ynorm Normalized View volume (1,1,1) (-1,-1,-1) Translation Scaling From right- to left handed
  • 79. Perspective projection 1 P1 P2 P’1 P’2 View plane: z = zvp Projection reference point zview xview yview View plane: orthogonal to zview axis.
  • 80. Perspective projection 2 P = (x, y, z) R: Projection reference point zview xview yview (xr, yr, zr) (xp, yp, zp) To simplify, Assume R in origin View plane: z = zvp Question: What is the projection of P on the view plane?
  • 81. Perspective projection 3 P = (x, y, z) zview xview yview (xp, yp, zp) (0,0, 0) R= . ' and ; ' ; ' or , 1 0 with , ' : to (origin) from Line uz z uy y ux x u u       P X P R . hence ' : plane with crossing At z z u z z vp vp   y z z y x z z x vp p vp p   and gives on Substituti View plane: z = zvp
  • 82. Perspective projection 4 P = (x, y, z) View plane zview yview Viewed from the side R z y zvp yp y z z y z y z y vp p vp p   hence : that see can We
  • 83. Perspective projection 5 P = (x, y, z) Clipping window in View plane zview yview R zvp W wmax wmin Ratio between W=wmaxwmin and zvp determines strenght perspective Viewed from the side
  • 84. Viewed from the side Perspective projection 6 Clipping window in View plane zview yview R  Ratio between W=wmaxwmin and zvp determines strenght perspective. This ratio is 2tan(/2), with  the view angle.
  • 88. Perspective projection 8 zview yview R zvp W How to specify the ratio between W en zvp? How to specify ‘how much’ perspective I want to see? Option 1: Specify view angle . 
  • 89. Perspective projection 9 zview yview R zvp W Use camera as metaphor. User specifies focal length f . (20 mm – wide angle, 50 mm – normal, 100 mm – tele). Application adjusts W and/or zvp, such that W/zvp = 24/f. For x: W/zvp = 36/f. f (mm) 24 mm
  • 92. To Normalized Coordinates… zview xview yview R znorm xnorm ynorm Normalized View volume (1,1,1) (1, 1, 1) Rectangular frustum View Volume
  • 93. Side view Front view Perspective projection 10 yview R zview znorm ynorm Perspective transformation: Distort space, such that perpendicular projection gives an image in perspective.
  • 94. Perspective projection 10 yview R 2r zn zf zview znorm ynorm Simplest case: Square window, clipping plane coincides with view plane: zn=zvp
  • 95. Perspective projection 11 yview R zn zf zview znorm ynorm (-r, -r, zn) ((zf /zn)r, (zf /zn)r, zf ) 2r (-1,-1,-1) (1,1,1)
  • 96. (r,  r, zn) (rzf /zn, rzf /zn, zf ) Perspective projection 11 yview R zview znorm ynorm (1, 1, 1) (1,1,1) How to put this transformation in the pipeline? How to process division by z? Earlier: y z z y x z z x vp p vp p   ,
  • 97. Homogeneous coordinates (reprise) • Add extra coordinate: P = (px , py , pz , ph) or x = (x, y, z, h) • Cartesian coordinates: divide by h x = (x/h, y/h, z/h) • Points: h = 1 (temporary…)perspective: h = z !
  • 99. Perspective projection 12 xview R zview znorm ynorm (r, r, zn) (rzf /zn, rzf /zn, zf ) (1, 1, 1) (1,1,1) (r, r, zn) . 0 , / : gives n Elaboratio . 1 also then , and / If . 1 then , and If . / ) ( is form Generic . First                 x xz xy n xx p f n f p n x xz xy xx p t s s r z s x z z z rz x x z z r x z t z s y s x s x x
  • 100. Perspective projection 13 yview R zview znorm ynorm (r, r, zn) (rzf /zn, rzf /zn, zf ) (1, 1, 1) (1,1,1) . 0 ), / ( : Or . / ) / ( : gives , as Same . Next the         y yz yx n yy n p t s s r z s z y r z y x y
  • 101. Perspective projection 14 yview R zview znorm ynorm (r, r, zn) (rzf /zn, rzf /zn, zf ) (1, 1, 1) (1,1,1) . 0 , 2 , gives n Elaboratio . 1 then , If . 1 then , If . / ) ( : is form Generic . : Finally                   zy zx f n f n z f n f n zz f f p n z zz zy zx p s s z z z z t z z z z s z z z z z z z t z s y s x s z z
  • 103. 3D Viewport coordinates 1 znorm xnorm ynorm Normalized View volume (1,1,1) (1, 1, 1) zv xv yv 3D screen (xvmin, yvmin, 0) (xvmax, yvvmax, 1) scaling translation
  • 104. 3D Viewport coordinaten 2                                                  1 1 0 0 0 2 1 2 1 0 0 0 0 2 0 0 0 0 2 : s coordinate screen 3D to s coordinate view normalized from tion Transforma min max min max p p p s s s z y x yv yv xv xv h z y x
  • 105. OpenGL 3D Viewing 1 3D Viewing in OpenGL: • Position camera; • Specify projection.
  • 106. OpenGL 3D Viewing 2 z x y View volume Camera always in origin, in direction of negative z-axis. Convenient for 2D, but not for 3D.
  • 107. OpenGL 3D Viewing 3 Solution for view transform: Transform your model such that you look at it in a convenient way. Approach 1: Do it yourself. Apply rotations, translations, scaling, etc., before rendering the model. Surprisingly difficult and error-prone. Approach 2: Use gluLookAt();
  • 108. OpenGL 3D Viewing 4 MatrixMode(GL_MODELVIEW); gluLookAt(x0,y0,z0, xref,yref,zref, Vx,Vy,Vz); x0,y0,z0: P0, viewpoint, location of camera; xref,yref,zref: Pref, centerpoint; Vx,Vy,Vz: V, view-up vector. Default: P0 = (0, 0, 0); Pref = (0, 0, 1); V=(0, 1, 0).
  • 109. OpenGL 3D Viewing 5 z x y Orthogonal projection: MatrixMode(GL_PROJECTION); glOrtho(xwmin, xwmax, ywmin, ywmax, dnear, dfar); xwmin xwmax ywmin ywmax xwmin, xwmax, ywmin,ywmax: specification window dnear: distance to near clipping plane dfar : distance to far clipping plane Select dnear and dfar right: dnear < dfar, model fits between clipping planes.
  • 110. OpenGL 3D Viewing 6 Perspective projection: MatrixMode(GL_PROJECTION); glFrustrum(xwmin, xwmax, ywmin, ywmax, dnear, dfar); xwmin xwmax ywmin ywmax xwmin, xwmax, ywmin,ywmax: specification window dnear: distance to near clipping plane dfar : distance to far clipping plane z x y Standard projection: xwmin = -xwmax, ywmin = -ywmax Select dnear and dfar right: 0 < dnear < dfar, model fits between clipping planes.
  • 111. OpenGL 3D Viewing 7 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
  • 113. Visibility  Assumption: All polygons are opaque  What polygons are visible with respect to your view frustum?  Outside: View Frustum Clipping  Remove polygons outside of the view volume  For example, Liang-Barsky 3D Clipping  Inside: Hidden Surface Removal  Backface culling  Polygons facing away from the viewer  Occlusion  Polygons farther away are obscured by closer polygons  Full or partially occluded portions  Why should we remove these polygons?  Avoid unnecessary expensive operations on these polygons later
  • 117. Occlusion: Full, Partial, None Full Partial None l The rectangle is closer than the triangle l Should appear in front of the triangle
  • 118. Backface Culling  Avoid drawing polygons facing away from the viewer  Front-facing polygons occlude these polygons in a closed polyhedron  Test if a polygon is front- or back-facing? front-facing back-facing Ideas?
  • 119. Detecting Back-face Polygons  The polygon normal of a …  front-facing polygon points towards the viewer  back-facing polygon points away from the viewer If (n  v) > 0  “back-face” If (n  v) ≤ 0  “front-face” v = view vector  Eye-space test … EASY!  “back-face” if nz < 0  glCullFace(GL_BACK) back front
  • 120. Polygon Normals  Let polygon vertices v0, v1, v2,..., vn - 1 be in counterclockwise order and co-planar  Calculate normal with cross product: n = (v1 - v0) X (vn - 1 - v0)  Normalize to unit vector with n/║n║ v0 v1 v2 v3 v4 n
  • 121. Normal Direction  Vertices counterclockwise  Front-facing  Vertices clockwise  Back-facing 0 1 2 0 2 1 Front facing Back facing
  • 122. Painter’s Algorithm (1)  Assumption: Later projected polygons overwrite earlier projected polygons Graphics Pipeline 1 1 2 2 3 3 Oops! The red polygon Should be obscured by the blue polygon
  • 123. Painter’s Algorithm (2)  Main Idea  A painter creates a picture by drawing background scene elemens before foreground ones  Requirements  Draw polygons in back-to- front order  Need to sort the polygons by depth order to get a correct image from Shirley
  • 124. Painter’s Algorithm (3)  Sort by the depth of each polygon Graphics Pipeline 1 1 2 2 3 3 depth
  • 125. Painter’s Algorithm (4)  Compute zmin ranges for each polygon  Project polygons with furthest zmin first (z) depth zmin zmin zmin zmin
  • 126. Painter’s Algorithm (5)  Problem: Can you get a total sorting? zmin zmin zmin zmin Correct?
  • 127. Painter’s Algorithm (6)  Cyclic Overlap  How do we sort these three polygons?  Sorting is nontrivial  Split polygons in order to get a total ordering  Not easy to do in general
  • 128. Visibility  How do we ensure that closer polygons overwrite further ones in general?
  • 129. Z-Buffer  Depth buffer (Z-Buffer)  A secondary image buffer that holds depth values  Same pixel resolution as the color buffer  Why is it called a Z-Buffer?  After eye space, depth is simply the z-coordinate  Sorting is done at the pixel level  Rule: Only draw a polygon at a pixel if it is closer than a polygon that has already been drawn to this pixel
  • 130. Z-Buffer Algorithm  Visibility testing is done during rasterization
  • 131. Z-buffer: A Secondary Buffer DAM Entertainment Color buffer Depth buffer
  • 132. Z-Buffer  How do we calculate the depth values on the polygon interior? P1 P2 P3 P4 ys za zp zb Scanline order ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( b a p a a b a p s b s a x x x x z z z z y y y y z z z z y y y y z z z z                2 1 1 1 2 1 4 1 1 1 4 1 Bilinear Interpolation
  • 133. Z-buffer - Example                                                                 Z-buffer Screen
  • 134.                                                                                                Parallel with the image plane
  • 135.                                                                                         Not Parallel
  • 136. Z-Buffer Algorithm  Algorithm easily handles this case
  • 137. Z-buffering in OpenGL  Create depth buffer by setting GLUT_DEPTH flag in glutInitDisplayMode()or the appropriate flag in the PIXELFORMATDESCRIPTOR.  Enable per-pixel depth testing with glEnable(GL_DEPTH_TEST)  Clear depth buffer by setting GL_DEPTH_BUFFER_BIT in glClear()