Computer Graphics
description
Transcript of Computer Graphics
Computer Graphics
Computer Graphics
Lecture 8
Arbitrary Viewing II:
More Projection, Clipping and Mathematics of 3D Viewing
Computer Graphics
21/10/2008 Lecture 8 2
Parallel projections.
• Specified by a direction to the centre of projection, rather than a point.– Centre of projection at infinity.
• Orthographic– The normal to the projection plane is the same
as the direction to the centre of projection.
• Oblique– Directions are different.
Computer Graphics
21/10/2008 Lecture 8 3
Mathematics of Viewing
• We need to generate the transformation matrices for perspective and parallel projections.
• They should be 4x4 matrices to allow general concatenation.
• And there’s still 3D clipping and more viewing stuff to look at.
Computer Graphics
21/10/2008 Lecture 8 4
Perspective projection – simplest case.
d
x
y
z
ProjectionPlane.
P(x,y,z)
Pp(xp,yp,d)
Centre of projection at the origin,Projection plane at z=d.
Computer Graphics
21/10/2008 Lecture 8 5
Perspective projection – simplest case.
d
x
y
z
P(x,y,z)
Pp(xp,yp,d)
z
P(x,y,z)
d
z
P(x,y,z)
d
y
x
xp
yp
dz
y
z
ydy
dz
x
z
xdx
z
y
d
y
z
x
d
x
pp
pp
/ ;
/
;
:trianglessimilarFrom
Computer Graphics
21/10/2008 Lecture 8 6
Perspective projection.
01/d00
0100
0010
0001
:matrix 4x4 a as drepresente becan ation transformThe
perM
TTT
pp dzzyxdz
ydz
xddyx
1..1
Computer Graphics
21/10/2008 Lecture 8 7
Perspective projection.
TT
perp
Tp
dzzyxWZYX
z
y
x
PMP
WZYXP
/
101/d00
0100
0010
0001
point projected general theRepresent
Computer Graphics
21/10/2008 Lecture 8 8
Perspective projection.
ddz
y
dz
x
W
Z
W
Y
W
X
dzzyxP Tp
,/
,/
,,
: 3D back to come W toDropping
/Trouble with this formulation :
Centre of projection fixed at the origin.
Computer Graphics
21/10/2008 Lecture 8 9
Finding vanishing points.
• Recall : An axis vanishing point is the point where the axis intercepts the projection plane point at infinity.
Tvpxp 0001
:point by themultiply
point, vanishingaxis x find toE.g
e.perspectivpoint 1 a have weSo
00
01/d00
0100
0010
0001
:n formulatio For this
dP
P
P
M
zvp
yvp
xvp
per
Computer Graphics
21/10/2008 Lecture 8 10
Alternative formulation.
z
P(x,y,z)
d
x
xp
z
P(x,y,z)
d
y
yp
Projection plane at z = 0Centre of projection at z = -d
1)/( ;
1)/(
dby Multiply
;
:trianglessimilarFrom
dz
y
dz
ydy
dz
x
dz
xdx
dz
y
d
y
dz
x
d
x
pp
pp
Computer Graphics
21/10/2008 Lecture 8 11
Alternative formulation.
11/d00
0000
0010
0001
perM
z
P(x,y,z)
d
x
xp
z
P(x,y,z)
d
y
yp
Projection plane at z = 0,Centre of projection at z = -d
Now we can allow d
Computer Graphics
21/10/2008 Lecture 8 12
Stereo Projection• Stereo projection is just two perspective projections :
object
Left eye
Right eye
z
x
r
r
l
l
display screen
Max effect at 50cm
E
E
Computer Graphics
21/10/2008 Lecture 8 13
Stereo ProjectionE is the interocular separation, typically 2.5cm to 3cm.
d is the distance of viewer from display, typically 50cm.
Let 2E = 5cm:
1100
0000
001020001
:
1100
0000
001020001
:
d
d
eyeRight
d
d
eyeLeft
.102:
71.5505tan2tan 11
anglepreservetodEthus
dEanglestereo o
Computer Graphics
21/10/2008 Lecture 8 14
View as an anaglyph
Computer Graphics
21/10/2008 Lecture 8 15
Orthographic projection.
1000
0000
0010
0001
orthM
Orthographic Projection onto a plane at z = 0.
xp = x , yp = y , z = 0.
Computer Graphics
21/10/2008 Lecture 8 16
Implementation of viewing.
• Transform into world coordinates.
• Perform projection into view volume or eye coordinates.
• Clip geometry outside the view volume.
• Perform projection into screen coordinates.
• Remove hidden lines.
Computer Graphics
21/10/2008 Lecture 8 17
3D clipping.
• For orthographic projection, view volume is a box.
• For perspective projection, view volume is a frustrum.
Far clipping plane.
Near clipping plane
left
right
Need to calculate intersectionWith 6 planes.
Computer Graphics
21/10/2008 Lecture 8 18
Speeding up projection.
• Can always place camera at origin ! – OpenGL , Renderman.
• Much easier to clip lines to unit cube– Define canonical view volumes.– Define normalising transformations that project
view volume into canonical view volume.– Clip, transform to screen coordinates.
Computer Graphics
21/10/2008 Lecture 8 19
3D clipping.
• Can use Cohen-Sutherland algorithm.– Now 6-bit outcode.– Trivial acceptance where both endpoint
outcodes are all zero.– Perform logical AND, reject if non-zero.– Find intersect with a bounding plane and add
the two new lines to the line queue.– Line-primitive algorithm.
Computer Graphics
21/10/2008 Lecture 8 20
3D polygon clipping.
• Sutherland-Hodgman extends easily to 3D.
• Call ‘CLIP’ 6 times rather than 4.
• Polygon-primitive algorithm.
Computer Graphics
21/10/2008 Lecture 8 21
Sutherland-Hodgman algorithm.
Four cases of polygon clipping :
Inside Outside Inside Outside Inside Outside Inside Outside
Case 3No
output.Case 1
OutputVertex
Case 2.
OutputIntersection
Case 4
SecondOutput
FirstOutput
Computer Graphics
21/10/2008 Lecture 8 22
Clipping and homogeneous coordinates.
• Efficient to transform frustrum into perspective canonical view volume – unit slope planes.
• Even better to transform to parallel canonical view volume– Clipping must be done in homogeneous coordinates.
• Points can appear with –ve W and cannot be clipped properly in 3D.
Computer Graphics
21/10/2008 Lecture 8 23
Transforming between canonical view-volumes
• The perspective canonical view-volume can be transformed to the parallel canonical view-volume with the following matrix:
0100)1()1(
100
0010
0001
]1,[d
d
dTthendzIf ppcv
• Derivation left as an exercise.
Computer Graphics
21/10/2008 Lecture 8 24
Clipping in 3D.
• 3D parallel projection volume is defined by:
-1x 1, -1 y 1 , -1 z 0• Replace by X/W,Y/W,Z/W:
-1X/W 1, -1 Y/W 1 , -1 Z/W 0• Corresponding plane equations are :
X= -W, X=W, Y=-W, Y=W, Z=-W, Z=0
Computer Graphics
21/10/2008 Lecture 8 25
Clipping in W
• If W>0 , multiplication by W doesn’t change sign.
W>0: -W X W, -W Y W, -W Z 0
• However if W<0, need to change sign :
W<0: -WX W,-W Y W, -W Z 0
Computer Graphics
21/10/2008 Lecture 8 26
Points in Homogeneous coordinates.
X or Y
W
W=1
P1=[1 2 3 4]T
P2=[-1 –2 –3 –4]T
Projection of P1 and P2 onto W=1 plane
Computer Graphics
21/10/2008 Lecture 8 27
Points in Homogeneous coordinates.
X or Y
W
W=1
P1=[1 2 3 4]T
P2=[-1 –2 –3 –4]T
Projection of P1 and P2 onto W=1 planeRegion A
Region B
Need to consider both regions when Performing clipping.
Computer Graphics
21/10/2008 Lecture 8 28
Clipping in Homogeneous coordinates
• Could clip twice – once for region B, once for region A.– Expensive.
• Check for negative W values and negate points before clipping.
• What about lines with endpoints in each region ?
Computer Graphics
21/10/2008 Lecture 8 29
Lines in Homogeneous coordinates.
X
WP1
P2
W=1
Projection of points.
Computer Graphics
21/10/2008 Lecture 8 30
Lines in Homogeneous coordinates.
X
WP1
P2
W=1
W=-X
W=XClipped lines
Solution : Clip line segments, negate both endpoints, clip again.
Computer Graphics
21/10/2008 Lecture 8 31
Final step.
• Divide by W to get back to 3-D– Divide by z.– Where the perspective projection actually gets
done – perspective foreshortening.
• Now we have a ‘view volume’.– Don’t flatten z due to hidden line calculations.
Computer Graphics
21/10/2008 Lecture 8 32
Summary.
• Orthographic matrix - replace (z) axis with point.
• Perspective matrix – multiply w by z.– Clip in homogeneous coordinates.– Preserve z for hidden surface calculations.– Can find number of vanishing points.
Computer Graphics
21/10/2008 Lecture 8 33
Reading for Arbitrary ViewingI and II
• Foley et al. Chapter 6 – all of it,– Particularly section 6.5
• Introductory text, Chapter 6 – all of it,– Particularly section 6.6
• This will cover both this handout and the previous handout.