![]() |
| | #1 |
| Registered User Join Date: Mar 2008
Posts: 11
| questions about arrays basic collision detection I've got this idea to hand code the bounding boxes for solid objects into arrays, and use a for loop to check for collisions; something like this: Code: int object_max_x[A_BAJILLION]
int object_max_y[A_BAJILLION]
int object_min_x[A_BAJILLION]
int object_min_y[A_BAJILLION]
// a bajillion being a #define for the number of solid objects in a given map.
int character_max_x
int character_max_y
int character_min_x
int character_min_y
int collision_detection()
{
for (a=0; a<A_BAJILLION; a++)
{
if (character_max_x>object_min_x[a]
return 1;
if (character_max_y>object_min_y[a]
return 1;
if (character_min_x<object_max_x[a]
return 1;
if (character_min_y<object_max_x[a]
return 1;
}
return 0:
}
|
| The_Hermit is offline | |
| | #2 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| http://en.wikipedia.org/wiki/Quad_tree Assuming that your objects don't hyperspace to random positions each time they move, then things which were close by on the last iteration are the ones most likely to collide on this iteration. Use this to your advantage when trying to figure out what to compare.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Mar 2008
Posts: 11
| Thanks, man. That makes sense. lol, god of the C |
| The_Hermit is offline | |
![]() |
| Tags |
| arrays, collision, detection, question |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problems with AABB Collision Detection. | Shamino | Game Programming | 10 | 03-30-2009 07:00 PM |
| Collision Detection | Grantyt3 | C++ Programming | 3 | 09-30-2005 03:21 PM |
| Collision Detection | ahluka | Game Programming | 2 | 08-06-2005 12:14 PM |
| Questions on basic Quick Sort | Weng | C++ Programming | 4 | 12-16-2003 10:06 AM |
| Collision with quads? | SyntaxBubble | Game Programming | 6 | 01-18-2002 06:17 PM |