Viewing in 3D Common Coordinate Systems
Total Page:16
File Type:pdf, Size:1020Kb
Common Coordinate Viewing in 3D Systems (Chapt. 6 in FVD, Chapt. 12 in Hearn & Baker) • Object space – local to each object • World space – common to all objects • Eye space / Camera space – derived from view frustum • Screen space – indexed according to hardware attributes y Specifying the Viewing v Up Coordinates P u w • Viewing Coordinates system, [u, P 0 v, w], describes 3D objects with x z respect to a viewer. ane pl ew Vi • A viewing plane (projection plane) is set up perpendicular to • P =(x ,y ,z ) is a point where a 0 0 0 0 w and aligned with (u,v). camera is located. • P is a point to look-at. • To set a view plane we have to • N=(P -P)/|P -P| is the view-plane specify a view-plane normal 0 0 vector, N, and a view-up vector, normal vector. Up, (both, in world coordinates): • Up is the view up vector, whose projection onto the view-plane is directed up. • How to form Viewing How to form Viewing coordinate system coordinate system : Up N UpuN w ; u ; v wuu N N UpuN • The transformation, M, from world-coordinate into viewing- coordinates is: ªu u u 0ºª1 0 0 x º « x y z » 0 « » w N / || N || « v v v 0» 0 1 0 y0 M x y z « » «w w w 0»«0 0 1 z » « x y z »« 0 » First, normalize the look-at vector to form the w-axis ¬« 0 0 0 1¼»¬0 0 0 1 ¼ Create V perpendicular to U and W Create U perpendicular to Up and W V Up Up W W U U u UpuW V W U U |UpuW | Projections • Viewing 3D objects on a 2D display requires a mapping from 3D to 2D. • A projection is formed by the intersection of certain lines (projectors) with the view plane. • Projectors are lines from the center of projection through each point in the object. Center of Projection • Center of projection at infinity Parallel Projection results with a parallel projection. A parallel projection preserves relative • A finite center of projection results proportions of objects, but does not with a perspective projection. give realistic appearance (commonly used in engineering drawing). Parallel Projection Perspective Projection • Projectors are all parallel. A perspective projection produces realistic • Orthographic: Projectors are appearance, but does not preserve relative perpendicular to the projection proportions. plane. • Oblique: Projectors are not necessarily perpendicular to the projection plane. Orthographic Oblique • Lengths and angles of faces Orthographic Projection parallel to the viewing planes are preserved. • Since the viewing plane is aligned • Problem: 3D nature of projected with (xv,yv), orthographic objects is difficult to deduce. projection is performed by: ªx º ªx º ª1 0 0 0ºªx º « p » « v » « »« v » T op «y p » «yv » «0 1 0 0»«yv » View « 0 » « 0 » «0 0 0 0»«z » « » « » « »« v » ¬ 1 ¼ ¬ 1 ¼ ¬0 0 0 1¼¬ 1 ¼ F iew ron V t v ide iew S (x,y,z) (x,y) yv xv P0 zv • Cavalinear projection : Oblique Projection – Preserves lengths of lines perpendicular to the viewing plane. • Projectors are not perpendicular to the – 3D nature can be captured but viewing plane. • Angles and lengths are preserved for faces shape seems distorted. parallel to the plane of projection. • Cabinet projection: • Somewhat preserves 3D nature of an object. – lines perpendicular to the viewing plane project at 1/2 of their length. – A more realistic view than the Cavalinear projection. y 1 1 1/2 1 x x 1 1 45° 45° z z Cavalinear Projection Cabinet Projection Perspective Projection • In a perspective projection, the center of projection is at a finite distance from the viewing plane. • Parallel lines that are not parallel to the viewing plane, converge to a vanishing point. – A vanishing point is the projection of a point at infinity. Z-axis vanishing point y x z y Vanishing Points • There are infinitely many general vanishing points. x • There can be up to three axis z vanishing points (principal vanishing points). • Perspective projections are One point (z axis) categorized by the number of perspective projection principal vanishing points, equal to the number of principal axes x axis z axis intersected by the viewing plane. vanishing point. vanishing point. • Most commonly used: one-point Two points and two-points perspective. perspective projection 3-point Perspective M.C.Escher’s"Relativity" where 3 worlds co- exist thanks to 3-point perspective. 3-point Perspective Perspective Projection (x,y,z) A perspective projection produces (xp,yp,0) realistic appearance, but does not preserve relative proportions. y center of d x projection z x (x,y,z) xp z d • Using similar triangles it follows: x x y y p ; p d zd d zd dx dy x ; y ; z 0 p zd p zd p Observations • Thus, a perspective projection matrix is defined: • Mper is singular (|Mper|=0), thus ª1 0 0 0º Mper is a many to one mapping « » «0 1 0 0» M per «0 0 0 0» • Points on the viewing plane « 1 » «0 0 1» (z=0) do not change. ¬ d ¼ • The vanishing point of parallel ª1 0 0 0ºª º ª x º « » x « » lines directed to (Ux,Uy,Uz) is at 0 1 0 0 « » y « »«y» « » [dU /U , dU /U ]. M P « » « » x z y z per 0 0 0 0 «z» 0 « 1 »« » « z d » f «0 0 1»¬1¼ « » • When d , Mper Mort ¬ d ¼ ¬ d ¼ dx dy x ; y ; z 0 p zd p zd p Zoom-in Zoom-in Projection Projection plane plane Center of Center of Projection Projection What is the difference between moving the center of Summary projection and moving the projection plane? Original Planar geometric projections Center of Projection z plane Parallel Perspective Projection One Moving the Center of Projection Oblique Orthographic point Front Top Cavalinear Two Side Other point Center of Projection z Cabinet Projection plane Other Three Moving the Projection Plane point Center of Projection z Projection plane Another view in Another view in Perspective Perspective 7KUHHSRLQWÃSHUVSHFWLYH 7ZRSRLQWÃSHUVSHFWLYH )RXUSRLQWÃSHUVSHFWLYH 7KUHHSRLQWÃSHUVSHFWLYH Fisheye views of the Hagia Sophia (Istanbul) )LYHSRLQWÃSHUVSHFWLYHÃ" (also known as Aya Sofya ) 6L[SRLQWÃSHUVSHFWLYHÃ" Vertical lines Fisheye view View Window House of Stairs • After objects were projected onto the viewing plane, an image is taken from a View Window. • A view window can be placed anywhere on the view plane. • In general the view window is aligned with the viewing coordinates and is defined by its extreme points: (xwmin,ywmin) and (xwmax,ywmax) e plan View y ) v yw max x, (xw ma xv View window zv ) ,ywmin (xwmin M.C. Escher’s House of Stairs • In order to limit the infinite view volume we View Volume define two additional planes: Near Plane and Far Plane. • Given the specification of the view • Only objects in the bounded view volume window, we can set up a View Volume. can appear. • Only objects inside the view volume • The near and far planes are parallel to the might appear in the display, the rest are view plane and specified by znear and zfar. clipped. • A limited view volume is defined: – For orthographic: a rectangular parallelpiped. – For oblique: an oblique parallelpiped. – For perspective: a frustum. Far zv Plane Near Plane dow win zv Far w indo Plane Near w Plane Trivial Accept/Reject Canonical View Volumes • In order to determine the objects that are seen in the view window we have to clip objects against six planes forming the view volume. • Clipping against arbitrary 3D plane requires considerable computations. • For fast clipping we transform the general view volume to a canonical Red polygons are rejected view volume against which clipping is easy to apply. Viewing Black are accepted Coordinates And Canonical view Blue are tagged for clipping Transformation Clipping Projection Transformation Ax By C 0 z Classify the vertices of the polygons against Affine Transformation: each side Si of the frustum in turn: x y If all the vertices are on the outside of some Si, then cull the polygon, otherwise, Polygons with all its vertices inside all Sj are n accepted. z n All others are tagged. OpenGL Transformation Perspective transformation: Pipe-Line cc c ªxc º ª1 0 0 0 ºªxc º « » « »« » « cc» « »« c » Homogeneous coordinates « yc » «0 1 0 0 »« yc » in World System « » « »« » cc f n fn c « zc » «0 0 2 »« zc » « » « f n f n»« » « » « »« » ¬ 1 ¼ ¬0 0 1 0 ¼¬ 1 ¼ ModelView Matrix xcc xc xc ycc yc yc Viewing Coordinates xcc ycc 1 zc zc 1 zc zc Projection Matrix >@>@0 0 n 1 o 0 0 1 1 Clip Coordinates >@>@0 0 f 1 o 0 0 1 1 Clipping -1 1 1 Viewport z z Transformation -1 -1 Window Coordinates .