Fixed bug where adding colliders would fail to maintain previous collider sizes

This commit is contained in:
Diren D Bharwani 2022-11-17 10:42:45 +08:00
parent 8f9fedff41
commit 7288894507
3 changed files with 21 additions and 4 deletions

View File

@ -304,6 +304,9 @@ namespace SHADE
const auto* RHS_BOX = reinterpret_cast<const SHBox*>(rhs); const auto* RHS_BOX = reinterpret_cast<const SHBox*>(rhs);
shape = new SHBox{ positionOffset, RHS_BOX->GetWorldExtents() }; shape = new SHBox{ positionOffset, RHS_BOX->GetWorldExtents() };
auto* lhsBox = reinterpret_cast<SHBox*>(shape);
lhsBox->SetRelativeExtents(RHS_BOX->GetRelativeExtents());
break; break;
} }
case Type::SPHERE: case Type::SPHERE:
@ -311,6 +314,9 @@ namespace SHADE
const auto* RHS_SPHERE = reinterpret_cast<const SHSphere*>(rhs); const auto* RHS_SPHERE = reinterpret_cast<const SHSphere*>(rhs);
shape = new SHSphere{ positionOffset, RHS_SPHERE->GetWorldRadius() }; shape = new SHSphere{ positionOffset, RHS_SPHERE->GetWorldRadius() };
auto* lhsSphere = reinterpret_cast<SHSphere*>(shape);
lhsSphere->SetRelativeRadius(RHS_SPHERE->GetRelativeRadius());
break; break;
} }
default: break; default: break;

View File

@ -109,14 +109,25 @@ namespace SHADE
{ {
// TODO(Diren): Add more collider shapes // TODO(Diren): Add more collider shapes
case SHCollisionShape::Type::BOX: addBoxShape(collisionShape); break; case SHCollisionShape::Type::BOX:
case SHCollisionShape::Type::SPHERE: addSphereShape(collisionShape); break; {
addBoxShape(collisionShape);
break;
}
case SHCollisionShape::Type::SPHERE:
{
addSphereShape(collisionShape);
break;
}
default: break; default: break;
} }
rp3dBody->updateLocalCenterOfMassFromColliders(); rp3dBody->updateLocalCenterOfMassFromColliders();
rp3dBody->updateLocalInertiaTensorFromColliders(); rp3dBody->updateLocalInertiaTensorFromColliders();
SyncColliders(*colliderComponent);
return index; return index;
} }

View File

@ -38,8 +38,8 @@ namespace SHADE
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
SHVec3 gravity = SHVec3{ 0.0f, -9.81f, 0.0f }; SHVec3 gravity = SHVec3{ 0.0f, -9.81f, 0.0f };
uint16_t numVelocitySolverIterations = 15; uint16_t numVelocitySolverIterations = 10;
uint16_t numPositionSolverIterations = 8; uint16_t numPositionSolverIterations = 5;
bool sleepingEnabled = true; bool sleepingEnabled = true;
}; };