Hello everyone! I’m trying to learn SAT, and I almost have everything figured out. The biggest struggle for me what to understand projection. I’m noticing my collision between two rectangles works fine, but once I rotate, on certain angles it isn’t checking min and max properly as you can see a gap in the image, but it still shows collision.
I’ve pasted my code, it’s not much. I cannot seem to fiquire out why it’s not projecting properly. My dot formula and project should be correct, unless I’m something is wrong with the rects updating.
I’m using two SFML Rectangles, and when they move or rotate I have to call getTransform().transformPoint(rectB.getPoint(1)) (points are zero based, so this would be top right), and the points are correct when I debug. Also, I use width / 2, because the origin is in the center of the rect.
Any idea what I’m doing wrong here?
Based on the images showing red when they’re so far apart *red means collision = true*
I’m assuming my projection is wrong because the min and max for both rects would have a gap.
// Get Faces
axesEdge[0] = sf::Vector2f(rectA.getTransform().transformPoint(rectA.getPoint(1)).x + rectA.getLocalBounds().width / 2 - rectA.getTransform().transformPoint(rectA.getPoint(0)).x + rectA.getLocalBounds().width / 2,
rectA.getTransform().transformPoint(rectA.getPoint(1)).y + rectA.getLocalBounds().height / 2 - rectA.getTransform().transformPoint(rectA.getPoint(0)).y + rectA.getLocalBounds().height / 2);
axesEdge[1] = sf::Vector2f(rectA.getTransform().transformPoint(rectA.getPoint(1)).x + rectA.getLocalBounds().width / 2 - rectA.getTransform().transformPoint(rectA.getPoint(2)).x + rectA.getLocalBounds().width / 2,
rectA.getTransform().transformPoint(rectA.getPoint(1)).y + rectA.getLocalBounds().height / 2 - rectA.getTransform().transformPoint(rectA.getPoint(2)).y + rectA.getLocalBounds().height / 2);
axesEdge[2] = sf::Vector2f(rectB.getTransform().transformPoint(rectB.getPoint(0)).x + rectB.getLocalBounds().width / 2 - rectB.getTransform().transformPoint(rectB.getPoint(3)).x + rectB.getLocalBounds().width / 2,
rectB.getTransform().transformPoint(rectB.getPoint(0)).y + rectB.getLocalBounds().height / 2 - rectB.getTransform().transformPoint(rectB.getPoint(3)).y + rectB.getLocalBounds().height / 2);
axesEdge[3] = sf::Vector2f(rectB.getTransform().transformPoint(rectB.getPoint(0)).x + rectB.getLocalBounds().width / 2 - rectB.getTransform().transformPoint(rectB.getPoint(1)).x + rectB.getLocalBounds().width / 2,
rectB.getTransform().transformPoint(rectB.getPoint(0)).y + rectB.getLocalBounds().height / 2 - rectB.getTransform().transformPoint(rectB.getPoint(1)).y + rectB.getLocalBounds().height / 2);