Implemented a custom physics engine #316

Merged
direnbharwani merged 95 commits from SHPhysics into main 2023-01-23 15:55:45 +08:00
3 changed files with 8 additions and 15 deletions
Showing only changes of commit 987a1fa515 - Show all commits

View File

@ -36,12 +36,6 @@ namespace SHADE
friend class SHCollisionShapeLibrary; friend class SHCollisionShapeLibrary;
public: public:
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
static constexpr float RADIUS = 0.1f;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Constructors & Destructor */ /* Constructors & Destructor */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -52,8 +52,8 @@ namespace SHADE
const SHSphereCollisionShape& SPHERE = dynamic_cast<const SHSphereCollisionShape&>(A); const SHSphereCollisionShape& SPHERE = dynamic_cast<const SHSphereCollisionShape&>(A);
const SHConvexPolyhedronCollisionShape& CONVEX = dynamic_cast<const SHConvexPolyhedronCollisionShape&>(B); const SHConvexPolyhedronCollisionShape& CONVEX = dynamic_cast<const SHConvexPolyhedronCollisionShape&>(B);
const SHVec3 CENTER = SPHERE.GetCenter(); const SHVec3 CENTER = SPHERE.GetCenter();
const float TOTAL_RADIUS = SPHERE.GetWorldRadius() + SHConvexPolyhedronCollisionShape::RADIUS; const float RADIUS = SPHERE.GetWorldRadius();
// Find closest face of polygon to circle // Find closest face of polygon to circle
@ -86,7 +86,7 @@ namespace SHADE
// Early out: // Early out:
// If face is facing away from center, signed dist is negative. // If face is facing away from center, signed dist is negative.
// Therefore signed distance is only positive when sphere is in front of the face. // Therefore signed distance is only positive when sphere is in front of the face.
if (SIGNED_DIST > TOTAL_RADIUS) if (SIGNED_DIST > RADIUS)
return false; return false;
if (SIGNED_DIST > bestDistance) if (SIGNED_DIST > bestDistance)
@ -97,7 +97,7 @@ namespace SHADE
} }
uint32_t numContacts = 0; uint32_t numContacts = 0;
const float PENETRATION = TOTAL_RADIUS - bestDistance; const float PENETRATION = RADIUS - bestDistance;
// Check if center is inside polyhedron (below the face) // Check if center is inside polyhedron (below the face)
if (bestDistance < SHMath::EPSILON) if (bestDistance < SHMath::EPSILON)
@ -182,7 +182,7 @@ namespace SHADE
manifold.normal = CP_TO_CENTER; manifold.normal = CP_TO_CENTER;
SHContact newContact; SHContact newContact;
newContact.penetration = TOTAL_RADIUS - projection; newContact.penetration = RADIUS - projection;
newContact.position = CP; newContact.position = CP;
newContact.featurePair.key = 0; newContact.featurePair.key = 0;
@ -196,7 +196,7 @@ namespace SHADE
// Check region C (closest point) // Check region C (closest point)
{ {
if (C_TO_CENTER.LengthSquared() < TOTAL_RADIUS * TOTAL_RADIUS) if (C_TO_CENTER.LengthSquared() < RADIUS * RADIUS)
{ {
manifold.normal = -SHVec3::Normalise(C_TO_CENTER); manifold.normal = -SHVec3::Normalise(C_TO_CENTER);
@ -213,13 +213,13 @@ namespace SHADE
} }
// Region D // Region D
if (PENETRATION <= TOTAL_RADIUS) if (PENETRATION <= RADIUS)
{ {
manifold.normal = -NORMAL; manifold.normal = -NORMAL;
SHContact newContact; SHContact newContact;
newContact.penetration = PENETRATION; newContact.penetration = PENETRATION;
newContact.position = SPHERE.GetCenter() - NORMAL * TOTAL_RADIUS; newContact.position = SPHERE.GetCenter() - NORMAL * RADIUS;
newContact.featurePair.key = 0; newContact.featurePair.key = 0;
manifold.contacts[numContacts++] = newContact; manifold.contacts[numContacts++] = newContact;

View File

@ -108,7 +108,6 @@ namespace SHADE
/* /*
* TODO: A lot of this needs to be cleaned up.
* Resolve Contacts * Resolve Contacts
*/ */