Saturday, May 27, 2017

c++ - SAT, How Do I Find The Penetration Vector?


I've just successfully implemented Separating Axis Theorem (SAT) in my game but I was wondering how do I find the penetration vector? I heard it can be useful for collision response. e.g. The harder they collide the harder the response.


I want the penetration vector so I apply it to the position of an object when it is current penetrating an other so I can move it back outside of the other object's bounds.


Here is my code so far.


Any help would be much appreciated,



Thanks in advance.



Answer



The classic way to do this is the GJK algorithm. It's a fairly complicated algorithm with a lot of moving parts, so might be tricky to implement. However, there are many implementations out there on the Web that you might be able to adapt.


A simpler way to get an approximate penetration vector might be to leverage the SAT itself; when you iterate over all the possible separating axes and check for overlap on each, keep track of which axis has the shortest overlap and use that as the penetration vector.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...