1 / 41

Collisions and Intersections

Collisions and Intersections. When objects move, test for collision. When projecting surfaces, check for intersections. ( Many slides adapted from Amitabh Varshney). Collision Strategy. Brute force test. Fine if few shapes. Test by bounding with simpler shape.

dory
Download Presentation

Collisions and Intersections

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Collisions and Intersections • When objects move, test for collision. • When projecting surfaces, check for intersections. (Many slides adapted from Amitabh Varshney)

  2. Collision Strategy • Brute force test. Fine if few shapes. • Test by bounding with simpler shape. • Only do brute force if necessary. • Use hierarchy of simpler shapes. • Faster for complex scenes.

  3. 2D Intersections • Sides intersect • Or one inside other

  4. Sides Intersect • Intersect lines and check whether intersection point is inside each line segment. • Check if each line divides other line segment in half.

  5. How to tell whether two line segments intersect. First, convert to equations for lines. (x1,y1) (x2,y2) goes to y = (y2-y1)/(x2-x1)x + (y1(x2-x1) – x1(y2-y1). Now suppose we have two lines, y = m1x+b1, y = m2x+b2. Solve for x and y. For example, we have m1x+b1=m2x+b2. x = (b1-b2)/(m2-m1). Now we want to know whether (x,y) is in between (x1,y1) and (x2,y2), and the same for the other line segment. One simple way is to tell whether the sum of the distance from each end point to (x,y) is the same as the distance between the end points. This is a bit cumbersome. We can do things with less computation by checking whether the line of line segment one divides the endpoints of line segment two, and vice versa. To do this, compute the line the first line segment lies on, and represent it as: ax + by = c, where (a,b) is a unit vector. Then compute (a,b)*(x1,y1) = c1, and (a,b)*(x2,y2) = c2. We should have either c1 <= c <= c2, or c2 <= c <= c1.

  6. One shape inside another • Easier for convex shapes. • Convex polygon is inside iff all vertices are inside. • Vertex is inside iff it is on inside of each side. • If shape isn’t convex, decompose it into convex shapes.

  7. Recall from before how to tell if a point is inside a convex shape, by judging whether it is on the appropriate side of each bounding line of the shape. We can write a line as (a,b)*(x,y) = c. Then a side of the line is (a,b)*(x,y) >= c (or <=c).

  8. Circles easier • Testing whether two circles intersect is much easier. • So put a circle around each shape (How?) (x2,y2) r2 (x1,y1) r1 (x2-x1)2 + (y2-y1)2 > (r1+r2)2

  9. Circles • Pros: Very fast. • If scene is fixed, circles for scene can be computed once. • If object moves, circle can move with it easily. • Cons: Circle can exaggerate shape.

  10. Axial Rectangles • A rectangle with sides aligned with the x and y axes. • Easy to generate. Just take min and max x and y values. • Easy to check for intersection. • Don’t intersect if one max value less than other’s min value.

  11. Hierarchical • Keep subdividing space into axial rectangles: quadtrees. • Bound everything with axial rectangles. • Divide space into four squares. Does object share a square with the scene? • If yes, recurse. • At some point just check. • Many related, more complicated strategies possible.

  12. Algorithms for Visibility Determination • Object-Order • Sort the objects and then display them • Image-Order • Scan-convert objects in arbitrary order and then depth sort the pixels • Hybrid of the above

  13. Painter’s Algorithm • Object-Order Algorithm • Sort objects by depth • Display them in back-to-front order

  14. Painter’s Algorithm Second Fourth Third First

  15. Painter’s Algorithm • Sort polygons by farthest depth. • Check if polygon is in front of any other. • If no, render it. • If yes, has its order already changed backward? • If no, render it. • If yes, break it apart.

  16. Which polygon is in front? Our strategy: apply a series of tests. • First tests are cheapest • Each test says poly1 is behind poly2, or maybe. • If min z of poly1 > max z poly2, 1 in back.

  17. x 2. The plane of the polygon with smaller z is closer to viewer than other polygon. (a,b,c,)*(x,y,z) >= d. B A z x 3. The plane of polygon with larger z is completely behind other polygon. B A z

  18. 4. Check whether they overlap in image • Use axial rectangle test. • Use complete test. y y x x Non-Overlapping x or y Overlapping projection x B B is on one side of A A z

  19. Problem Cases: Cyclic and Intersecting Objects

  20. Painter’s Algorithm • Solution: split polygons • Advantages of Painter’s Algorithm • Simple • Easy transparency • Disadvantages • Have to sort first • Need to split polygons to solve cyclic and intersecting objects

  21. Z-Buffer Algorithm • Image precision, object order • Scan-convert each object • Maintain the depth (in Z-buffer) and color (in color buffer) of the closest object at each pixel • Display the final color buffer • Simple; easy to implement in hardware

  22. Z-Buffer Algorithm for( each pixel(i, j) ) // clear Z-buffer and frame buffer { z_buffer[i][j] = far_plane_z; color_buffer[i][j] = background_color; } for(each face A) for( each pixel(i, j) in the projection of A) { Compute depth zand color cof Aat (i,j); if( z > z_buffer[i][j] ) { z_buffer[i][j] = z; color_buffer[i][j] = c; } }

  23. Efficient Z-Buffer • Incremental computation • Polygon satisfies plane equation • Z can be solved as • Take advantage of coherence • within scan line: • next scan line:

  24. z1 y1 zp za zb ys y2 z2 y3 z3 Z Value Interpolation

  25. Z-Buffer: Analysis • Advantages • Simple • Easy hardware implementation • Objects can be non-polygons • Disadvantages • Separate buffer for depth • No transparency • No antialiasing: one item visible per pixel

  26. Spatial Data-Structures for Visibility • Octrees (generalization of Binary trees in 1D and Quad trees in 2D) • Binary-Space Partition Trees (BSP trees) (an alternative generalization of Binary trees in 1D) • Subdividing architectural buildings into cells (rooms) and portals (doors/windows)

  27. Portals • Similar to view-frustum culling • View-independent • Preprocess and save a list of possible visible surfaces for each portal

  28. Cells and Portals A D E F B C G H A E B C D F G H Images courtesy: Dave Luebke, UVa

  29. Cells and Portals A D E F B C G H A E B C D F G H Images courtesy: Dave Luebke, UVa

  30. Cells & Portals A D E F B C G H A E B C D F G H Images courtesy: Dave Luebke, UVa

  31. Cells & Portals A D E F B C G H A E B C D F G H Images courtesy: Dave Luebke, UVa

  32. Cells & Portals A D E F B C G H A E B C D F G H Images courtesy: Dave Luebke, UVa

  33. BSP Trees • Idea • Preprocess the relative depth information of the scene in a tree for later display • Observation • The polygons can be painted correctly if for each polygon F: • Polygons on the other side of F from the viewer are painted before F • Polygons on the same side of F as the viewer are painted after F

  34. Building a BSP Tree Typedef struct { polygon root; BSP_tree *backChild, *frontChild; } BSP_tree; BSP_tree *makeBSP(polygon *list) { if( list = NULL) return NULL; Choose polygon F from list; Split all polygons in list according to F; BSP_tree* node = new BSP_tree; node->root = F; node->backChild = makeBSP( polygons on front side of F ); node->frontChild = makeBSP( polygons on back side of F ); return node; }

  35. 5 5a 2 5b 3 1 4 Building a BSP Tree (2D) 3 4 5b 1 2 5a

  36. 3 5 5a back front 2 5b 2 3 4 5b front back 1 4 5a 1 Building a BSP Tree (2D)

  37. 3 5 5a back front 2 5b 2 4 3 front back back 1 4 5a 5b 1 Building a BSP Tree (2D)

  38. Displaying a BSP Tree void displayBSP ( BSP_tree *T ) { if ( T != NULL) { if ( viewer is in front of T->root ) { // display backChild first displayBSP ( T->backChild ); displayPolygon ( T->root ); displayBSP ( T->frontChild ); } else { // display frontChild first displayBSP ( T->frontChild ); displayPolygon ( T->root ); displayBSP ( T->backChild ); } }

  39. 3 5 5a back front 2 5b 2 4 3 front back back 1 4 5a 5b 1 Displaying a BSP Tree Display order: 4, 5b, 3, 5a, 2, 1 (only 3 is front facing)

  40. BSP Trees: Analysis • Advantages • Efficient • View-independent • Easy transparency and antialiasing • Disadvantages • Tree is hard to balance • Not efficient for small polygons

More Related