Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 381 – Advanced Game Programming Quickhull and GJK.

Similar presentations


Presentation on theme: "CSE 381 – Advanced Game Programming Quickhull and GJK."— Presentation transcript:

1 CSE 381 – Advanced Game Programming Quickhull and GJK

2 What is collision detection? Determining if, when, & where two objects intersect What objects? Linear components, planes, triangles, rectangles, oriented boxes, spheres, capsules, lozenges, cylinders, ellipsoids, etc. Hugely important part of a 3D game engine. Why? done continuously every frame involves huge amounts of computations Entire textbooks are written on this subject alone Real-Time Collision Detection by Christer Ericson Collision Detection in Interactive 3D Environments by Gino van den Bergen

3 Collision Detection & Graphics Work together in a game engine Should be developed together Both share: geometric data timing elements So, pool resources for their algorithms e.g., scene graphs, spatial partitioning (octrees, bsps…)

4 Game Engine Collision Detection 2 phases Broad phase: determine which pairs of shapes need to be tested for collision Narrow phase: determine collision results for each pair identified in broad phase All game objects maintain collision sets data for collisions calculations i.e., bounding volumes

5 Types of Collisions Object versus plane (navigation or culling) Object versus object (general collision) Linear component versus object (picking)

6 Imagine a complex world Hundreds of interior structures, each with rooms Complex external terrain environment Water with underwater structures (interiors) Rather than testing these items serially, we can do so hierarchically much faster continuously reduce the problem

7 How should collision data be organized? One of the most important questions in designing a collision system Game world might contain a large number of interacting objects an exhaustive comparison is too exhaustive Objects should be organized into collision groups e.g., rooms, partitions, etc.

8 Rooms as collision groups Scene graphs & collision sets are not static, they change with the game as players, NPCs, or other game objects move/change When a player enters a room, the scene graph is reconfigured player is now part of room collision group Only objects moving within a room are tested against one another for collisions

9 Collision Detection Game Physics This is a huge topic Game physics is rapidly changing

10 Collision Detection & Response Collision Detection detecting what game objects are colliding with each other Collision Response providing a programmed response to collisions that fits with the game’s design & custom laws of physics

11 Static vs. Dynamic Objects Static objects never move Dynamic objects move Collisions may be between: Static objects & dynamic objects (fast & easy) Dynamic objects & dynamic objects (harder)

12 What types of collisions might we care about? Main character and static objects: terrain, floor, tiles, walls, furniture, buildings, game objects (i.e. power-ups, ammo), etc. Main character & dynamic objects: enemies, projectiles (i.e. bullets, arrows, etc.), particles (expensive), etc. Other dynamic objects and: other static objects other dynamic objects

13 Collisions in Pairs In collision detection, we always compare pairs of objects. Easier to: understand design & implement solutions A naïve approach: one pair at a time, compare all game objects in a game world against all other game objects in a game world

14 Collision Detection Calculations What data are we looking for? 1.Do these two objects potentially collide? 2.Do these two objects collide? 3.When did these two objects collide? 4.Where did these two objects collide? where on geometry of objects, points of impact These 4 questions get progressively: more computationally expensive to implement more complex to implement (more math)

15 Phases of Collision Detection Spatial Partitioning Algorithms problem reduction only perform additional phases on pairs of object on same “islands” Broad Phase – early rejection tests Do the coarse Bounding Volumes of two objects collide? Narrow Phase What are the contact points on object geometries? Done down to the last triangle in 3D games

16 Bounding Volumes The base geometry used for all collision tests instead of the shape’s geometry, which is too expensive Properties of desirable BVs: inexpensive intersection tests tight fitting inexpensive to compute easy to rotate and transform use little memory Ref: [1]

17 Assumptions you might make All collideable game objects: have rectangular Bounding Volumes don’t rotate, or if they do rotate, we don’t care about them colliding with stuff Thus: no polytope collision detection equations no rotation equations this makes life much easier (no narrow phase)

18 Common Bounding Volumes Note that the space craft has been rotated Ref: [1], Figure 4.2 This semester, we like AABBs and/or Spheres axis-aligned bounding boxes

19 Spatial Partitioning First, reduce the problem only perform additional phases on pairs of object on same “islands” Common Solutions: Octree Algorithms (quadtrees for 2D) also: Portals (ala Quake), BSP trees (Binary Space Partitions), Spatial Hashing, etc.

20 Octrees Used to divide a 3D world into “islands” 2D divided via Quadtrees Why? to make rendering more efficient to make collision detection more efficient What would be the data for these nodes? region coordinates for cell though a smart implementation might eliminate this too AABBs

21 Octree Source: http://en.wikipedia.org/wiki/Image:Octree2.pnghttp://en.wikipedia.org/wiki/Image:Octree2.png

22 Octree Drawbacks Objects cross islands octree has to be constantly updated not so bad Objects straddle islands collision detection may involve objects from multiple islands can be a headache

23 Broad Phase Do the coarse AABBs of two objects collide? Common solution: separating axis algorithms including temporal coherence For efficiencies use: Sweep & Prune an extension of separating axis, more efficient for many elements

24 Narrow Phase What are the contact points on object geometries? for 3D might be convex hulls Two Steps 1.determine potentially colliding primitives (ex: triangles) of a pair of objects AABB tree algorithms 2.determine contact between primitives GJK algorithms Ref[3]

25 What’s a convex set? What does convex mean? Convex Test: –For all the shape’s vertices: Make a line between each pair Is entire line inside object? –If yes, it is convex –If no, it is not (i.e., has dent)

26 Convex Set vs. Hull Convex Set –a set of points representing a convex shape Convex Hull –a minimal convex set –minimally snugly fits points (rubber band analogy)

27 Quickhull Algorithm for making a convex hull from a points set 1)Find min and max points on all axes to form minimal bounding box 2)Min/Max points represent first approximation 3)Exclude all points within the hull 4)For each line in approximation, find point furthest outside polytope 5)Add those points to hull in between the points that formed the line 6)If any points remain to consider, go back to step 3

28 GJK Gilbert – Johnson – Keerthi distance algorithm Used to determine the minimum distance between convex sets Why? –to see if they are colliding –to see where they are colliding

29 Minkowski Sum What’s that? –A mathematical operation performed on 2 shapes A B = All Points in A + All Points in B How many points do we end up with? –A * B

30 Visualizing Minkowski Sums Results in swept shapes A B A B

31 Minkowski Difference The Opposite of a Minkowski Sum A B = All Points in A – All Points in B How many points do we end up with? –A * B

32 Visualizing Minkowski Differences Results in swept shapes A B A B

33 An Interesting Detail For Minkowski Difference A B If A and B are intersecting, A B contains origin A B A B

34 Now Let’s Get Back To GJK Assume we have two shapes, A & B We want to know if A & B intersect

35 GJK for A & B Collision Test 1.Calculate Minkowski Difference 2.Select any Minkowski Difference point 3.Start at that point, and try to get to origin by visiting other points. –remember, this is a convex set 4.Build polytope using 4 points –iteratively update to find next one 5.If any polytope along way contains origin, no collision 6.If polytope never contains origin, no collision

36 Visualizing GJK Miss (no collision) Note: I’ve simplified things a bit for rendering

37 Visualizing GJK Hit (collision)


Download ppt "CSE 381 – Advanced Game Programming Quickhull and GJK."

Similar presentations


Ads by Google