Removed unused collision table and fixed bug with kinematic bodies exploding

This commit is contained in:
Diren D Bharwani 2023-01-16 03:48:08 +08:00
parent 19bffc9124
commit 85f0902c2d
3 changed files with 1 additions and 53 deletions

View File

@ -42,31 +42,10 @@ namespace SHADE
, { SHCollision::CapsuleVsSphere, SHCollision::CapsuleVsConvex, SHCollision::CapsuleVsCapsule } // Capsule , { SHCollision::CapsuleVsSphere, SHCollision::CapsuleVsConvex, SHCollision::CapsuleVsCapsule } // Capsule
}; };
const bool SHCollisionDispatcher::collisionTable[NUM_TYPES][NUM_TYPES]
{
/* S ST K KT D DT */
/* S */ { false, false, false, true, true, true }
, /* ST */ { false, false, true, true, true, true }
, /* K */ { false, true, false, true, true, true }
, /* KT */ { true, true, true, true, true, true }
, /* D */ { true, true, true, true, true, true }
, /* DT */ { true, true, true, true, true, true }
};
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Public Member Functions Definitions */ /* Public Member Functions Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
bool SHCollisionDispatcher::ShouldCollide(const SHCollisionShape& A, const SHCollisionShape& B) noexcept
{
// Filter through collision table
const int TYPE_A = SHUtilities::ConvertEnum(A.GetType()) + A.IsTrigger() ? TYPE_OFFSET : 0;
const int TYPE_B = SHUtilities::ConvertEnum(B.GetType()) + B.IsTrigger() ? TYPE_OFFSET : 0;
if (!collisionTable[TYPE_A][TYPE_B])
return false;
}
bool SHCollisionDispatcher::Collide(SHManifold& manifold, const SHCollisionShape& A, const SHCollisionShape& B) noexcept bool SHCollisionDispatcher::Collide(SHManifold& manifold, const SHCollisionShape& A, const SHCollisionShape& B) noexcept
{ {
const int TYPE_A = SHUtilities::ConvertEnum(A.GetType()); const int TYPE_A = SHUtilities::ConvertEnum(A.GetType());

View File

@ -31,18 +31,6 @@ namespace SHADE
/* Member Functions */ /* Member Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/**
* @brief
* Filters the collision through the collision table and layer matching.
* @param A
* A Collision Shape.
* @param B
* A Collision Shape.
* @return
* True if both shapes should be tested for collision.
*/
static bool ShouldCollide (const SHCollisionShape& A, const SHCollisionShape& B) noexcept;
static bool Collide (SHManifold& manifold, const SHCollisionShape& A, const SHCollisionShape& B) noexcept; static bool Collide (SHManifold& manifold, const SHCollisionShape& A, const SHCollisionShape& B) noexcept;
static bool Collide (const SHCollisionShape& A, const SHCollisionShape& B) noexcept; static bool Collide (const SHCollisionShape& A, const SHCollisionShape& B) noexcept;
@ -54,33 +42,14 @@ namespace SHADE
using ManifoldCollide = bool(*)(SHManifold&, const SHCollisionShape& A, const SHCollisionShape& B); using ManifoldCollide = bool(*)(SHManifold&, const SHCollisionShape& A, const SHCollisionShape& B);
using TriggerCollide = bool(*)(const SHCollisionShape& A, const SHCollisionShape& B); using TriggerCollide = bool(*)(const SHCollisionShape& A, const SHCollisionShape& B);
enum class Types
{
STATIC
, KINEMATIC
, DYNAMIC
, STATIC_TRIGGER
, KINEMATIC_TRIGGER
, DYNAMIC_TRIGGER
, COUNT
};
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Data Members */ /* Data Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
// Read the Types enum class, then see where it's used and it'll make sense
static constexpr int TYPE_OFFSET = 3;
static constexpr int NUM_SHAPES = static_cast<int>(SHCollisionShape::Type::COUNT); static constexpr int NUM_SHAPES = static_cast<int>(SHCollisionShape::Type::COUNT);
static constexpr int NUM_TYPES = static_cast<int>(Types::COUNT);
static const ManifoldCollide manifoldCollide [NUM_SHAPES][NUM_SHAPES]; static const ManifoldCollide manifoldCollide [NUM_SHAPES][NUM_SHAPES];
static const TriggerCollide triggerCollide [NUM_SHAPES][NUM_SHAPES]; static const TriggerCollide triggerCollide [NUM_SHAPES][NUM_SHAPES];
static const bool collisionTable [NUM_TYPES][NUM_TYPES];
}; };

View File

@ -643,7 +643,7 @@ namespace SHADE
// Compute world centroid // Compute world centroid
worldCentroid = (R * localCentroid) + motionState.position; worldCentroid = (R * localCentroid) + motionState.position;
if (bodyType == Type::STATIC) if (bodyType != Type::DYNAMIC)
return; return;
// Compute world inertia // Compute world inertia