Added Collision Tags #233

Merged
direnbharwani merged 10 commits from SP3-2-Physics into main 2022-11-20 22:40:53 +08:00
6 changed files with 19 additions and 29 deletions
Showing only changes of commit 7226ccf279 - Show all commits

View File

@ -174,6 +174,7 @@ namespace Sandbox
SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f); SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f);
editor->PollPicking(); editor->PollPicking();
// TODO: Move into an Editor menu
static bool drawColliders = false; static bool drawColliders = false;
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F10)) if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F10))
{ {

View File

@ -30,7 +30,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHCollisionTag::SHCollisionTag() noexcept SHCollisionTag::SHCollisionTag() noexcept
: mask { SHUtilities::ConvertEnum(eTag::ALL_TAGS) } : mask { SHUtilities::ConvertEnum(eTag::TAG_1) }
{} {}
SHCollisionTag::SHCollisionTag(uint16_t tagValue) noexcept SHCollisionTag::SHCollisionTag(uint16_t tagValue) noexcept

View File

@ -251,12 +251,6 @@ namespace SHADE
collisionTags = newCollisionTag; collisionTags = newCollisionTag;
} }
void SHCollisionShape::SetCollisionTags(SHCollisionTag::eTag newCollisionTag) noexcept
{
dirty = true;
collisionTags = SHCollisionTag{ newCollisionTag };
}
void SHCollisionShape::SetFriction(float friction) noexcept void SHCollisionShape::SetFriction(float friction) noexcept
{ {
dirty = true; dirty = true;

View File

@ -96,7 +96,6 @@ namespace SHADE
void SetIsTrigger (bool isTrigger) noexcept; void SetIsTrigger (bool isTrigger) noexcept;
void SetCollisionTags (const SHCollisionTag& newCollisionTag) noexcept; void SetCollisionTags (const SHCollisionTag& newCollisionTag) noexcept;
void SetCollisionTags (SHCollisionTag::eTag newCollisionTag) noexcept;
void SetFriction (float friction) noexcept; void SetFriction (float friction) noexcept;
void SetBounciness (float bounciness) noexcept; void SetBounciness (float bounciness) noexcept;
void SetDensity (float density) noexcept; void SetDensity (float density) noexcept;

View File

@ -254,6 +254,10 @@ namespace SHADE
} }
case 9: // Mass case 9: // Mass
{ {
rp3dBody->setMass(component.mass);
rp3dBody->updateLocalCenterOfMassFromColliders();
rp3dBody->updateLocalInertiaTensorFromColliders();
//if (component.GetAutoMass()) //if (component.GetAutoMass())
//{ //{
// rp3dBody->updateMassPropertiesFromColliders(); // rp3dBody->updateMassPropertiesFromColliders();
@ -261,9 +265,9 @@ namespace SHADE
//} //}
//else //else
//{ //{
rp3dBody->setMass(component.mass); // rp3dBody->setMass(component.mass);
rp3dBody->updateLocalCenterOfMassFromColliders(); // rp3dBody->updateLocalCenterOfMassFromColliders();
rp3dBody->updateLocalInertiaTensorFromColliders(); // rp3dBody->updateLocalInertiaTensorFromColliders();
//} //}
break; break;
@ -309,10 +313,18 @@ namespace SHADE
default: break; 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 // Sync tags
const unsigned short MASK_BITS = collisionShape.GetCollisionTags();
rp3dCollider->setCollisionCategoryBits(MASK_BITS);
rp3dCollider->setCollideWithMaskBits(MASK_BITS);
collisionShape.dirty = false; collisionShape.dirty = false;
} }
@ -322,19 +334,6 @@ namespace SHADE
/* Private Function Member Definitions */ /* 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 void SHPhysicsObject::addBoxShape(SHCollisionShape& boxShape) const noexcept
{ {
const rp3d::Transform OFFSETS const rp3d::Transform OFFSETS

View File

@ -96,9 +96,6 @@ namespace SHADE
/* Function Members */ /* Function Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void syncMaterial (int colliderIndex, SHCollisionShape& collisionShape) const noexcept;
void syncTags (int colliderIndex, SHCollisionShape& collisionShape) const noexcept;
// Box Shapes // Box Shapes
void addBoxShape (SHCollisionShape& boxShape) const noexcept; void addBoxShape (SHCollisionShape& boxShape) const noexcept;