Use J3ML triangle v triangle collision
This commit is contained in:
@@ -86,9 +86,11 @@ namespace {
|
||||
}
|
||||
|
||||
bool operator()(const CollisionMap& lhs, const AABB& rhs) const {
|
||||
for (const auto& triangle : lhs.getTriangles())
|
||||
if (false /* rhs.Intersects(triangle) */)
|
||||
/*for (const auto& triangle : lhs.getTriangles()) {
|
||||
if (rhs.Intersects(triangle)) {
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -106,65 +108,20 @@ namespace {
|
||||
}
|
||||
|
||||
bool operator()(const CollisionMap& lhs, const CollisionMap& rhs) const {
|
||||
// Not yet implemented
|
||||
auto lTriangles = lhs.getTriangles();
|
||||
auto rTriangles = rhs.getTriangles();
|
||||
|
||||
for (const auto& lTriangle : lTriangles) {
|
||||
for (const auto& rTriangle : rTriangles) {
|
||||
if (lTriangle.Intersects(rTriangle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
bool orientedBoundingBoxCollides(const OrientedBoundingBox &lhs, const OrientedBoundingBox &rhs) {
|
||||
Vector3 axes[3] = {
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(0, 1, 0),
|
||||
Vector3(0, 0, 1)
|
||||
};
|
||||
|
||||
for (const auto& axis : axes) {
|
||||
float projection1Min = FLT_MAX, projection1Max = -FLT_MAX;
|
||||
float projection2Min = FLT_MAX, projection2Max = -FLT_MAX;
|
||||
|
||||
for (const auto& vertex : lhs.vertexArray.vertices) {
|
||||
Vector3 vert = {vertex.x, vertex.y, vertex.z};
|
||||
float projection = vert.Dot(axis);
|
||||
if (projection < projection1Min) projection1Min = projection;
|
||||
if (projection > projection1Max) projection1Max = projection;
|
||||
}
|
||||
|
||||
for (const auto& vertex : rhs.vertexArray.vertices) {
|
||||
Vector3 vert = {vertex.x, vertex.y, vertex.z};
|
||||
float projection = vert.Dot(axis);
|
||||
if (projection < projection2Min) projection2Min = projection;
|
||||
if (projection > projection2Max) projection2Max = projection;
|
||||
}
|
||||
|
||||
if (projection1Max < projection2Min || projection2Max < projection1Min)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& axis : axes) {
|
||||
float projection1Min = FLT_MAX, projection1Max = -FLT_MAX;
|
||||
float projection2Min = FLT_MAX, projection2Max = -FLT_MAX;
|
||||
|
||||
for (const auto& vertex : lhs.vertexArray.vertices) {
|
||||
Vector3 vert = {vertex.x, vertex.y, vertex.z};
|
||||
float projection = vert.Dot(axis);
|
||||
if (projection < projection1Min) projection1Min = projection;
|
||||
if (projection > projection1Max) projection1Max = projection;
|
||||
}
|
||||
|
||||
for (const auto& vertex : rhs.vertexArray.vertices) {
|
||||
Vector3 vert = {vertex.x, vertex.y, vertex.z};
|
||||
float projection = vert.Dot(axis);
|
||||
if (projection < projection2Min) projection2Min = projection;
|
||||
if (projection > projection2Max) projection2Max = projection;
|
||||
}
|
||||
|
||||
if (projection1Max < projection2Min || projection2Max < projection1Min)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true; //OBBs collide.
|
||||
}
|
||||
|
||||
struct ContainsVisitor {
|
||||
Vector3 position;
|
||||
|
||||
|
Reference in New Issue
Block a user