Docsity

Viewport - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Viewport - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer Graphics 3D Clipping and Viewport Transformation

3D Clipping

ß Clipping occurs after projection transformation

ß Clipping is against canonical view volume

3D Clipping

n 3D clipping against canonical view volume (CVV)

n Automatically clipping after projection matrix

n Liang-Barsky algorithm (embellished by Blinn)

n CVV == 6 infinite planes (x=-1,1;y=-1,1;z=-1,1)

n Clip edge-by-edge of the an object against CVV

n Chopping may change number of sides of an object. E.g.

chopping tip of triangle may create quadrilateral

3D Clipping

n Problem:

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)

3D Clipping

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

3D Clipping

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]

t

t_in t_out

CI

3D Clipping

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)

3D Clipping

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

3D Clipping

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)

3D Clipping Implementation

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

3D Clipping Pseudocode

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;

3D Clipping Pseudocode

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 }

Viewport Transformation

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)

References

n Hill, sections 7.4.4, 4.8.