26
2003 CS Hons RW778 Graphics 1 Chapter 7: Three- Chapter 7: Three- Dimensional Viewing Dimensional Viewing Chapter 5: Camera with parallel Chapter 5: Camera with parallel projection projection Now: Camera with perspective projection Now: Camera with perspective projection 7.2 The Camera Revisited 7.2 The Camera Revisited Eye, view volume, Eye, view volume, view angle, near plane, view angle, near plane, far plane, aspect ratio, far plane, aspect ratio, viewplane. viewplane. Perspective view: P’ determined by finding Perspective view: P’ determined by finding where line from eye to P intersects where line from eye to P intersects viewplane. viewplane.

2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

Embed Size (px)

Citation preview

Page 1: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 1

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Chapter 5: Camera with parallel projectionChapter 5: Camera with parallel projection Now: Camera with perspective projectionNow: Camera with perspective projection 7.2 The Camera Revisited7.2 The Camera Revisited

– Eye, view volume, Eye, view volume, view angle, near plane,view angle, near plane,far plane, aspect ratio,far plane, aspect ratio,viewplane.viewplane.

– Perspective view: P’ determined by finding where line Perspective view: P’ determined by finding where line from eye to P intersects viewplane.from eye to P intersects viewplane.

Page 2: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 2

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.2.1 Setting the View Volume7.2.1 Setting the View Volume– Projection matrixProjection matrix– gluPerspective(viewAngle, gluPerspective(viewAngle, aspectRatio, N, F)aspectRatio, N, F)

7.2.2 Positioning and Pointing the Camera7.2.2 Positioning and Pointing the Camera– Move camera away from default position and point in Move camera away from default position and point in

given direction: Rotation and translation in modelview given direction: Rotation and translation in modelview matrix.matrix.

Page 3: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 3

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– General camera with Arbitrary Orientation and General camera with Arbitrary Orientation and PositionPosition

» Transformation? Modelview matrix?Transformation? Modelview matrix?

– Attach explicit coordinate system to cameraAttach explicit coordinate system to camera– Pitch, heading, Pitch, heading,

yaw, rollyaw, roll

– Selfstudy: pp.361-366Selfstudy: pp.361-366

Page 4: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 4

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.3 Building a Camera in a Program7.3 Building a Camera in a Program– Selfstudy.Selfstudy.

7.4 Perspective Projections of 3D Objects7.4 Perspective Projections of 3D Objects

» Vertex v Vertex v modeling transformations modeling transformations camera camera position and orientation : Now in eye coordinatesposition and orientation : Now in eye coordinates

» Vertex P in eye coordinates must be projected onto Vertex P in eye coordinates must be projected onto point (x*,y*) on near plane.point (x*,y*) on near plane.

Page 5: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 5

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.4.1 Perspective Projection of a Point7.4.1 Perspective Projection of a Point– Fundamental operation: Projecting 3D point Fundamental operation: Projecting 3D point

into 2D coordinates on a plane.into 2D coordinates on a plane.– Construct local coordinate system on near planeConstruct local coordinate system on near plane

– (x*,y*) = (N(P(x*,y*) = (N(Pxx/(-P/(-Pzz)), N(P)), N(Pyy,/(-P,/(-Pzz))))

Page 6: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 6

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– NoteNote» -P-Pzz achieves perspective foreshortening achieves perspective foreshortening

» PPzz=0 if P lies on plane z=0: Clip before projecting=0 if P lies on plane z=0: Clip before projecting

» If PIf Pzz lies behind eye, also clipped before projecting. lies behind eye, also clipped before projecting.

» N scales picture (size only)N scales picture (size only)

» Straight lines project to straight lines (proof given)Straight lines project to straight lines (proof given)

– Selfstudy: Example 7.4.2 IMPORTANT!Selfstudy: Example 7.4.2 IMPORTANT!

Page 7: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 7

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.4.2 Perspective Projection of a Line7.4.2 Perspective Projection of a Line– Lines parallel in 3D project to lines, but not Lines parallel in 3D project to lines, but not

necessarily parallel.necessarily parallel.– Lines that passed behind the eye cause “passage Lines that passed behind the eye cause “passage

through infinity” – should be clipped.through infinity” – should be clipped.– Perspective projections produce geometrically Perspective projections produce geometrically

realistic pictures, except for very long lines realistic pictures, except for very long lines parallel to viewplane.parallel to viewplane.

Page 8: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 8

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– Projecting Parallel LinesProjecting Parallel Lines» 3D line P(t) = A + 3D line P(t) = A + cc(t)(t)» Yields (parametric form) for projectionYields (parametric form) for projection

» If A+If A+cct parallel to viewplane, then ct parallel to viewplane, then czz=0, and=0, andp(t) = N(Ap(t) = N(Axx+c+cxxt,At,Ayy+c+cyyt)/(-At)/(-Azz))Slope is cSlope is cyy/c/cxx

» If two lines in 3D are parallel to each other and to If two lines in 3D are parallel to each other and to the viewplane, they project two parallel lines.the viewplane, they project two parallel lines.

t

tN,

t

tN)t(p

cAcA

cAcA

zz

yy

zz

xx

Page 9: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 9

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

» Suppose c not parallel to viewplane (cSuppose c not parallel to viewplane (czz!=0):!=0):

» For large t, p(For large t, p()=(Nc)=(Ncxx/(-c/(-czz), Nc), Ncyy/(-c/(-czz)) : vanishing )) : vanishing

pointpoint

» Depends only on direction Depends only on direction cc all parallel lines all parallel lines share same vanishing point, i.e. project to lines that share same vanishing point, i.e. project to lines that are not parallel.are not parallel.

Page 10: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 10

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– Lines that pass behind the eyeLines that pass behind the eye» B projects to B’:B projects to B’:

wrong side of viewplanewrong side of viewplane» Let C move from A to B; asLet C move from A to B; as

C moves, its projection slidesC moves, its projection slidesfurther to right until it spurtsfurther to right until it spurtsoff to infinityoff to infinity

» When C moves behind eye, projection appears to When C moves behind eye, projection appears to left on viewplane.left on viewplane.

– Selfstudy: Example 7.4.3,Selfstudy: Example 7.4.3,– Anomaly of Viewing Long Parallel LinesAnomaly of Viewing Long Parallel Lines

Page 11: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 11

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Perspective and the Graphics PipelinePerspective and the Graphics Pipeline– Adding pseudodepth – if two points project to the same Adding pseudodepth – if two points project to the same

point, we only need to know which is nearerpoint, we only need to know which is nearer– Efficiency: Efficiency:

(x*,y*,z*) = (N(P(x*,y*,z*) = (N(Pxx/(-P/(-Pzz)), N(P)), N(Pyy,/(-P,/(-Pzz), (aP), (aPzz+b)/(-P+b)/(-Pzz))))

– Choose –1<=a,b<=1Choose –1<=a,b<=1– Let pseudodepth be –1 when PLet pseudodepth be –1 when Pzz= -N, 1 when P= -N, 1 when Pzz = -F. = -F.– Then a = -((F+N)/(F-N)) andThen a = -((F+N)/(F-N)) and

b = (-2FN)/(F-N). b = (-2FN)/(F-N).– Due to precision problems, pseudodepth values may be Due to precision problems, pseudodepth values may be

equal for two different pints as –Pequal for two different pints as –Pzz approaches F. approaches F.

Page 12: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 12

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Using Homogeneous CoordinatesUsing Homogeneous Coordinates– Point (PPoint (Pxx,P,Pyy,P,Pzz,1); vector (v,1); vector (vxx,v,vyy,v,vzz,0),0)– Extend: Point has family of homogeneous Extend: Point has family of homogeneous

coordinates (wPcoordinates (wPxx,wP,wPyy,wP,wPzz,w) for any w except ,w) for any w except w=0.w=0.

– To convert point from ordinary to To convert point from ordinary to homogeneous coordinates, append 1.homogeneous coordinates, append 1.

– To convert point from homogenous to ordinary To convert point from homogenous to ordinary coordinates, divide all components by last, and coordinates, divide all components by last, and discard last component.discard last component.

Page 13: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 13

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– Transforming points in homogeneous Transforming points in homogeneous coordinates: coordinates:

» If matrix M has last row (0 0 0 1), affine If matrix M has last row (0 0 0 1), affine transformation MP=Q, last component of Q is w.transformation MP=Q, last component of Q is w.

» If M doesn’t have last row (0 0 0 1), MP=Q gives If M doesn’t have last row (0 0 0 1), MP=Q gives point; can divide by last component to find point; can divide by last component to find coordinates : coordinates : perspective division.perspective division.

» If M doesn’t have last row (0 0 0 1), not affine but If M doesn’t have last row (0 0 0 1), not affine but perspectiveperspective transformation. transformation.

» Note: perspective projection = perspective Note: perspective projection = perspective transformation + orthographic projectiontransformation + orthographic projection

Page 14: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 14

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– Geometric Nature of Perspective Geometric Nature of Perspective TransformationTransformation

» Lines through eye map intoLines through eye map intolines parallel to z-axis.lines parallel to z-axis.

» Lines perpendicular toLines perpendicular toz-axis map into lines perpen-z-axis map into lines perpen-dicular to z-axis.dicular to z-axis.

» Transformation warps objects into new shapes.Transformation warps objects into new shapes.» Perspective transformation warps objects so that, Perspective transformation warps objects so that,

when viewed with an orthographic projection, they when viewed with an orthographic projection, they appear the same as the original objects do when appear the same as the original objects do when viewed with a perspective projection.viewed with a perspective projection.

Page 15: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 15

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Transformed View Volume; Canonical View Transformed View Volume; Canonical View VolumeVolume– top to y=toptop to y=top– bottom to y=bottbottom to y=bott– left to x=leftleft to x=left– right to x=rightright to x=right– parallelepiped with dimensions related to camera’s propertiesparallelepiped with dimensions related to camera’s properties

– Scale and shift into canonical view volume (cube from Scale and shift into canonical view volume (cube from –1 to 1 in each dimension)–1 to 1 in each dimension)

– Transformation matrix known as Transformation matrix known as projection matrix.projection matrix.– OpenGL: OpenGL: glFrustrum()glFrustrum()

Page 16: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 16

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Projection matrix :Projection matrix :

0100NF

FN2

NF

)NF(00

0botttop

botttop

bottomtop

N20

0leftright

leftright0

leftright

N2

R

Page 17: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 17

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.4.4 Clipping Faces against View Volume7.4.4 Clipping Faces against View Volume– As Cyrus-Beck, but in 4D.As Cyrus-Beck, but in 4D.

» Clip AC against six infiniteClip AC against six infiniteplanes.planes.

» For each wall, test whetherFor each wall, test whetherA and C same side. If not, clip.A and C same side. If not, clip.

» Calculate six boundary coordinates (BC) for A and Calculate six boundary coordinates (BC) for A and C. All 6 positive: point inside CVV, else outside.C. All 6 positive: point inside CVV, else outside.

» Both same side: trivial accept, reject. Else clip.Both same side: trivial accept, reject. Else clip.

Page 18: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 18

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– Selfstudy: Rest of clipping algorithm, pp.387-Selfstudy: Rest of clipping algorithm, pp.387-389.389.

– Selfstudy: Why clip against CVV?Selfstudy: Why clip against CVV?– Selfstudy; Why clip in Homogeneous Selfstudy; Why clip in Homogeneous

Coordinates?Coordinates?– Selfstudy: The Viewport Transformation.Selfstudy: The Viewport Transformation.

Page 19: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 19

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.5 Producing Stereo Views7.5 Producing Stereo Views– Not for exam purposes.Not for exam purposes.

7.6 Taxonomy of Projections7.6 Taxonomy of Projections

Page 20: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 20

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.6.1 One-, Two-, Three Point Perspective7.6.1 One-, Two-, Three Point Perspective– Suppose n-axis of camera is perpendicular to Suppose n-axis of camera is perpendicular to

one principal axis or another; therefore one principal axis or another; therefore vanishing point at infinity.vanishing point at infinity.

– Count number of finite vanishing points, i.e. Count number of finite vanishing points, i.e. number of principal exis not perp. to n.number of principal exis not perp. to n.

– One point PerspectiveOne point Perspective» n perp. to two principal axes; two of (nn perp. to two principal axes; two of (nxx,n,nyy,n,nzz) must ) must

be 0.be 0.

Page 21: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 21

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Page 22: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 22

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

7.6.2 Parallel Projections7.6.2 Parallel Projections– Perspective projection: Points projected along Perspective projection: Points projected along

projectors that converge on eyeprojectors that converge on eye– Parallel projection: All projectors have same Parallel projection: All projectors have same

direction direction dd..– Two types: Two types:

obliqueobliqueorthographicorthographic

Page 23: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 23

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Orthographic ProjectionsOrthographic Projections– ddxx=d=dyy=0=0

– Orthographic projection in OpenGL: READ.Orthographic projection in OpenGL: READ.– Types of Orthographic ProjectionsTypes of Orthographic Projections– Multiview:Multiview:

» Top, front, side viewsTop, front, side views

» nn made parallel to each of made parallel to each of kk, , ii, , jj in turn. in turn.

Page 24: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 24

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– Axonometric:Axonometric:» nn not parallel to any principal axis not parallel to any principal axis

» Foreshortening factor sin(Foreshortening factor sin())

Isometric: all 3 principal axes foreshortened equallyIsometric: all 3 principal axes foreshortened equally Dimetric: 2 foreshortened equallyDimetric: 2 foreshortened equally Trimetric: all 3 foreshortened unequallyTrimetric: all 3 foreshortened unequally

Page 25: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 25

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

– Oblique projections: Selfstudy.Oblique projections: Selfstudy.

Page 26: 2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection

2003 CS Hons RW778 Graphics 26

Chapter 7: Three-Dimensional ViewingChapter 7: Three-Dimensional Viewing

Programming Task 5Programming Task 5 : Implement Case : Implement Case Study 7.1 (Flying a camera through a Study 7.1 (Flying a camera through a scence), p. 405, in Hill.scence), p. 405, in Hill.