Collision detection against curves or other complex shapes and bitmaps.

Started by
2 comments, last by wodinoneeye 9 years, 6 months ago

Ok so I am new in game development and for simple games bounding box collision is fine. However, let's say you have a shape or bitmap like this:

QkpjT.jpg

Now this is just an example but if you had more elaborate curves or even a whole shape which was more complex than a simple polygon or rectangle-like shape, how would you do precise collision detection? And I am strictly speaking in 2D here. I just want to know the concept behind how you would do this. Thanks!

Advertisement

You would either represent it as a collection of simple collision primitives (circles, boxes etc.) that are scaled and rotated to approximate it well, or you would approximate it as an arbitrary polygon (which the physics engine could triangulate or just do physics based on the polygon edges or whatever works the best)

Check some 2D physics engine and see what features it has.

o3o

Here's a great article about per-pixel collision detection: http://lazyfoo.net/SDL_tutorials/lesson18/

And a quad-tree implementation for speeding it up: http://gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374

There is a thing called 'lazy evaluation' where for the bulk of the collision interactions you use a fairly crude evaluation method (like AABB axis aligned bounding boxes) to validly eliminate most (hopefully vast majority) of the candidates for the collision test, leaving the remainder to be subjected to the much more processing -intense (but accurate) methods.

Eample is a human figure object maintaining a AABB box that encompases every extremity and then being used to filter out obvious misses of projectiles, but then if passed proceding to a more accurate piece by piece (figure mesh) testing can then be done to be fully accurate (or as accurate as needed for the games mechanics). Thus eliminating alot of unncecessary and game performance sapping processing.

--------------------------------------------[size="1"]Ratings are Opinion, not Fact

This topic is closed to new replies.

Advertisement