0% found this document useful (0 votes)
17 views53 pages

7 - 3D Concepts & Transformation

Uploaded by

dawitkebedewoldu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views53 pages

7 - 3D Concepts & Transformation

Uploaded by

dawitkebedewoldu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

3D Concepts & Transformation

1
Right Handed Coordinate System

+Y +Y

+Z

+X +X

+Z

2
Viewing a 3D world
+Y
We have a model in this world
and would like to view it from a
new position.

+X

+Z
We’ll call this new position the
camera or eyepoint. Our job is to
figure out what the model looks
3
like on the display plane.
Parallel Projection
+Y

+Z
+X

4
Perspective Projection
+Y

+Z
+X

5
What are some new things to
think about?

Hidden Surface Removal


Visibility
Depth Cueing

6
How to make a 2D image appear as
3D!
• Output is typically 2D Images
• Yet we want to show a 3D world!
• How can we do this?
– We can include ‘cues’ in the image that give
our brain 3D information about the scene
– These cues are visual depth cues

7
Visual Depth Cues
• Monoscopic Depth Cues (single 2D image)
• Stereoscopic Depth Cues (two 2D images)
• Motion Depth Cues (series of 2D images)
• Physiological Depth Cues (body cues)

8
Monoscopic Depth Cues
• Interposition
– An object that obstructs another is closer
• Shading
– Shape info. Shadows are included here
• Size
– Usually, the larger object is closer
• Linear Perspective
– parallel lines converge at a single point
• Surface Texture Gradient
– more detail for closer objects
• Height in the visual field
– Higher the object is (vertically), the further it
is
• Atmospheric effects
– further away objects are blurrier
• Brightness
– further away objects are dimmer
9
3D Transformations

10
3D Transformations
• Remembering 2D transformations -> 3x3
matrices
T=(tx, ty, tz)
1 0 t x 
 x  x 
T t x , t y         0 1 t y 
t
 y  t y   0 0 1 
 
1 0 0 t x 
   x 
x t 
T t x , t y , t z    y   t y   
    0 1 0 t y 
0 0 1 t z 
 z  t z   
 0 0 0 1  11
Scale, 3D Style
sx 0 0
sx 0   x  S=(sx, sy, sz)
S s x , s y     0 0 
s y   y  
* sy
0  0 0 1 
sx 0 0 0
sx 0  x 
0 
0
S s x , s y , s z    0 0  *  y   
0 sy 0
sy
0 0 sz 0
 0 0  
sz   z    
0 0 0 1

12
Rotation
What does a rotation in 3D mean? R=(rx, ry, rz, )
Q: How do we specify a rotation?

A: We give a vector to
rotate about, and a theta 
that describes how much
we rotate.

Q: Since 2D is sort of like a


special case of 3D, what is
the vector we’ve been
rotating about in 2D? 13
Rotations about the Z axis
What do you think the rotation matrix is for
rotations about the z axis?
R=(0,0,1,)
cos   sin  0
cos   sin   
R      sin  cos  0 
 sin  cos   
 0 0 1 
cos   sin  0 0
 sin  cos  0 0 
R (0,0,1, )   
 0 0 1 0
 
 0 0 0 1

14
Rotations about the X axis

Let’s look at the other axis rotations

R=(1,0,0,)

1 0 0 0
 0 cos   sin  0 
R (1,0,0,  )  
 0 sin  cos  0
 
0 0 0 1

15
Rotations about the Y axis

R=(0,1,0,)

 cos  0 sin  0
 0 1 0 0 
R ( 0,1,0,  )  
  sin  0 cos  0
 
 0 0 0 1

16
Rotations for an arbitrary axis
1 0 0 0
 0 cos   sin  0 
R (1,0,0,  )  
 0 sin  cos  0
 
0 0 0 1
 cos  0 sin  0
 0 1 0 0 
R ( 0,1,0,  )  
  sin  0 cos  0
 
 0 0 0 1
 cos   sin  0 0
 sin  cos  0 0 
R ( 0,0,1,  )  
 0 0 1 0
 
 0 0 0 1 17
Rotations for an arbitrary axis

R    R x 1    R y 1     R z    R y     R x  
u

Steps:

 1. Normalize vector u
2. Compute 
 3. Compute 
4. Create rotation matrix

18
Transformation in OpenGL
• glTranslate*()
Ex. glTranslatef(-20.0, 0.0, 0.0);
• glRotate*()
Ex. glRotatef (90.0, 0.0, 0.0, 1.0);
• glScale*()
Ex. glScalef(1.5, 0.5, 1.0);

19
3D Viewing

20
The Question
• Given a 3D point, an eye position, a camera
position, and a display plane, what is the
resulting pixel position?

• Now extend this for a group of three points

• Then apply what you know about scan


conversion.
21
Different Phases:
Model Definition

22
Different Phases:
Transformations

23
Different Phases:
Projection

24
Different Phases:
Projection

25
Different Phases:
Rasterization

26
Different Phases:
Scan Conversion

27
Graphics Pipeline So Far
Object Transformation
Object Coordinates Object -> World

World Projection Xform


World Coordinates World -> Projection

Camera Normalize Xform & Clipping


Projection Coordinates Projection -> Normalized

Viewport Viewport Transform


Normalized Coordinates Normalized -> Device

Screen
Device Coordinates 28
Projections

29
Projections: Left-handed Screen
Coordinates

30
Parallel Projections: Orthographic or
Isometric Projection
VP'  PParallelMV
1 0 0 0
0 1 0 0
PParallel( Orthographic )  
0 0 0 0
 
0 0 0 1

31
Parallel Projection

32
Parallel Projections: Oblique Projection

Let
[xp, yp,zp] - the direction of projection
(x,y,z) - a point on the object
(x’,y’,z’) – a point of the projection result

Then: (parametric equation) 0  xp / zp 0 


1
x’ = x + xp.u 0 1  yp / zp 0 
y’ = y + yp.u Ppara lell( obliq ue)  
0 0 0 0
z’ = z + zp.u for some 0<=u<=1  
0 0 0 1
If the view plane is the xy-plane, then z’ = 0
Substituting: x’ = x – (xp/zp).z
y’ = y – (yp/zp).z
33
Parallel Projections: Oblique Projection
(xp,yp,zvp)
L

ǿ(
(x,y,zvp)

VP'  PParallelMVVC
L1  tan 1 
1 0 L1 cos  0
 
0 1 L1 sin  0
PParallel( Oblique) 
0 0 0 0
 
0 0 0 34 1
Parallel Projections: Oblique Projection


L

35
Perspective Projections

foreshortening - the
farther an object is from
the camera , the smaller it
appears in the final image

36
Perspective Projection

37
Perspective Projection

38
Perspective Projection Side View
P=(xp,yp,zp) t=0 P’=(x’,y’,z’) t=?

C=(xc,yc,zc) t=1
xp
x’
z’
zp

39
Perspective Projection
Let
(xc ,yc , zc] - the center of projection (reference point)
(x ,y ,z) - a point on the object
(x’,y’,z’) – a point on the projection view plane

Then: parametric equation 1 0  x / z c c 0 


x’ = xc + (x - xc).u 0 1  y / z 0 
y’ = yc + (y - yc).u 
c c
P
0 0 0
p ersp ective

z’ = zc + (z - zc).u for some 0<=u<=1 0


 
0 0  1 / zc 1
If the view plane is the xy-plane, then z’ = 0
Substituting: x’ = (- zc x + xc z) /(z – zc)
y’ = (- zc y + yc z)/(z – zc)
40
Perspective Projection View Volume
•a pyramid of vision - it approximates the cone of vision
of our eyes or a camera
•a view volume that is an infinite rectangular pyramid
with its apex at the center of projection

41
Perspective Projection Side View
P=(xp,yp,zp) t=0 P’=(x’,y’,z’) t=?

C=(xc,yc,zc) t=1
xp
x’
z’
zp
x' xp

z' z p

 x'  x p
z'

xp 
  x '  1 0 0 0  x 
 y ' 0 
p
y' yp  z w  1 0 0 y 
    p 
p
z  z' yp 
z' z p w  p ;  y'  y p    z '  0 0 1 0  z 
  0  p 
z'  zp w  1
  0 0 421 
z'
 w  
z'  z' 

z '  z p
zp 

z' 
Perspective Projection Side View
P=(xp,yp,zp) t=0 P’=(x’,y’,z’) t=?

C=(xc,yc,zc) t=1
xp h
x’
z’
zp

 z' xp   z' z' 


 x'  x p    x'  x p  xp 
 z p w   zp hz p 
z  z' yp   z' z' 
w  p ;  y'  y p   w  z p  y'  y p  yp 
z'  zp w  Scale by h  zp hz p 
 z'   fz p z' f 
 z '  z   z '   
f  z ' 43f  z'
p
 zp   
Perspective Divide

 z' z'   z' 


 x'  x p  xp   0 0 0 
 zp hz p   x '   hhoriztonal  xp 
 z' z'   y '  z'  y p 
w  z p  y'  y p  yp    0 hvertical
0 0
 
 zp hz p   z'   z 
   0 far  near * far   p 
 fz p  w
0 
 z '  
z' f
  far  near far  near   1 
 f  z' f  z'   0 0 1 0 

Foreshortening - look at the x,y, and w values, and how they depend on how far
away the object is.
Modelview Matrix - describes how to move the world->camera coordinate
system
Perspective Matrix - describes the camera you are viewing the world with.
44
Perspective Matrix
Note: Normalized Device Coordinates are a
LEFT-HANDED Coordinate system

45
Projection in OpenGL
• glOrtho(GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top, GLdouble
near, GLdouble far);

• gluPerspective(GLdouble theta, GLdouble


aspect, GLdouble near, GLdouble far);

• glFrustum(GLdouble left, GLdouble right,


GLdouble bottom, GLdouble top, GLdouble
near, GLdouble far); 46
Visible Surface Determination

47
Goal of Visible Surface
Determination
To draw only the surfaces (triangles) that are visible, given a
view point and a view direction

48
Multiple Objects
• If we want to draw: We can sort in z.
Sorting may
become slow
Called Painter’s
Algorithm or
splatting.

49
Painter’s (Depth-Sorting) Algorithm

• Triangle’s representative z value


– Minimum z
– Maximum z
– Polygon’s centroid
• Work cost = sort + draw

• An object space visibility algorithm

50
Painter’s Algorithm
• Pros: • Cons:
– No extra memory – Precision issues (and
– Relatively fast additional work to
– Easy to understand and handle them)
implement – Sort stage
– Intersecting objects

51
Depth Buffer Algorithm
• A memory to store the depth value for each
pixel
• Begin frame
– Clear color
– Clear depth to z = zmax
• Draw Triangles
– When scan converting znew pixel < zvalue at the pixel, set
color and zvalue at the pixel = znew pixel
– What does it mean if znew pixel > zvalue at the pixel?

52
Depth Buffer Algorithm
• Pros: • Cons:
– Easy to understand and – Z precision
implement – additional memory
– per pixel “correct” – Z fighting
answer
– no preprocess
– draw objects in any
order
– no need to redivide
objects
53

You might also like