Three-Dimensional i Viewingi Chap 7, 29 Spring Yeong Gil Shin
Viewing i Pipeline H d fi i d? How to define a window? How to project onto the window?
Rendering "Create a picture (in a snthetic camera) Specification of projection tpe Specification of viewing parameters: viewer's ee, viewing plane (viewing coordinates) Clipping in 3D: window, view volume Projection : the transformation of points from a coordinate sstem in n dimensions to a coordinate sstem in m dimensions where m<n Displa: view port
General 3D Viewing i Pipeline Modeling coordinates (MC) World coordinates (WC) Viewing coordinates (VC) VRC, camera position Projection coordinates (PC) window, projection tpe Normalied coordinates (NC) Device coordinates (DC) view port in a screen
Projections Projection coordinate sstem: Left-handed Core, DirectX wh? h? - screen coordinate sstem is left-handed d Right-handed - GKS, PHIGS, OpenGL Projection plane (view plane): viewing surface where objects are projected. v n u
Viewing-Coordinate Parameters View reference point (VRP) The viewing origin in WC : P Ee position, camera position = (,, ) Viewing Coordinate : view, view, view (or uvn) Defined b P,N,VUP View-plane (Projection plane) Locates on view ais : vp Perpendicular to view
Viewing-Coordinate Parameters How we specif a view plane normal vector, N [Wa I] The origin of WC to a selected point position [Wa II] The direction from a reference point P ref to the viewing origin: N = P P ref P ref : look-at point ref Viewing direction: N (in RHS)
Viewing-Coordinate Parameters View-up vector: VUP Specified in the world coordinates Used to establish the positive direction for the view ais VUP should be perpendicular to N, but it can be difficult to a direction for VUP that is precisel perpendicular p to N view VUP view N P = VRP view
Viewing-Coordinate Reference Frame (VRC) The camera orientation is determined b viewing reference frame, View Reference Coordinate (VRC), view, view, view (or uvn) The origin of the viewing reference frame : P (= VRP) n = N = ( n, n, n ) N VUP n u = VUP v = n u = ( u, u, u = ( v, v, v ) ) n VUP N v P View plane w.r.t. VRC u
World-to-Viewing Transformation Transformation from WC to VRC Translate the viewing-coordinate origin to the worldcoordinate origin Appl rotations to align the u, v, n aes with the world w, w, w aes, respectivel u v n
World-to-Viewing Transformation v v v u u u T R = = n n n T R u n v P P u u u u = =, P n P v T R M vc wc n n n v v v
Eample of VRC WC Given R VUP R R R R = = VPN = VUP = R VUP VUP = 2.5 = det 2.5 = R R R R ( 6 8 7.5) ( ) ( 6, 8, 7.5) i 6. j 8. = (.8,.6,.) VPN = (.48,.64,.6), k 7.5 = (.35,.48,.8) = 2.5 VUP ( 8. 6..) R R R R =
Hierarch of plane geometric projections plane geometric projections parallel perspective orthographic aonometric oblique trimetric cavalier cabinet dimetric isometric single-point two-point three-point
Parallel l Projections Parallel l direction of projection (DOP) Direction of projection same for all points The parallel l projection of fthe point t( (,,) on the -plane gives ( + a, + b,) When a = b =, the projection is said to be orthographic or orthogonal. Otherwise, it is oblique. Preserves relative dimension Orthographic parallel projections The direction of projection is normal to the projection plane Architectural, engineering drawings
Aonometric Parallel Projection Orthographic h parallel l projection that displas more than one face of an object Projection plane intersects each principal ais Classif b how man identical angles of a corner of a projected cube. Three: isometric Two: dimetric None : trimetric t i
Oblique Parallel Projections Parallel projection of which DOP is not perpendicular to the projection plane Onl faces of the object parallel to the projection plane are shown true sie and shape DOP α A' B' Α Β C AB = A' B' B' C' = BC 2 α = arctan(/ 2) = 26. 565 C ' )
Oblique Parallel Projections cavalier projections DOP 45 cabinet projections DOP 63.4
Perspective vs. Parallel Projections Perspective Parallel
Perspective Projections Lines that are not parallel l to the projection plane converge to a a single point in the projection (the vanishing point) Lines parallel to one of the major ais come to a vanishing point, these are called (principle) ais vanishing points. Onl three ais vanishing points in 3D space. Vanishing point
Projection Tpes
Projections Window a rectangular region on the projection plane (defined in VRC) Projection Reference Point (PRP) PRP is specified in the VRC sstem In general, PRP = the origin of Viewing reference coordinate Direction of projection (DOP): in a parallel projection, PRP CW Center of projection (COP): in a perspective projection, PRP = COP v window n COP=PRP u CW (Center of Window) Projection Plane
View Volume (View Frustum) 3D clipping region where we can see Defined b front and back clipping planes (which are parallel to view plane) (,,) (right,top,near) COP (left,bottom,near) far near and far are positive
Create a View Volume (left, top) far v near u (right, bottom) n CW is not aligned n-ais (left, right, top, bottom, near, far) n width far height v near u CW is aligned n-ais (width, height, ht near, far) n far CW is aligned n-ais v near (field of view, aspect, near, far) aspect = width/height u field of view
3D Viewing i ) Establishing a View Reference Coordinate Sstem User suppl the following parameters the view reference point (VRP) - in WC VPN - a vector in WC VUP - a vector in WC v n VRP u
3D Viewingi 2) View Mapping (WC VRC NPC) the projection tpe the Projection Reference Point (PRP) a view plane distance (= vp ) In DirectX, view plane is identical to near plane anearplaneandafarplanedistance 3) device-dependent dependent transformation v n PRP=COP u
Planar Geometric Projections Mathematics of Planar Geometric Projections P(,,) P p ( p, p,d) COP d Centre of projection at the origin Centre of projection at the origin Projection plane at =d
Planar Geometric Projections = = d d p p ; P(,,) P (,,d) = = = = d d d d d d p p / ; / P p ( p, p,d) d Y X d d / / = = d P M W Z Y per / = = d d d X Y X d W p p p, /, / ),, (,, / d d W W W p p p, /, / ),, (,,
Normaliing i Transformation Transform an arbitrar parallel- or perspectiveprojection view volume into the normalied or canonical view volume (in DirectX) or or - B - F - B - F parallel-projection canonical view volume - - perspective-projection canonical view volume
Normaliing i Transformation OpenGL
Normaliing transformation for parallel projections. Translate VRP to the origin of the WC 2. Rotate VRC such that n ais = ais, u ais = ais and v ais = ais. (B & 2, transformation from WCS to VRC) 3. Shear so the direction of projection parallel to the ais. (not necessar for orthographic projections) 4. Translate and scale into the parallel-projection canonical view volume v WC n u VRP (=PRP) CW
Normaliing transformation for parallel projections [Step2] R ( θ ) R ( φ ) R ( α ) ( VUP n Or use orthogonal matri properties v VRP VPN R u VPN VUP R = R = R = R R VPN VUP R r r2 r3 r r2 r3 R = r r r 2 3
Normaliing transformation for parallel projections [Step 3] shearing after step2, VRC = WC DOP = CW - PRP DOP VPN DOP - VPN -
Normaliing transformation for parallel projections -component of DOP is invariant. a b SH a b (, ) = DOP = CW PRP = dop wc ( dop dop ) DOP VPN - DOP - VPN a b DOP DOP ' = wc = dop dop dop a =, b = dop dop
Normaliing transformation for parallel projections View volume after transformation steps to 3 (u ma, v ma, B) - B - - or F (u min, v min, F) Step4 -
Normaliing transformation for parallel projections [Step 4] translate and scale. Translate satethe front center of the view volume ou uma + umin v + vmin T = ma par T,, F 2 2 2. Scale to the 2 2 sie 2 2 S par = S,, uma umin vma vmin F B
Normaliing transformation for perspective projection. Translate VRP to the origin of the WC: T( VRP) 2. Rotate VRC such that n ais = ais, u ais = ais and v ais = ais 3. Translate such that PRP=(prp u, prp v, prp n ) is at the origin: T( PRP) 4. Shear so the center line of the view volume becomes the -ais 5. (Scale such that the view volume becomes the canonical perspective view volume.) v WC n PRP=COP u
Normaliing transformation for perspective projection After step,2,3 Step 4 v n u PRP v n u
Normaliing transformation for perspective projection [Step 4] shearing shear so that CW PRP is into ais SH per = SH par Another Wa: VRP' = SH per T(-PRP) [ ] T component of VRP': vrp = prp n PRP
Normaliing transformation for perspective projection [Step 5] scale. Scale and to give the sloped planes bounding the view-volume unit slope. Scale the window so its half-height eg tand half-width are both vrp scale : scale : 2 vrp' ( u ma u min ) 2 vrp' ( v ma v min ) vrp v ma v min 2 = vrp ' + B ' ' v ma = vrp + F v 2 min
Normaliing transformation for perspective projection 2. Scale uniforml all three aes such that the back clipping plane =vrp +B becomes. scale factor: /(vrp +B) Perspective scale transformation ti S per = 2vrp ' 2vrp' S,, ( uma umin )( vrp' + B) ( vma vmin )( vrp' + B) ( vrp' + B)
DirectX: Viewing Transformation How to define VRC Ee-Point (= VRP) Look-At Position Look-At Position - Ee-Point N Up-Vector ( v, view ) Ee Up-vector v n LHS u Look-at Snta D3DXMATRIX *D3DXMatriLookAtLH( D3DXMATRIX *pout, CONST D3DXVECTOR3 *pee, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup ); Parameters pout : Pointer to the D3DXMATRIX structure that is the result of the operation. pee : Pointer to the D3DXVECTOR3 structure that defines the ee point. pat : Pointer to the D3DXVECTOR3 structure that defines the camera look-at target. pup : Pointer to the D3DXVECTOR3 structure that defines the current world's up, usuall [,, ].
DirectX: Orthographic Parallel Projection Transformation Snta D3DXMATRIX *WINAPI D3DXMatriOrthoLH( D3DXMATRIX *pout, FLOAT w, FLOAT h, FLOAT n, FLOAT f ); Parameters pout : Pointer to the D3DXMATRIX structure that contains the resulting matri. w : Width of the view volume. h : Height of the view volume. n : Minimum -value of the view volume which is referred to as -near. f : Maimum -value of the view volume which is referred to as -far. view view near w far h view
DirectX: Oblique Parallel Projection Transformation Snta D3DXMATRIX *D3DXMatriOrthoOffCenterLH (D3DXMATRIX *pout,, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT n, FLOAT f ); Parameters pout : Pointer to the D3DXMATRIX structure that is the result of the operation. l : Minimum -value of view volume. r : Maimum -value of view volume. b : Minimum -value of view volume. t : Maimum -value of view volume. n : Minimum -value of the view volume. f : Maimum -value of the view volume. view near far view view
DirectX: Perspective Projection Transformation When CW aligns n-ais Snta D3DXMATRIX *D3DXMatriPerspectiveFovLH( D3DXMATRIX *pout, FLOAT fov, FLOAT Aspect, FLOAT n, FLOAT f ); Parameters pout : Pointer to the D3DXMATRIX structure that is the result of the operation. fov : Field of view in the direction, in radians. Aspect : Aspect ratio, defined as view space width divided b height. n : Z-value of the near view-plane. f :Z-value of the far view-plane. n = view v = view far near u = view
DirectX: Perspective Projection Transformation When CW does not align n-ais Snta D3DXMATRIX *D3DXMatriPerspectiveOffCenterLH (D3DXMATRIX *pout, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT n, FLOAT f ); Parameters pout : Pointer to the D3DXMATRIX structure that is the result of the operation. l : Minimum -value of the view volume. r : Maimum -value of the view volume. b : Minimum -value of the view volume. t : Maimum -value of the view volume. n : Minimum -value of the view volume. f : Maimum -value of the view volume. view far near view view
3D Clipping i For orthographic projection, view volume is a bo For perspective projection, view volume is a frustum left Near clipping plane Far clipping plane. right Need to calculate intersection with 6 planes
3D Clipping i Clipping is efficientl done on the normalied view volume. The canonical parallel projection view volume is defined b:,, Clip primitives against this view volume
3D Region Coding for Clipping 3-D Etension of 2-D Cohen-Sutherland Algorithm For parallel-projection canonical view volume : Bit - point is above view volume: > Bit 2 - point is below view volume: < Bit 3 - point is right of view volume: > Bit 4 - point is left view volume: < Bit 5 - point is behind view volume: < Bit 6 - point is in front of view volume: > B or F
3D Region Coding for Clipping
3D Region Coding for Clipping For perspective-projection canonical view volume + F = B Bit - Point is above view volume > Bit 2 - Point is below view volume < Bit 3 - Point is right of view volume > Bit 4 - Point is left of view volume < Bit 5 - Point is behind view volume < = Bit 6 - Point is in front of view volume > min
Clipping and Homogeneous Coordinates Efficient to transform frustum into perspective canonical view volume unit slope planes Even better to transform to parallel canonical view volume Clipping i must be done in homogeneous coordinates We do not need to [X,Y,Z,W] [,,,] for the clipped region Points in homogeneous coordinate can appear with W and cannot be clipped properl in 3D
Clipping and Homogeneous Coordinates 3D parallel projection volume is defined b:,, Replace b X/W,Y/W,Z/W: X/W, Y/W, Z/W Corresponding plane equations are : X= W, X=W, Y= W, Y=W, Z= W, Z= If W>, multiplication li b W does not change sign. W>: W X W, W Y W, W Z However if W<, need to change sign : W<: W X W, W Y W, W Z
Clipping and Homogeneous Coordinates For the canonical parallel projection volume:,,, To clip to = (left): Homogeneous coordinate: Clip to X/W = Homogeneous plane: W+X = Point is visible if W+X >
Clipping and Homogeneous Coordinates The intersection of the line segment with a clipping plane: P 2 = ( α)p + αp and w + = [( α) w + αw2 ] + [( α) + α2] = P α = (w + + w 2 ) (w 2 + 2 ) P 2 Repeat for remaining boundaries : other Near and Far clipping planes
Clipping and Homogeneous Coordinates (eample) P = [ 2, *, *,2] P = [, 2*, 2*, 2 ] 2 OB region P 2 P α = (w + w 2 + ) (w 2 2 ) 2 + 2 ( 2) ( 2) 2 = = + 8 9 * * * * * * * P = [ 2, 8 8 2 + ( 2 ), + ( 2 ), ] 3 9 9 3 * Projected -coordinate of P = = w
Points in Homogeneous Coordinates W Region A P =[ 2 3 4] T W= Projection of P and dp 2 onto W= plane X or Y Region B P 2 =[ 2 3 4] T Need to consider both regions when performing clipping
Lines in Homogeneous Coordinates Could clip twice once for region A, once for region B. Epensive Check for negative W values and negate points before clipping P W Projection of points W= X P2
Lines in Homogeneous Coordinates P W Clipped lines W=X W= X W= X P2
3D Polgon Clipping Algorithms Bounding bo or sphere test for earl rejection Sutherland-Hodgman and Weiler-Atherton algorithms can be generalied
What s Net