# storing collision information

This topic is 4373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634046
• Total Posts
3015224
×