PDA

View Full Version : Hash Table collision detection(Is that a pun?)


LongJumper
2003.05.04, 11:45 PM
You know, I don't know jack about collision detection. I've avoided it to the point where I acutally work on my computer science projects now(I have a B in CompsCi 367 now, thank you.)

Anyway, I've read a little on the situation, and I've come to some conclusions:
1. It sucks.
2. It's hard to do and it sucks.
3. It sucks.

The general idea I have behind it is that you must loop through all objects in an area each time you do collision detection. I might be wrong, I'm still going to talk though.

My idea to preventing this solution that may not exit is to create an object hash table, keyed on the coordinates of an object(x and z would be weighted more, since you usually don't fly as much as you walk, you know)

With this situation, you'd only check objects that are around you, and you wouldn't have to search which objects were you near you because you could just look up the search keys for coordinates close to you.

Now of course, there are alot of problems with this. Such as how far do you check? What if an object is in your range, but it's center is out of it? Anyway, it's just a thought. It'd be good to get some thoughts on this.

OneSadCookie
2003.05.05, 12:26 AM
The problem with a hashtable is that it's unsorted. You could look up the particular x & z you're interested in, but the objects that are spatially near that one wouldn't be near it in the hashtable.

It's quite common to sort objects spatially (eg along x) to improve collision performance, though, which seems like the solution you were trying to come to :)

David
2003.05.05, 12:32 AM
I would recommend a quadtree or octtree, just make the world into a grid and check which squares each object is in, and then check any objects in the same square.

LongJumper
2003.05.05, 01:58 AM
Originally posted by OneSadCookie
The problem with a hashtable is that it's unsorted. You could look up the particular x & z you're interested in, but the objects that are spatially near that one wouldn't be near it in the hashtable.

It's quite common to sort objects spatially (eg along x) to improve collision performance, though, which seems like the solution you were trying to come to :)

Well, with sorted bucket chaining, you could possibly eliminate that problem?