1 / 17

2D Collision Detection

2D Collision Detection. For CSE 3902 By: Matt Boggus. Outline. Collision tests Pixel-pixel Square-square Axis-aligned bounding box (rectangle) testing Collision detection loops Exhaustive comparison Static objects vs. dynamic objects. Collision Detection tests. Pixel-pixel test .

nay
Télécharger la présentation

2D Collision Detection

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. 2D Collision Detection For CSE 3902 By: Matt Boggus

  2. Outline • Collision tests • Pixel-pixel • Square-square • Axis-aligned bounding box (rectangle) testing • Collision detection loops • Exhaustive comparison • Static objects vs. dynamic objects

  3. Collision Detection tests

  4. Pixel-pixel test • Given sprite pixel data and position on screen, make a binary mask for each sprite • Detection test • (XOR == 1) • Not intersecting • (XOR == 0) AND (OR == 1) • Intersecting • Pro: Accurate • Con: Slow; requires working with image data Raster graphic sprites (left) and masks (right)

  5. Square-square test

  6. Square-square test

  7. Square-square top-bottom collision

  8. Square-square left-right collision

  9. Non-square collision example (values indicate top-bottom)

  10. Axis-aligned bounding box testing

  11. Axis-aligned bounding box testing

  12. XNA rectangle and methods • Given two rectangles rectangleA and rectangleB • Rectangle.Intersects(Rectangle) • Returns true if the rectangles are intersecting, otherwise false • Example call: rectangleA.Intersects(rectangleB); • Rectangle.Intersect Method (Rectangle, Rectangle) • Returns the area where the two rectangles overlap, anempty rectangle if there is no overlap • Example call: Rectangle.Intersect(rectangleA,rectangleB);

  13. Rectangle Intersect left-right

  14. Rectangle Intersect top-bottom

  15. Types of Collision loops

  16. Exhaustive comparison • Given mario, enemyList (length n), and blockList (length m), test • mario vs. enemyList[0] through [n-1] • mario vs. blockList[0] through [m-1] • enemyList[0] vs. enemyList[1] through [n-1] • enemyList[1] vs. enemyList[2] through [n-1] • … • blockList[0] vs. blockList[1] through [m-1] ?

  17. Static vs. Dynamic • Non-moving, or static, objects only need to be compared against dynamics, not other static objects • foreach static object, test against all dynamic objects • foreachdyamic object, test against all other dynamic objects, taking care not to duplicate tests

More Related