<<

Overview

• Classical views • Computer viewing Viewing and perspectives • normalization

Planar Geometric Classical Viewing Projections • Viewing requires three basic elements • Standard projections project onto a plane – One or more objects – A viewer with a projection surface • Projectors are lines that either – Projectors that go from the object(s) to the – converge at a center of projection projection surface – are parallel • Classical views are based on the relationship among these elements • Such projections preserve lines – The viewer picks up the object and orients it how – but not necessarily angles she would like to see it • Nonplanar projections are needed for • Each object is assumed to constructed from flat applications such as map construction principal faces – Buildings, polyhedra, manufactured objects Classical Projections Perspective vs Parallel

treats all projections the same and implements them with a single pipeline • Classical viewing developed different techniques for drawing each type of projection • Fundamental distinction is between parallel and perspective viewing even though mathematically parallel viewing is the limit of perspective viewing

Taxonomy of Planar Perspective Projection Geometric Projections

planar geometric projections

parallel perspective

1 point2 point 3 point multiview axonometric oblique orthographic

isometric dimetric trimetric

Projectors are orthogonal to projection surface

Multiview Orthographic Advantages and Disadvantages Projection • parallel to principal face • Preserves both distances and angles • Usually form front, top, side views – Shapes preserved isometric (not multiview – Can be used for measurements orthographic view) front • Building plans • Manuals in CAD and architecture, • Cannot see what object really looks like we often display three because many surfaces hidden from view multiviews plus isometric side – Often we add the isometric top Types of Axonometric Axonometric Projections Projections Allow projection plane to move relative to object classify by how many angles of a corner of a projected cube are the same θ 1 none: trimetric θ θ 2 3 two: dimetric three: isometric

Advantages and Disadvantages Example, isometric/dimetric

• Lines are scaled ( foreshortened ) but can find scaling factors • Lines preserved but angles are not – Projection of a circle in a plane not parallel to the projection plane is an ellipse • Can see three principal faces of a box-like object • Some optical illusions possible – Parallel lines appear to diverge • Does not look real because far objects are scaled the same as near objects • Used in CAD applications, games Advantages and Disadvantages

Arbitrary relationship between projectors and • Can pick the angles to emphasize a particular projection plane face – Architecture: oblique, elevation oblique • Angles in faces parallel to projection plane are preserved while we can still see “around” side

• In physical world, cannot create with simple camera; possible with bellows camera or special lens (architectural)

Perspective Projection Vanishing Points

Projectors coverge at center of projection • Parallel lines (not parallel to the projection plan) on the object converge at a single point in the projection (the vanishing point ) • Drawing simple perspectives by hand uses these vanishing point(s)

vanishing point One-Point Perspective Two-Point Perspective

• One principal face parallel to projection plane • One principal direction parallel to projection • One vanishing point for cube plane • Two vanishing points for cube

Three-Point Perspective Advantages and Disadvantages

• No principal face parallel to projection plane • Objects further from viewer are projected smaller • Three vanishing points for cube than the same sized objects closer to the viewer (diminution ) – Looks realistic • Equal distances along a line are not projected into equal distances ( nonuniform foreshortening ) • Angles preserved only in planes parallel to the projection plane • More difficult to construct by hand than parallel projections (but not more difficult by computer) Computer Viewing The OpenGL Camera

• There are three aspects of the viewing • In OpenGL, initially the object and process, all of which are implemented in camera frames are the same the pipeline, – Default model-view matrix is an identity – Positioning the camera • The camera is located at origin and • Setting the model-view matrix points in the negative z direction – Selecting a lens • OpenGL also specifies a default view • Setting the projection matrix volume that is a cube with sides of length – Clipping 2 centered at the origin • Setting the view volume – Default projection matrix is an identity

Moving the Camera Default Projection Frame Default projection is orthogonal • If we want to visualize object with both positive and negative z values we can either

clipped out – Move the camera in the positive z direction 2 • Translate the camera frame – Move the objects in the negative z direction • Translate the world frame z=0 • Both of these views are equivalent and are determined by the model-view matrix – Want a translation ( glTranslatef(0.0,0.0,- d); ) – d > 0 Moving Camera back from Moving the Camera Origin frames after translation by –d • We can move the camera to any desired d > 0 position by a sequence of rotations and default frames translations • Example: side view – Rotate the camera – Move it away from origin – Model-view matrix C = TR

OpenGL code The LookAt Function

• Remember that last transformation • The GLU library contains the function specified is first to be applied gluLookAt to form the required modelview matrix through a simple interface • Note the need for setting an up direction glMatrixMode(GL_MODELVIEW) glLoadIdentity(); • Still need to initialize glTranslatef(0.0, 0.0, -d); glRotatef(90.0, 0.0, 1.0, 0.0); – Can concatenate with modeling transformations • Example: isometric view of cube aligned with axes glMatrixMode(GL_MODELVIEW): glLoadIdentity(); gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0. 0.0); gluLookAt Other Viewing APIs glLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz) • The LookAt function is only one possible API for positioning the camera • Others include – View reference point, view plane normal, view up (PHIGS, GKS-3D) – Yaw, pitch, roll – Elevation, azimuth, twist – Direction angles

Projections and Homogeneous Coordinate Normalization Representation • The default projection in the eye (camera) frame is default orthographic projection orthogonal xp = x p = Mp • For points within the default view volume p yp = y xp = x zp = 0 1 0 0 0 y = y w = 1   p p 0 1 0 0 zp = 0 M =   0 0 0 0 • Most graphics systems use view normalization   – All other views are converted to the default view by 0 0 0 1 transformations that determine the projection matrix – Allows use of the same pipeline for all views In practice, we can let M = I and set the z term to zero later Simple Perspective Perspective Equations

• Center of projection at the origin Consider top and side views • Projection plane z = d, d < 0

x z / d

x y xp = yp = zp = d z / d z / d

Homogeneous Coordinate Perspective Division Form 1 0 0 0 • However w ≠ 1, so we must divide by w to   consider q = Mp where M = 0 1 0 0 return from homogeneous coordinates 0 0 1 0 • This perspective division yields   0 0 /1 d 0 x y xp = yp = zp = d x  x  z / d z / d     y y the desired perspective equations q =   ⇒⇒⇒ p =   z  z  • We will consider the corresponding     clipping volume with the OpenGL 1 z / d   functions OpenGL Orthogonal Viewing OpenGL Perspective glOrtho(left,right,bottom,top,near,far) glFrustum(left,right,bottom,top,near,far)

near and far measured from camera

Using Field of View Normalization

• With glFrustum it is often difficult to get the • Rather than derive a different projection desired view matrix for each type of projection, • gluPerpective(fovy, aspect, near, – convert all projections to orthogonal far) often provides a better interface projections with the default view volume front plane • Use standard transformations in the pipeline aspect = w/h • Makes for efficient clipping Pipeline View Notes • Stay in four-dimensional homogeneous coordinates through both the modelview modelview projection perspective and projection transformations transformation transformation division – Both these transformations are nonsingular 4D → 3D – Default to identity matrices (orthogonal view) nonsingular • Normalization lets us clip against simple cube regardless of type of projection clipping projection • Delay final projection until end → – Important for hidden-surface removal to against default cube 3D 2D retain depth information as long as possible

Orthogonal Normalization Orthogonal Matrix glOrtho(left,right,bottom,top,near,far) • Two steps – Move center to origin normalization ⇒ find transformation to convert specified clipping volume to default T(-(left+right)/2, -(bottom+top)/2,(near+far)/2)) – Scale to have sides of length 2 S(2/(left-right),2/(top-bottom),2/(near-far))

 2 right − left  0 0 −  − −  right left right left  2 top + bottom  0 0 −  P = ST =  top − bottom top − bottom   2 far + near   0 0   near − far far − near   0 0 0 1  Final Projection Oblique Projections

• Set z =0 • The OpenGL projection functions cannot produce general parallel projections such as • Equivalent to the homogeneous coordinate transformation 1 0 0 0   0 1 0 0 M =   orth 0 0 0 0   0 0 0 1 • However if we look at the example of the cube it appears that the cube has been sheared • Oblique Projection = Shear + Orthogonal • Hence, general orthogonal projection in 4D is Projection P = Morth ST

General Shear Shear Matrix

xy shear ( z values unchanged) 1 0 − cot θ 0  −  H(θ,φ) = 0 1 cot φ 0 0 0 1 0   0 0 0 1

Projection matrix θ φ P = Morth H( , ) top view side view P = M STH (θ,φ) General case: orth Effect on Clipping Simple Perspective

• The projection matrix P = STH transforms Consider a simple perspective with the COP at the original clipping volume to the default the origin, the near clipping plane at z = -1, and a 90 degree field of view determined by the clipping volume planes object top view z = 1 x = ±z, y = ±z DOP DOP x = -1 far plane x = 1 z = -1 clipping near plane volume distorted object (projects correctly)

Perspective Matrices Generalization

Simple projection matrix in homogeneous 1 0 0 0   0 1 0 0 coordinates N =   1 0 0 0 0 0 α β     0 1 0 0 0 0 −1 0 M =     0 0 1 0   after perspective division, the point ( x, y, z , 1) goes to 0 0 −1 0 x’’ = x/z y’’ = y/z Note that this matrix is independent of the Z’’ = -(α+β/z) far clipping plane which projects orthogonally to the desired point regardless of α and β Picking α and β Normalization Transformation

If we pick distorted object near + far α = projects correctly far − near 2near ∗far β = near − far

the near plane is mapped to z = -1 the far plane is mapped to z =1 original ± ± and the sides are mapped to x = 1, y = 1 clipping original object new clipping volume volume Hence the new clipping volume is the default clipping volume

Normalization and Hidden- Surface Removal OpenGL Perspective • Although our selection of the form of the • glFrustum allows for an unsymmetric perspective matrices may appear somewhat viewing frustum (although arbitrary, it was chosen so that if z1 > z2 in the original clipping volume then the for the gluPerspective does not) transformed points z1’ > z2’ • Thus hidden surface removal works if we first apply the normalization transformation • However, the formula z’’ = -(α+β/z) implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small OpenGL Perspective Matrix Why do we do it this way? • The normalization in glFrustum requires • Single pipeline for both perspective and an initial shear to form a right viewing orthogonal viewing pyramid, followed by a scaling to get the • Stay in four dimensional homogeneous normalized perspective volume. Finally, coordinates as long as possible the perspective matrix results in needing – retains three-dimensional information needed only a final orthogonal transformation for hidden-surface removal and shading P = NSH • Simplify clipping

our previously defined shear and scale perspective matrix

• Next time: – Illumination and shading – Light sources – Reflection – Shading in OpenGL