Implemented a custom physics engine #316

Merged
direnbharwani merged 95 commits from SHPhysics into main 2023-01-23 15:55:45 +08:00
4 changed files with 11 additions and 9 deletions
Showing only changes of commit 1f2a9820d1 - Show all commits

View File

@ -66,7 +66,7 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: -1.45715916, y: 7, z: 0.64831841} Translate: {x: -1.45715916, y: 7, z: 0.0329093337}
Rotate: {x: -0, y: 0, z: -0} Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
@ -136,7 +136,7 @@
DrawColliders: false DrawColliders: false
Colliders: Colliders:
- Is Trigger: false - Is Trigger: false
Collision Tag: 1 Collision Tag: 2
Type: Box Type: Box
Half Extents: {x: 1, y: 1, z: 1} Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006 Friction: 0.400000006

View File

@ -376,6 +376,7 @@ namespace SHADE
{ {
SHEditorWidgets::CheckBox("Is Trigger", [shape] { return shape->IsTrigger(); }, [shape](bool value) { shape->SetIsTrigger(value); }); SHEditorWidgets::CheckBox("Is Trigger", [shape] { return shape->IsTrigger(); }, [shape](bool value) { shape->SetIsTrigger(value); });
SHEditorWidgets::ComboBox("Tag", collisionTagNames, [shape]{return SHCollisionTagMatrix::GetTagIndex(shape->GetCollisionTag().GetName());}, [shape](int const& value){shape->SetCollisionTag(SHCollisionTagMatrix::GetTag(value));});
if(ImGui::CollapsingHeader("Physics Material")) if(ImGui::CollapsingHeader("Physics Material"))
{ {

View File

@ -65,13 +65,6 @@ namespace SHADE
if (!collisionTable[TYPE_A][TYPE_B]) if (!collisionTable[TYPE_A][TYPE_B])
return false; return false;
// Filter through tags
const uint16_t TAG_A = A.GetCollisionTag().GetMask();
const uint16_t TAG_B = B.GetCollisionTag().GetMask();
const uint16_t MATCH = TAG_A & TAG_B;
return MATCH > 0;
} }
bool SHCollisionDispatcher::Collide(SHManifold& manifold, const SHCollisionShape& A, const SHCollisionShape& B) noexcept bool SHCollisionDispatcher::Collide(SHManifold& manifold, const SHCollisionShape& A, const SHCollisionShape& B) noexcept

View File

@ -143,6 +143,14 @@ namespace SHADE
// This applies both ways: A -> B and B -> A. // This applies both ways: A -> B and B -> A.
for (auto& [key, narrowphasePair] : narrowphaseBatch) for (auto& [key, narrowphasePair] : narrowphaseBatch)
{ {
// Filter through tags before attempting narrow-phase
const uint16_t TAG_A = narrowphasePair.A->GetCollisionTag().GetMask();
const uint16_t TAG_B = narrowphasePair.B->GetCollisionTag().GetMask();
const bool MATCH_TAG = TAG_A & TAG_B;
if (!MATCH_TAG)
continue;
const bool IS_A_TRIGGER = narrowphasePair.A->IsTrigger(); const bool IS_A_TRIGGER = narrowphasePair.A->IsTrigger();
const bool IS_B_TRIGGER = narrowphasePair.B->IsTrigger(); const bool IS_B_TRIGGER = narrowphasePair.B->IsTrigger();