Jump to content
  • Advertisement
Sign in to follow this  
daniel_i_l

storing collision information

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!