From 7226ccf27998a9222bad29cc0804453aa48e7b95 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sun, 20 Nov 2022 03:16:49 +0800 Subject: [PATCH] Tested Collision Tags --- .../src/Application/SBApplication.cpp | 1 + .../src/Physics/Collision/SHCollisionTags.cpp | 2 +- .../Physics/Interface/SHCollisionShape.cpp | 6 ---- .../src/Physics/Interface/SHCollisionShape.h | 1 - .../Physics/PhysicsObject/SHPhysicsObject.cpp | 35 +++++++++---------- .../Physics/PhysicsObject/SHPhysicsObject.h | 3 -- 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 0fb8adf9..cf5a9277 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -174,6 +174,7 @@ namespace Sandbox SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f); editor->PollPicking(); + // TODO: Move into an Editor menu static bool drawColliders = false; if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F10)) { diff --git a/SHADE_Engine/src/Physics/Collision/SHCollisionTags.cpp b/SHADE_Engine/src/Physics/Collision/SHCollisionTags.cpp index fdcf72c6..85072e5e 100644 --- a/SHADE_Engine/src/Physics/Collision/SHCollisionTags.cpp +++ b/SHADE_Engine/src/Physics/Collision/SHCollisionTags.cpp @@ -30,7 +30,7 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ SHCollisionTag::SHCollisionTag() noexcept - : mask { SHUtilities::ConvertEnum(eTag::ALL_TAGS) } + : mask { SHUtilities::ConvertEnum(eTag::TAG_1) } {} SHCollisionTag::SHCollisionTag(uint16_t tagValue) noexcept diff --git a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp index 46348c19..745d64c5 100644 --- a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp @@ -251,12 +251,6 @@ namespace SHADE collisionTags = newCollisionTag; } - void SHCollisionShape::SetCollisionTags(SHCollisionTag::eTag newCollisionTag) noexcept - { - dirty = true; - collisionTags = SHCollisionTag{ newCollisionTag }; - } - void SHCollisionShape::SetFriction(float friction) noexcept { dirty = true; diff --git a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.h b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.h index 7cd8528a..fd08e55d 100644 --- a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.h +++ b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.h @@ -96,7 +96,6 @@ namespace SHADE void SetIsTrigger (bool isTrigger) noexcept; void SetCollisionTags (const SHCollisionTag& newCollisionTag) noexcept; - void SetCollisionTags (SHCollisionTag::eTag newCollisionTag) noexcept; void SetFriction (float friction) noexcept; void SetBounciness (float bounciness) noexcept; void SetDensity (float density) noexcept; diff --git a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp index 6ce8e9d3..ea3d5996 100644 --- a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp +++ b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp @@ -254,6 +254,10 @@ namespace SHADE } case 9: // Mass { + rp3dBody->setMass(component.mass); + rp3dBody->updateLocalCenterOfMassFromColliders(); + rp3dBody->updateLocalInertiaTensorFromColliders(); + //if (component.GetAutoMass()) //{ // rp3dBody->updateMassPropertiesFromColliders(); @@ -261,9 +265,9 @@ namespace SHADE //} //else //{ - rp3dBody->setMass(component.mass); - rp3dBody->updateLocalCenterOfMassFromColliders(); - rp3dBody->updateLocalInertiaTensorFromColliders(); + // rp3dBody->setMass(component.mass); + // rp3dBody->updateLocalCenterOfMassFromColliders(); + // rp3dBody->updateLocalInertiaTensorFromColliders(); //} break; @@ -309,10 +313,18 @@ namespace SHADE default: break; } - syncMaterial(i, collisionShape); + // Sync material + auto* rp3dCollider = rp3dBody->getCollider(i); + auto& rp3dMaterial = rp3dCollider->getMaterial(); + + rp3dMaterial.setFrictionCoefficient(collisionShape.GetFriction()); + rp3dMaterial.setBounciness(collisionShape.GetBounciness()); + rp3dMaterial.setMassDensity(collisionShape.GetDensity()); // Sync tags - + const unsigned short MASK_BITS = collisionShape.GetCollisionTags(); + rp3dCollider->setCollisionCategoryBits(MASK_BITS); + rp3dCollider->setCollideWithMaskBits(MASK_BITS); collisionShape.dirty = false; } @@ -322,19 +334,6 @@ namespace SHADE /* Private Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHPhysicsObject::syncMaterial(int colliderIndex, SHCollisionShape& collisionShape) const noexcept - { - auto& rp3dMaterial = rp3dBody->getCollider(colliderIndex)->getMaterial(); - rp3dMaterial.setFrictionCoefficient(collisionShape.GetFriction()); - rp3dMaterial.setBounciness(collisionShape.GetBounciness()); - rp3dMaterial.setMassDensity(collisionShape.GetDensity()); - } - - void SHPhysicsObject::syncTags(int colliderIndex, SHCollisionShape& collisionShape) const noexcept - { - - } - void SHPhysicsObject::addBoxShape(SHCollisionShape& boxShape) const noexcept { const rp3d::Transform OFFSETS diff --git a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h index a5e8a53c..fefc983f 100644 --- a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h +++ b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.h @@ -96,9 +96,6 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - void syncMaterial (int colliderIndex, SHCollisionShape& collisionShape) const noexcept; - void syncTags (int colliderIndex, SHCollisionShape& collisionShape) const noexcept; - // Box Shapes void addBoxShape (SHCollisionShape& boxShape) const noexcept;