storing collision information

Started by
3 comments, last by Vorpy 17 years, 2 months ago
I have a collision detection system that uses SAT and am in the proccess of optimizing it. one thing that i've read about is storing the seperating axis for each pair of bodies and then checking it first when applying the SAT to those two bodies. my question is, how should i store these axes? should i make a giant array? hash table - if so what hash function? are there better options? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Advertisement
I think any method of representing a symmetric matrix would work. For a dense representation, this would require only half as much memory as storing an entire matrix. A hash table would correspond to a sparse representation, which would have higher overhead but only use memory for pairs of objects for which you are storing the witness information.

I think something nice about this problem is that when an object is removed from the world you can reuse the id you were using to look up the witness information without having to clean up the old information since choosing a poor witness won't affect the correctness of the algorithm. If you have n objects, the amount of witness information for collision checking between them is clearly O(n^2), so if you have a huge amount of objects it could be worth it to use a sparse representation and clean up old information to save space. Otherwise I don't see anything wrong with using the dense representation (an array/triangular matrix). If you have a maximum of n objects, you'd need space for n(n-1)/2 witnesses. For 1000 objects, with each witness using a byte of space (probably more than enough), that's still less than half a megabyte.
Thanks. I was wondering though, if i'm using a spatial partitioning technique which means that each object is only checked against a few other objects, would it be better for each object (or atleast one of the pair of colliding objects) to store the axis?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
1) use a global hash table based on object ID to store the SAs tests.
2) Store the SA for each object in a small array/list/hash table (allocated once, 8 should do).

2) is simpler, and probably slightly less messy, since you don't need to worry about objects moving away from each other (meaning, removing SAs tests from the hash table) or when objects gets destroyed. If you use a timestamp, you can discard the oldest SAs when necessary, so the slot gets re-used with a newer test. If the objects get destroyed, it wont matter that much, and the slot will get re-used.

my 2 cents.

Everything is better with Metal.

How about a global hash table used as a cache? An LRU (least recently used) cache can be built from a combination of a hash table and a linked list. Each hash table entry is also a linked list node. Whenever an entry is accessed it is reinserted at the front of the list. The hash table can be given a maximum size, and once this size is reached, adding new entries causes the entries at the back of the list to be deleted (reusing the node for the new entry).

The global cache would use space more efficiently and flexibly, but if it wasn't big enough then thrashing could occur making it a complete waste. Thrashing could be detected by using timestamps or a marker node or something and fixed by resizing the cache.

This topic is closed to new replies.

Advertisement