Fixed bug with relative collider sizes

This commit is contained in:
Diren D Bharwani 2022-10-31 23:18:20 +08:00
parent da561421b2
commit 6e604fe7e9
3 changed files with 13 additions and 16 deletions

View File

@ -128,7 +128,6 @@ namespace Sandbox
floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC); floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC);
auto* floorBox = floorCollider.AddBoundingBox(); auto* floorBox = floorCollider.AddBoundingBox();
floorBox->SetHalfExtents(floorTransform.GetWorldScale() * 0.5f);
// Create blank entity with a script // Create blank entity with a script
//testObj = SHADE::SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>(); //testObj = SHADE::SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();

View File

@ -251,7 +251,7 @@ namespace SHADE
SHEditorWidgets::DragVec3 SHEditorWidgets::DragVec3
( (
"Half Extents", { "X", "Y", "Z" }, "Half Extents", { "X", "Y", "Z" },
[box, transformComponent] { return (transformComponent->GetWorldScale() * 2.0f) * box->GetHalfExtents(); }, [box, transformComponent] { return (box->GetHalfExtents() * 2.0f) / transformComponent->GetWorldScale(); },
[collider](SHVec3 const& vec) { collider->SetBoundingBox(vec); }); [collider](SHVec3 const& vec) { collider->SetBoundingBox(vec); });
} }
else if (collider->GetType() == SHCollider::Type::SPHERE) else if (collider->GetType() == SHCollider::Type::SPHERE)

View File

@ -19,8 +19,9 @@
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "Editor/SHEditor.h" #include "Editor/SHEditor.h"
#include "Math/SHMathHelpers.h" #include "Math/SHMathHelpers.h"
#include "Scene/SHSceneManager.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Scene/SHSceneManager.h"
#include "Scripting/SHScriptEngine.h"
namespace SHADE namespace SHADE
{ {
@ -325,38 +326,35 @@ namespace SHADE
void SHPhysicsSystem::PhysicsFixedUpdate::Execute(double dt) noexcept void SHPhysicsSystem::PhysicsFixedUpdate::Execute(double dt) noexcept
{ {
auto* system = reinterpret_cast<SHPhysicsSystem*>(GetSystem()); auto* physicsSystem = reinterpret_cast<SHPhysicsSystem*>(GetSystem());
fixedTimeStep = 1.0 / system->fixedDT;
fixedTimeStep = 1.0 / physicsSystem->fixedDT;
accumulatedTime += dt; accumulatedTime += dt;
int count = 0; int count = 0;
while (accumulatedTime > fixedTimeStep) while (accumulatedTime > fixedTimeStep)
{ {
system->world->update(static_cast<rp3d::decimal>(fixedTimeStep)); physicsSystem->world->update(static_cast<rp3d::decimal>(fixedTimeStep));
accumulatedTime -= fixedTimeStep; accumulatedTime -= fixedTimeStep;
++count; ++count;
} }
stats.numSteps = count; stats.numSteps = count;
system->worldUpdated = count > 0; physicsSystem->worldUpdated = count > 0;
system->interpolationFactor = accumulatedTime / fixedTimeStep; physicsSystem->interpolationFactor = accumulatedTime / fixedTimeStep;
} }
void SHPhysicsSystem::PhysicsPostUpdate::Execute(double) noexcept void SHPhysicsSystem::PhysicsPostUpdate::Execute(double) noexcept
{ {
auto* system = reinterpret_cast<SHPhysicsSystem*>(GetSystem()); auto* physicsSystem = reinterpret_cast<SHPhysicsSystem*>(GetSystem());
// Interpolate transforms for rendering // Interpolate transforms for rendering
if (system->worldUpdated) if (physicsSystem->worldUpdated)
{ physicsSystem->SyncTransforms();
system->SyncTransforms();
// TODO(Kah Wei): Take Collision & Trigger messages here physicsSystem->ClearInvalidCollisions();
system->ClearInvalidCollisions();
}
} }
void SHPhysicsSystem::onContact(const CallbackData& callbackData) void SHPhysicsSystem::onContact(const CallbackData& callbackData)