Ok I'm totally lost with collision detection, I'm absolutely an idiot when it comes to it, if anyone knows anything about it or wants to see the code I'm trying to make work, let me know, I cannot figure out how to do collision detection.
Palad1 said:Are you working in 2D or 3D?
in 2d, a fairly simple solution used to detect collisions in the viewing area is to keep a second screen buffer where each pixel value is an index of the object.
So you have
1/ the screen buffer filled with rgb values
2/ the collision buffer filled with entities ID
Cheers,
Palad1
pdpfilms said:I must say, I'm very pleased MacRumors now has a specific Programming section. Because I have absolutely no idea what you're talking about.
slooksterPSV said:Ok I'm totally lost with collision detection, I'm absolutely an idiot when it comes to it, if anyone knows anything about it or wants to see the code I'm trying to make work, let me know, I cannot figure out how to do collision detection.
List of rectangles , cycle through the list of rectangles, if any rectangle is within/touching another, its collided... I did a primitive one using NSContainsRect() and NSIntersectsRect() and other simple rectangle methods. The more tricky part is "what to do when they do collide."slooksterPSV said:Since I don't have it figured out, I'm using C++ and SDL as the SDK/API. I was able to use source code from another person with their permission on how to detect collisions. But I still need to learn how to do it.
if ((player.x >= object.x) && (player.x <= object.x + object.w - 1))
{
...
if ( (player.y >= object.y) && (player.y <= object.y + object.h - 1) )
{
return true;
}
}
return false;
Here's A, B at time 0:
A B
time 1:
A B
time 2:
A B
time 3:
A B
time 4:
B A
Here's A, B at time 0:
A--| |--B
time 1:
A--| |--B
time 2:
A--| |--B
time 3:
A|-|B
time 4:
|--B A--|
slooksterPSV said:Ok I'm totally lost with collision detection, I'm absolutely an idiot when it comes to it, if anyone knows anything about it or wants to see the code I'm trying to make work, let me know, I cannot figure out how to do collision detection.
superbovine said:FYI: when you say collision detection in the computer science world, please specify what you are talking about because collision detection in networking is way different than graphics.
SDL_Surface* temp = NULL;
...
//blit the surface to an arbitrary bitmap (instead of the screen) and blit only what parts are defined as in the SDL_Rect.
MarkCollette said:A true collision happens when to objects share the same space at the same time. The calculations get more complex, the more dimensions you're modelling. Some suggestions here are effectively optimisations on that.
For the object buffer (each pixel point has a pointer to the object), if they are drawn on the same space they have collided. But take care, objects can collide without ever visually overlapping. Take for example two objects on the X axis, moving towards each other rapidly. Depending on how rapidly you render those objects, they may not be drawn while they overlap.
OMGosh, that helps sooooooo much, now I just need help with my scrolling - I made a new post for it and included my source in a 4.7MB file.Catfish_Man said:Everything you never wanted to know about implementing 2D collision detection and physics engines: http://www.harveycartel.org/metanet/tutorials.html
savar said:This is a very interesting post. Where have you implemented a physics model like this? In a game or some kind of scientific app?