Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Collision Detection 2.0  (Read 4437 times)

0 Members and 1 Guest are viewing this topic.

GroundZero

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Collision Detection 2.0
« on: February 04, 2012, 01:07:25 pm »
Dear readers,

for several months I have been trying to get a pixel based collision detection working, but nothing is working out.

Is there any guide on the internet, tutorial or anything that I can download, that you know off it is working 100%?

I tried several things but none are working. Either 1000's of errors or just simply not working.

I am using SFML2.0 with QtSDK 4.7.4.

I want pixels based collision detection because when i would use a bounding box, it would look weird i.e. if a enemy shoots magic, you can get hit even when it is not a collision for example because the invisible bounding box around the sprite.


Hopefully someone can tell me how to make such kind of collision detection.

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
Collision Detection 2.0
« Reply #1 on: February 06, 2012, 05:29:42 pm »
Checking every pixel of a image can be an expensive operation. So programmers usually use a boolean bidimensional array to keep the information about the pixels.

Code: [Select]
bool **mask;

You would have to check every pixel and check its transparency, this way you can set pixel
  • [y] to 1 or 0. Then only you have to check the 2 images comparing the masks each other.


The generation of the matrix can be expensive so you should do it when starting or loading the game.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Collision Detection 2.0
« Reply #2 on: February 06, 2012, 07:10:17 pm »
I would use a one-dimensional array and map 2 dimensions to it. And I would prefer STL containers like std::vector<bool> to get rid of memory management, pointers to pointers and unsafe accesses. Although the latter is a little bit an unfortunate specialization with some "special" features...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Collision Detection 2.0
« Reply #3 on: February 06, 2012, 07:19:14 pm »
I wouldn't throw away the bounding box approach either.  Since collision detection is such a CPU intensive action it works well to use a mult-tier approach.  Check for a collision with the bounding boxes first; if it returns a hit then run the check for a pixel collision on those objects to see if they are actually intersecting.  This way you're not wasting processing time on checking for pixel perfect collisions when the objects aren't even near each other.

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
Collision Detection 2.0
« Reply #4 on: February 06, 2012, 09:31:43 pm »
Totally agree with the last 2 answers =)

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile

 

anything