












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Computer Graphics 3D Clipping and Viewport Transformation
ß Clipping occurs after projection transformation
ß Clipping is against canonical view volume
n Two points, A = (Ax, Ay, Az, Aw) and C = (Cx, Cy, Cz, Cw), in homogeneous coordinates n If segment intersects with CVV, need to compute intersection point I-=(Ix,Iy,Iz,Iw)
n Using notation (Aw +Ax) = w + x, write boundary coordinates for 6 planes as:
BC5 w-z z=
BC4 w+z z=-
BC3 w-y y=
BC2 w+y y=-
BC1 w-x x=
BC0 w+x x=-
Homogenous Clip plane coordinate
Boundary coordinate (BC)
ß Trivial accept: 12 BCs (6 for pt. A, 6 for pt. C) are positive ß Trivial reject: Both endpoints outside of same plane
n If not trivial accept/reject, then clip
n Define Candidate Interval (CI) as time interval during which edge might still be inside CVV. i.e. CI = t_in to t_out
n Conversely: values of t outside CI = edge is outside CVV
n Initialize CI to [0,1]
n Test against each wall in turn
n If BCs have opposite signs = edge hits plane at time t_hit
n Define: “entering” = as t increases, outside to inside
n i.e. if pt. A is outside, C is inside
n Likewise, “leaving” = as t increases, inside to outside (A inside, C outside)
n Algorithm: n Test for trivial accept/reject (stop if either occurs) n Set CI to [0,1] n For each of 6 planes: n Find hit time t_hit n If, as t increases, edge entering, t_in = max(t_in,t_hit) n If, as t increases, edge leaving, t_out = min(t_out, t_hit) n If t_in > t_out => exit (no valid intersections)
Note: seeking smallest valid CI without t_in crossing t_out
n If valid t_in, t_out, calculate adjusted edge endpoints A, C as
n A_chop = A + t_in ( C – A) n C_chop = A + t_out ( C – A)
n Function clipEdge( ) n Input: two points A and C (in homogenous coordinates) n Output: n 0, if no part of line AC lies in CVV n 1, otherwise n Also returns clipped A and C n Store 6 BCs for A, 6 for C
int clipEdge(Point4& A, Point4& C) { double tIn = 0.0, tOut = 1.0, tHit; double aBC[6], cBC[6]; int aOutcode = 0, cOutcode = 0;
…..find BCs for A and C …..form outcodes for A and C
if((aOutCode & cOutcode) != 0) // trivial reject return 0; if((aOutCode | cOutcode) == 0) // trivial accept return 1;
for(i=0;i<6;i++) // clip against each plane { if(cBC[i] < 0) // exits: C is outside { tHit = aBC[i]/(aBC[i] – cBC[I]); tOut = MIN(tOut, tHit); } else if(aBC[i] < 0) // enters: A is outside { tHit = aBC[i]/(aBC[i] – cBC[i]); tIn = MAX(tIn, tHit); } if(tIn > tOut) return 0; // CI is empty: early out }
n After clipping, do viewport transformation n We have used glViewport(x,y, wid, ht) before n Use again here!! n glViewport shifts x, y to screen coordinates n Also maps pseudo-depth z from range [-1,1] to [0,1] n Pseudo-depth stored in depth buffer, used for Depth testing (Will discuss later)