From a30b6d60595d2b655f2d02e5f934026924cc7b76 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Wed, 13 Oct 2021 00:25:28 +0700 Subject: [PATCH] Remove redundant iterations counter in GJK & EPA --- engine/Consts.h | 1 - engine/physics/RigidBody.cpp | 13 ++----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/engine/Consts.h b/engine/Consts.h index 2415018..5714dc1 100644 --- a/engine/Consts.h +++ b/engine/Consts.h @@ -9,7 +9,6 @@ namespace Consts { const double PI = 3.14159265358979323846264338327950288; const double EPS = 0.000001; - const int GJK_MAX_ITERATIONS = 50; const double EPA_EPS = 0.0001; const double RAY_CAST_MAX_DISTANCE = 10000; diff --git a/engine/physics/RigidBody.cpp b/engine/physics/RigidBody.cpp index 4bb3351..a7b0664 100644 --- a/engine/physics/RigidBody.cpp +++ b/engine/physics/RigidBody.cpp @@ -144,9 +144,7 @@ std::pair RigidBody::checkGJKCollision(std::shared_ptr // New direction is towards the origin std::unique_ptr direction = std::make_unique(-*support); - int iterations = 0; - - while (iterations < Consts::GJK_MAX_ITERATIONS) { + while (true) { support = std::make_unique(_support(obj, *direction)); if (support->dot(*direction) <= 0) @@ -164,11 +162,7 @@ std::pair RigidBody::checkGJKCollision(std::shared_ptr _inCollision = true; return std::make_pair(true, *points); } - - iterations++; } - - return std::make_pair(false, *points); // no collision } CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr obj) { @@ -187,9 +181,7 @@ CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr std::shared_ptr minNormal{}; double minDistance = std::numeric_limits::max(); - int iterations = 0; - - while ((minDistance == std::numeric_limits::max()) && (iterations < Consts::GJK_MAX_ITERATIONS)) { + while (minDistance == std::numeric_limits::max()) { minNormal = std::make_shared(normals[minFace]->normal); minDistance = normals[minFace]->distance; @@ -244,7 +236,6 @@ CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr faces .insert(faces .end(), newFaces .begin(), newFaces .end()); normals.insert(normals.end(), newNormals.begin(), newNormals.end()); } - iterations++; } _collisionNormal = minNormal;