Jump to content
  • Advertisement
Sign in to follow this  
Bombshell93

Collision SAT - testing an axis

This topic is 2498 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

okay for the life of me whenever I get into collision this always hits me in the face,
I've tried to understand, I've read masses of papers, hints and explanations, but never found a clear implementation.

To my understanding of separating axis theorem, you find axes running along the edge of each object.
You test against each axis until its confirmed the objects are not touching, if you can not confirm the objects are not touching after testing every axis then the objects must be touching.

The bit which gets me is how do I test against an axis, I've not been able to find much elaboration on this.
Does anyone have a basic example or a link to a well commented implementation?

Any and all help appreciated,
Thanks in advanced,
Bombshell

EDIT: Sorry, I accidentally posted this in graphics programming, only just noticed -.-''
EDIT: if possible could someone lock or remove this thread, its fairly pointless in the wrong topic, I've made an appropriate updated thread in the Game Programming forum.

Share this post


Link to post
Share on other sites
Advertisement
The "axes" are actually perpendicular to the sides of the objects. You then project the objects onto the subspace defined by that axis (by calculating dot products). If they don't intersect in the subspace then they can't intersect in the original space either.

Share this post


Link to post
Share on other sites
Okay I've given it a shot, a shot in the dark I've no clue if I'm doing it right or if I'm being a moron.

This is a collision test for a simple "is touching" or "isn't touching" response inside of an AABB, testing against a triangle in Java.
public boolean isColliding(Triangle i)
{
double axisX, axisY, temp, minB, minT, maxB, maxT;

axisX = -(i.y1 - i.y2); axisY = i.x1 - i.x2; //get axis
temp = Math.sqrt((axisX * axisX) + (axisY * axisY)); //length of "axis"
axisX /= temp; axisY /= temp; //normalize axis

//Box
temp = (axisX * x) + (axisY * y); //Dot product of top-left
minB = maxB = temp;
temp = (axisX * x) + (axisY * (y + h)); //bottom-left
if (temp > maxB) { maxB = temp; }
else if (temp < minB) { minB = temp; }
temp = (axisX * (x + w)) + (axisY * (y + h)); //bottom-right
if (temp > maxB) { maxB = temp; }
else if (temp < minB) { minB = temp; }
temp = (axisX * (x + w)) + (axisY * y); //top-right
if (temp > maxB) { maxB = temp; }
else if (temp < minB) { minB = temp; }

//Triangle
temp = (axisX * i.x1) + (axisY * i.y1); //Dot product of vert 1
minT = maxT = temp;
temp = (axisX * i.x2) + (axisY * i.y2); //vert 2
if (temp > maxT) { maxT = temp; }
else if (temp < minT) { minT = temp; }
temp = (axisX * i.x3) + (axisY * i.y3); //vert 3
if (temp > maxT) { maxT = temp; }
else if (temp < minT) { minT = temp; }

if (maxB < minT || minB > maxT) { return false; }

// Test other axes //

return true;
}


is this right?
I'd have created a vector2 class but I despise using functions for addition and subtraction and etc. sadly java has no operator overloading to my knowledge. So everything is fairly raw.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!