Remove redundant iterations counter in GJK & EPA

master
Vectozavr 2021-10-13 00:25:28 +07:00
parent 41fa09887a
commit a30b6d6059
2 changed files with 2 additions and 12 deletions

View File

@ -9,7 +9,6 @@ namespace Consts {
const double PI = 3.14159265358979323846264338327950288; const double PI = 3.14159265358979323846264338327950288;
const double EPS = 0.000001; const double EPS = 0.000001;
const int GJK_MAX_ITERATIONS = 50;
const double EPA_EPS = 0.0001; const double EPA_EPS = 0.0001;
const double RAY_CAST_MAX_DISTANCE = 10000; const double RAY_CAST_MAX_DISTANCE = 10000;

View File

@ -144,9 +144,7 @@ std::pair<bool, Simplex> RigidBody::checkGJKCollision(std::shared_ptr<RigidBody>
// New direction is towards the origin // New direction is towards the origin
std::unique_ptr<Vec3D> direction = std::make_unique<Vec3D>(-*support); std::unique_ptr<Vec3D> direction = std::make_unique<Vec3D>(-*support);
int iterations = 0; while (true) {
while (iterations < Consts::GJK_MAX_ITERATIONS) {
support = std::make_unique<Vec3D>(_support(obj, *direction)); support = std::make_unique<Vec3D>(_support(obj, *direction));
if (support->dot(*direction) <= 0) if (support->dot(*direction) <= 0)
@ -164,11 +162,7 @@ std::pair<bool, Simplex> RigidBody::checkGJKCollision(std::shared_ptr<RigidBody>
_inCollision = true; _inCollision = true;
return std::make_pair(true, *points); return std::make_pair(true, *points);
} }
iterations++;
} }
return std::make_pair(false, *points); // no collision
} }
CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr<RigidBody> obj) { CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr<RigidBody> obj) {
@ -187,9 +181,7 @@ CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr<RigidBody>
std::shared_ptr<Vec3D> minNormal{}; std::shared_ptr<Vec3D> minNormal{};
double minDistance = std::numeric_limits<double>::max(); double minDistance = std::numeric_limits<double>::max();
int iterations = 0; while (minDistance == std::numeric_limits<double>::max()) {
while ((minDistance == std::numeric_limits<double>::max()) && (iterations < Consts::GJK_MAX_ITERATIONS)) {
minNormal = std::make_shared<Vec3D>(normals[minFace]->normal); minNormal = std::make_shared<Vec3D>(normals[minFace]->normal);
minDistance = normals[minFace]->distance; minDistance = normals[minFace]->distance;
@ -244,7 +236,6 @@ CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr<RigidBody>
faces .insert(faces .end(), newFaces .begin(), newFaces .end()); faces .insert(faces .end(), newFaces .begin(), newFaces .end());
normals.insert(normals.end(), newNormals.begin(), newNormals.end()); normals.insert(normals.end(), newNormals.begin(), newNormals.end());
} }
iterations++;
} }
_collisionNormal = minNormal; _collisionNormal = minNormal;