1
play

1 3 D Clipping 3 D Clipping Represent edge param et rically as - PDF document

3 D Clipping CS 4 7 3 1 : Com put e r Gr a phics Le ct u r e 1 4 : 3 D Clippin g a n d Vie w por t Tr a n sf or m a t ion Em m anuel Agu Clipping occur s a ft e r pr oj e ct ion t r a nsfor m a t ion Clipping is a ga inst ca nonica


  1. 3 D Clipping CS 4 7 3 1 : Com put e r Gr a phics Le ct u r e 1 4 : 3 D Clippin g a n d Vie w por t Tr a n sf or m a t ion Em m anuel Agu � Clipping occur s a ft e r pr oj e ct ion t r a nsfor m a t ion � Clipping is a ga inst ca nonica l vie w volum e 3 D Clipping 3 D Clipping Problem: � 3D clipping against canonical view volum e (CVV) � � Two point s, A = ( Ax, Ay, Az, Aw ) and C = ( Cx, Cy, Cz, Cw ), Autom atically clipping after projection m atrix in hom ogeneous coordinates � � I f segm ent int ersect s wit h CVV, need t o com put e Liang- Barsky algorithm (em bellished by Blinn) � intersection point I -= (I x, Iy, I z, I w ) CVV = = 6 infinite planes (x= - 1,1; y= - 1,1; z= - 1,1) � Clip edge- by- edge of the an object against CVV � Chopping m ay change num ber of sides of an object. E.g. � chopping tip of triangle m ay create quadrilateral 1

  2. 3 D Clipping 3 D Clipping � Represent edge param et rically as A + ( C – A)t � Using not at ion ( Aw + Ax) = w + x, writ e boundary coordinat es for 6 planes as: � I ntepretation : a point is t raveling such t hat : � at t im e t = 0, point at A Boundary Homogenous Clip plane � at t im e t = 1, point at C coordinate ( BC) coordinate � Lik e Cohen-Sut herland, first det erm ine t rivial accept / rej ect BC0 w+ x x= -1 E.g. t o t est edge against plane, point is: � BC1 w-x x= 1 � I nside (right of plane x= - 1) if Ax/ Aw > -1 or ( Aw + Ax) > 0 BC2 w+ y y= -1 � I nside ( left of plane x= 1) if Ax/ Aw < 1 or ( Aw -Ax ) > 0 BC3 w-y y= 1 BC4 w+ z z= -1 BC5 w-z z= 1 - 1 1 Ax/ Aw � Trivia l a ccept : 12 BCs ( 6 for pt . A, 6 for pt . C) are posit ive � Trivial rej ect: Bot h endpoint s out side of sam e plane 3 D Clipping 3 D Clipping I f not trivial accept/ rej ect, then clip How t o calculat e t _hit ? � � � Define Candidat e I nt erval ( CI ) as t im e int erval during which � Represent an edge t as: edge m ight st ill be inside CVV. i.e. CI = t _in t o t _out = + − + − + − + − Edge ( t ) (( Ax ( Cx Ax ) t , ( Ay ( Cy Ay ) t , ( Az ( Cz Az ) t , ( Aw ( Cw Aw ) t ) CI 0 1 + − Ax Cx Ax t ( ) = t E.g. I f x = 1, � 1 + − Aw ( Cw Aw ) t t_in t_out � Solving for t above, � Conversely: values of t out side CI = edge is out side CVV − Aw Ax = t I nit ialize CI t o [ 0,1] − − − � ( Aw Ax ) ( Cw Cx ) 2

  3. 3 D Clipping 3 D Clipping � Test against each wall in t urn � Algorithm : � I f BCs have opposit e signs = edge hit s plane at t im e t _hit � Test for t rivial accept / rej ect ( st op if eit her occurs) Define: “ ent ering” = as t increases, out side t o inside � Set CI t o [ 0,1] � i.e. if pt . A is out side, C is inside � For each of 6 planes: � Likewise, “ leaving” = as t increases, inside t o out side ( A inside, � Find hit t im e t _hit � C out side) � I f, as t increases, edge ent ering, t _in = m ax( t _in,t _hit ) � I f, as t increases, edge leaving, t _out = m in( t _out , t _hit ) � I f t _in > t _out = > exit ( no valid int ersect ions) N ot e : seeking sm allest valid CI wit hout t _in crossing t _out 3 D Clipping 3 D Clipping � I f valid t _in, t _out , calculat e adj ust ed edge endpoint s A, C as Exam ple t o illust rat e search for t _in, t _out N ot e : CVV is different shape. This is j ust exam ple � A_chop = A + t _in ( C – A) � C_ chop = C + t _ out ( C – A ) 3

  4. 3 D Clipping I m plem entation 3 D Clipping I m plem entation � Funct ion clipEdge( ) � Use outcodes t o t rack in/ out � I nput : t wo point s A and C ( in hom ogenous coordinat es) � Number walls 1… 6 � Bit i of A’s outcode = 0 if A is inside it h wall � Output: � 1 otherwise � 0, if no part of line AC lies in CVV � Trivial accept : bot h A and C out codes = 0 � 1, otherwise � � Also returns clipped A and C Trivial rej ect : bit wise AND of A and C out codes is n on-zero � Store 6 BCs for A, 6 for C � I f not trivial accept/ reject: � Compute tHit � Update t_in, t_out � If t_in > t_out, early exit 3 D Clipping Pseudocode 3 D Clipping Pseudocode int clipEdge( Point4& A, Point4& C) for( i= 0;i< 6;i+ + ) / / clip against each plane { { double tI n = 0 .0 , tOut = 1 .0 , tHit; if( cBC[ I ] < 0) / / exits: C is outside double aBC[ 6 ] , cBC [ 6] ; { int aOutcode = 0, cOutcode = 0; tHit = aBC[ I ] / (aBC[ I ] – cBC[ I ] ) ; tOut = MI N( tOut, tHit); …..find BCs for A and C } …..form outcodes for A and C else if( aBC[ i] < 0 ) / / enters: A is outside { if( ( aOutCode & cOutcode ) != 0) / / trivial reject tHit = aBC[ i] / (aBC[ i] – cBC [ i] ) ; return 0; if( ( aOutCode | cOutcode ) = = 0) / / trivial accept tI n = MAX( tI n, tHit); return 1; } if( tI n > tOut) return 0; / / CI is em pty: early out } 4

  5. 3 D Clipping Pseudocode View port Transform ation Point4 tmp ; / / stores homogeneous coordinates � After clipping, do viewport t ransform at ion I f( aOutcode != 0) / / A is out: tI n has changed � We have used glViewport ( x,y, w id, ht) before { � Use again here! ! tmp .x = A.x + tI n * ( C.x – A.x) ; � glViewport shift s x, y t o screen coordinat es / / do sam e for y, z, and w com ponents � Also m aps pseudo -dept h z fr om r ange [ - 1,1] to [ 0,1] } � Pseudo- dept h st ored in dept h buffer, used for Dept h t est ing ( Will I f( cOutcode != 0 ) / / C is out: tOut has changed discuss later) { C.x = A.x + tOut * ( C.x – A.x); / / do sam e for y, z and w com ponents } A = tmp ; Return 1; / / som e of the edges lie inside CVV } References � Hill, sections 7.4.4, 4.8.2 5

Recommend


More recommend