From e232435246c1b25ea848e964abedd9df9ea4a249 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Sun, 17 Oct 2021 23:53:30 +0700 Subject: [PATCH] Code refactoring. --- engine/physics/RigidBody.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/engine/physics/RigidBody.cpp b/engine/physics/RigidBody.cpp index 9954ddf..2678073 100644 --- a/engine/physics/RigidBody.cpp +++ b/engine/physics/RigidBody.cpp @@ -136,6 +136,13 @@ NextSimplex RigidBody::_tetrahedronCase(const Simplex &points) { } std::pair RigidBody::checkGJKCollision(std::shared_ptr obj) { + // This is implementation of GJK algorithm for collision detection. + // It builds a simplex (a simplest shape that can select point in space) around + // zero for Minkowski Difference. Collision happend when zero point is inside. + // See references: + // https://www.youtube.com/watch?v=MDusDn8oTSE + // https://blog.winter.dev/2020/gjk-algorithm/ + // Get initial support point in any direction std::shared_ptr support = std::make_shared(_support(obj, Vec3D{1, 0, 0})); @@ -169,6 +176,12 @@ std::pair RigidBody::checkGJKCollision(std::shared_ptr } CollisionPoint RigidBody::EPA(const Simplex& simplex, std::shared_ptr obj) { + // This is implementation of EPA algorithm for solving collision. + // It uses a simplex from GJK around and expand it to the border. + // The goal is to calculate the nearest normal and the intersection depth. + // See references: + // https://www.youtube.com/watch?v=0XQ2FSz3EK8 + // https://blog.winter.dev/2020/epa-algorithm/ std::vector polytope(simplex.begin(), simplex.end()); std::vector faces = {