Projection (Part 1) Created by Dr. Slim BECHIKH for SPSU course - - - PowerPoint PPT Presentation
Projection (Part 1) Created by Dr. Slim BECHIKH for SPSU course - - - PowerPoint PPT Presentation
Projection (Part 1) Created by Dr. Slim BECHIKH for SPSU course - CS4363 Computer Graphics and Multimedia Fall 2014 Recall: 3D Viewing and View Volume Now: Set view volume Previously: Lookat( ) to set camera position
Recall:3DViewingandViewVolume
Previously: Lookat( ) to set camera position Now: Set view volume
Recall:DifferentViewVolumeShapes
Differentviewvolume=>differentlook Foreshortening?Nearobjectsbigger x y z x y z Perspective view volume (exhibits foreshortening) Orthogonal view volume (no foreshortening)
ViewVolumeParameters
Needtosetviewvolumeparameters
Projectiontype:perspective,orthographic,etc. Fieldofviewandaspectratio Nearandfarclippingplanes
FieldofView
Viewvolumeparameter Determineshowmuchofworldinpicture(vertically) Largerfieldofview=smallerobjectsdrawn x y z y z field of view (view angle) center of projection
NearandFarClippingPlanes
Onlyobjectsbetweennearandfarplanesdrawn
x y z Near plane Far plane
ViewingFrustrum
Nearplane+farplane+fieldofview=ViewingFrustum Objectsoutsidethefrustumareclipped
x y z Near plane Far plane Viewing Frustum
SettingupViewVolume/ProjectionType
PreviousOpenGLprojectioncommandsdeprecated!!
Perspectiveviewvolume/projection:
gluPerspective(fovy,aspect,near,far)or glFrustum(left,right,bottom,top,near,far)
Orthographic:
glOrtho(left,right,bottom,top,near,far)
Usefulfunctions,soweimplementsimilarinmat.h:
Perspective(fovy,aspect,near,far)or Frustum(left,right,bottom,top,near,far) Ortho(left,right,bottom,top,near,far)
x y z x y z What are these arguments? Next!
Perspective(fovy,aspect,near,far)
Aspectratiousedtocalculatewindowwidth
x y z y z fovy near far Aspect = w / h w h
Nearplane
Frustum(left,right,bottom,top,near,far)
CanuseFrustrum()inplaceofPerspective() Sameviewvolumeshape,differentarguments
x y z left right bottom top near far
near and far measured from camera
Ortho(left,right,bottom,top,near,far)
Fororthographicprojection
x y z left right bottom top near far
near and far measured from camera
ExampleUsage: SettingViewVolume/ProjectionType
void display() { // clear screen glClear(GL_COLOR_BUFFER_BIT); ……….. // Set up camera position LookAt(0,0,1,0,0,0,0,1,0); ……….. // set up perspective transformation Perspective(fovy, aspect, near, far); ……….. // draw something display_all(); // your display routine }
Demo
NateRobbinsdemoonprojection
VRP COP Object in 3 space Projectors Projected image
PerspectiveProjection
Aftersettingviewvolume,thenprojection
transformation
Projection?
Classic:Converts3Dobjecttocorresponding2Donscreen How?Drawlinefromobjecttoprojectioncenter Calculatewhereeachintersectsprojectionplane
projection plane camera
How?Drawparallellinesfromeachobjectvertex Theprojectioncenterisatinfinite Inshort,use(x,y)coordinates,justdropzcoordinates
OrthographicProjection
x y z
Triangle In 3D Projection of Triangle in 2D
Whatifyouuserdoesnotsetupprojection? DefaultOpenGLprojectionisorthogonal(Ortho()); Toprojectpointswithindefaultviewvolume
DefaultViewVolume/Projection?
x y z
Triangle In 3D Projection of Triangle in 2D
xp = x yp = y zp = 0
Vertices after Projection Vertices before Projection
HomogeneousCoordinate Representation
xp = x yp = y zp = 0 wp = 1 pp = Mp M =
- 1
1 1
Inpractice,canletM =I,setthe ztermtozerolater default orthographic projection
Vertices after Projection (2D) Vertices before Projection (3D) Default Projection Matrix
Keeps(x,y)coordintatesfordrawing,dropsz Wemayneedz.Why?
TheProblemwithClassicProjection
x y z
VertexTriangle In 3D Projection of Triangle in 2D
VRP COP Object in 3 space Projectors Projected image
xp = x yp = y zp = 0
Classic Projection Loses z value
Normalization:KeepszValue
Mostgraphicssystemsuseviewnormalization Normalization: convertallotherprojectiontypesto
- rthogonalprojectionswiththedefaultviewvolume
x y z x y z Default view volume Clipping against it
Perspectivetransform matrix Orthotransform matrix
References
InteractiveComputerGraphics(6th edition),Angeland
Shreiner
ComputerGraphicsusingOpenGL(3rd edition),HillandKelley