From 1f2a9820d1cc96a7d78e2842969a04e8f7c27cc4 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Mon, 2 Jan 2023 22:49:12 +0800 Subject: [PATCH] Readded collision tags and moved collision filtering to an earlier stage --- Assets/Scenes/PhysicsSandbox.shade | 4 ++-- .../EditorWindow/Inspector/SHEditorComponentView.hpp | 1 + .../Physics/Collision/Narrowphase/SHCollisionDispatch.cpp | 7 ------- SHADE_Engine/src/Physics/Collision/SHCollisionSpace.cpp | 8 ++++++++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Assets/Scenes/PhysicsSandbox.shade b/Assets/Scenes/PhysicsSandbox.shade index b07549cc..a02f3b24 100644 --- a/Assets/Scenes/PhysicsSandbox.shade +++ b/Assets/Scenes/PhysicsSandbox.shade @@ -66,7 +66,7 @@ NumberOfChildren: 0 Components: 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} Scale: {x: 1, y: 1, z: 1} IsActive: true @@ -136,7 +136,7 @@ DrawColliders: false Colliders: - Is Trigger: false - Collision Tag: 1 + Collision Tag: 2 Type: Box Half Extents: {x: 1, y: 1, z: 1} Friction: 0.400000006 diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 6117dfe8..a46e2550 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -376,6 +376,7 @@ namespace SHADE { 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")) { diff --git a/SHADE_Engine/src/Physics/Collision/Narrowphase/SHCollisionDispatch.cpp b/SHADE_Engine/src/Physics/Collision/Narrowphase/SHCollisionDispatch.cpp index 4a949d77..e11902e0 100644 --- a/SHADE_Engine/src/Physics/Collision/Narrowphase/SHCollisionDispatch.cpp +++ b/SHADE_Engine/src/Physics/Collision/Narrowphase/SHCollisionDispatch.cpp @@ -65,13 +65,6 @@ namespace SHADE if (!collisionTable[TYPE_A][TYPE_B]) 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 diff --git a/SHADE_Engine/src/Physics/Collision/SHCollisionSpace.cpp b/SHADE_Engine/src/Physics/Collision/SHCollisionSpace.cpp index 4dcc7cb7..88fdac40 100644 --- a/SHADE_Engine/src/Physics/Collision/SHCollisionSpace.cpp +++ b/SHADE_Engine/src/Physics/Collision/SHCollisionSpace.cpp @@ -143,6 +143,14 @@ namespace SHADE // This applies both ways: A -> B and B -> A. 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_B_TRIGGER = narrowphasePair.B->IsTrigger();