-
Is there a collision between A and B?
-
Where was the collision?
-
When was the collision? (or will be?)
-
Computational cost
-
Which objects can collide with each other?
-
How many collision tests do we need to do?
-
How expensive are collision tests?
-
-
Collisions between objects of arbitrarily complex geometry is expensive
-
use simpler geometry for objects
-
at least until we know we need something better
-
i.e. cheat, at least some of the time
-
|
Important
|
Make you program work first. Then make if fast |
|
Tip
|
Ideally, we’d profile our code to see which parts use lots of time and use that for guidance. Your IDE may be able to help you with this. |
-
Point
-
Line / Plane
-
Circle / Sphere
-
Rectangle / Cuboid (AKA: Boxes)
-
Axis-Aligned
-
non-Axis-Aligned
-
-
Triangle / ???
-
Convex Polygon / Convex Polyhedron
-
Concave Polygon / Concave Polyhedron
-
Circle-Circle / Sphere-Sphere
-
Circle-Line / Sphere-Plane
-
Axis-Aligned-Box vs Axis-Aligned-Box
-
non-Axis-Aligned vs non-Axis-Aligned
-
Convex polygon / Convex polyhedron
-
Concave polygon / Concave polyhedron
| Point | Line | Circle | AAB | Box | Convex | Concave | |
|---|---|---|---|---|---|---|---|
Point |
??? |
- |
- |
- |
- |
- |
- |
Line |
??? |
??? |
- |
- |
- |
- |
- |
Circle |
??? |
??? |
??? |
- |
- |
- |
- |
AAB |
??? |
??? |
??? |
??? |
- |
- |
- |
Box |
??? |
??? |
??? |
??? |
??? |
- |
- |
Convex |
??? |
??? |
??? |
??? |
??? |
??? |
- |
Concave |
??? |
??? |
??? |
??? |
??? |
??? |
??? |
| Point | Line | Circle | AAB | Box | Convex | Concave | |
|---|---|---|---|---|---|---|---|
Point |
:-) |
- |
- |
- |
- |
- |
- |
Line |
:-) |
:-) |
- |
- |
- |
- |
- |
Circle |
:-) |
:-) |
:-) |
- |
- |
- |
- |
AAB |
:-) |
:-) |
:-) |
:-) |
- |
- |
- |
Box |
OK |
OK |
:-( |
OK |
OK |
- |
- |
Convex |
OK |
OK |
:-( |
:-( |
:-( |
:-( |
- |
Concave |
:-( |
:-( |
HARD |
HARD |
HARD |
HARD |
HARD |
-
For each box, for each axis, have a minimum and a maximum value
-
AKA an interval
-
-
non-collision on ANY axis ⇒ non-collision
-
test for each axis (X, Y, Z):
-
???
-
-
What to do when we find a Collision
-
Various options, including:
-
calculate next positions, for collisions apply forces
-
calculate next positions, for collisions change velocities
-
physically (real-world) unrealistic
-
-
calculate next positions, for collisions change positions
-
very physically (real-world) unrealistic
-
-
store present position, calculate next positions, for collisions revert to stored
-
|
Warning
|
SDL’s draw functions (e.g. SDL_RenderCopy, SDL_RenderFillRect) work in Window Coordinates
|
|
Tip
|
You DON’T want to. You WANT to work in something independent of the resolution, and less discrete. i.e. some floating point system. |
|
Tip
|
You’ll need (WANT) to convert from your coordinate system to Window coordinates (remember linear transformations and matrices …). |
|
Tip
|
You can choose where your origin is. Where makes most sense to you? |
|
Tip
|
You can choose which way is positive - e.g. does the y-value increase as you go DOWN the Window, or increase as you go UP the window |
-
SDL’s draw functions use a position (top-left) and a height and width
-
these may not be the most useful/natural for us
-
-
We may want to make our sprite interface talk about sprite centers, and translate that when we draw
|
Tip
|
Collision detection can be difficult to debug. Have a mode where you render the collision bounds can be really helpful. |
-
http://headerphile.blogspot.co.uk/2014/04/part-5-game-programming-in-sdl2.html
-
http://lazyfoo.net/tutorials/SDL/27_collision_detection/index.php
-
http://www.miguelcasillas.com/?mcportfolio=collision-detection-c
-
http://www.euclideanspace.com/threed/animation/collisiondetect/
-
http://www.euclideanspace.com/physics/dynamics/collision/index.htm
-
https://studiofreya.com/3d-math-and-physics/simple-aabb-vs-aabb-collision-detection/
-
https://www.toptal.com/game/video-game-physics-part-i-an-introduction-to-rigid-body-dynamics
-
https://www.toptal.com/game/video-game-physics-part-ii-collision-detection-for-solid-objects
-
https://www.toptal.com/game/video-game-physics-part-iii-constrained-rigid-body-simulation
-
http://www.gamasutra.com/view/feature/131598/advanced_collision_detection_.php
-
http://www.randygaul.net/2013/03/27/game-physics-engine-part-1-impulse-resolution/



