Calculating axes for separating axes theorem

Started by
0 comments, last by jakob_tadej8 5 months ago

Hello! I am trying to implement SAT to detect collisions but can't quite figure out which axes to check. I currently have an array with all the vertices and a for loop which goes up to 6 in increments of 2(so 0, 2, 4) since I only have cuboids as colliders. Currently I am checking the following axes:

curr = vertices[i];
edges[0] = other->vertices[(i + 1)] - curr;
edges[1] = other->vertices[(i + 2)] - curr;		
curr = other->vertices[i];
edges[0] = other->vertices[(i + 1)] - curr;
edges[1] = other->vertices[(i + 2)] - curr;

Now I know I need to also use cross products of edges of the 2 colliders and I have tried (note that j is another iterator that has the same conditions and is inside the first loop)

axis = glm::normalize(glm::cross(glm::normalize(vertices[(i + 1)] - vertices[i]),
glm::normalize(other->vertices[(j + 2)] - other->vertices[j])));
axis = glm::normalize(glm::cross(glm::normalize(vertices[(i + 2)] - vertices[i]),
glm::normalize(other->vertices[(j + 1)] - other->vertices[j])));

Now the checks above don't seem to do it as the colliders then extend infinitely along the Z axis. I have also tried something like this:

axis = glm::normalize(glm::cross(glm::normalize(vertices[(i + 1)] - vertices[i]),
glm::normalize(other->vertices[(j + 1)] - other->vertices[j])));

but that check always fails and a collision is never detected.

So my question is what am I doing wrong and which axes do I need to check for proper collision detection? Thanks in advance!

This topic is closed to new replies.

Advertisement