From d59f4e88c267c957e36911b1fb2a1f6ca2372fbe Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sun, 5 Mar 2023 23:39:33 +0800 Subject: [PATCH] Added gravity scale Update react dependency --- Assets/Scenes/PhysicsTest.shade | 4 +++- .../Inspector/SHEditorComponentView.hpp | 4 ++++ .../PhysicsObject/SHPhysicsObjectManager.cpp | 1 + .../Physics/Interface/SHRigidBodyComponent.cpp | 15 +++++++++++++++ .../src/Physics/Interface/SHRigidBodyComponent.h | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Assets/Scenes/PhysicsTest.shade b/Assets/Scenes/PhysicsTest.shade index 20903809..982556af 100644 --- a/Assets/Scenes/PhysicsTest.shade +++ b/Assets/Scenes/PhysicsTest.shade @@ -12,6 +12,7 @@ Type: Dynamic Drag: 0.00999999978 Angular Drag: 0.100000001 + Gravity Scale: 0.100000001 Use Gravity: true Interpolate: false Sleeping Enabled: true @@ -75,10 +76,10 @@ Yaw: 0 Roll: 0 Width: 1920 - Height: 1080 Near: 0.00999999978 Far: 10000 Perspective: true + FOV: 90 IsActive: true Scripts: ~ - EID: 65539 @@ -187,6 +188,7 @@ Type: Dynamic Drag: 0.00999999978 Angular Drag: 0.100000001 + Gravity Scale: 1 Use Gravity: true Interpolate: true Sleeping Enabled: true diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 8adb45b5..fe84db31 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -263,6 +263,10 @@ namespace SHADE if(rbType == SHRigidBodyComponent::Type::DYNAMIC) //Dynamic only fields { SHEditorWidgets::CheckBox("Use Gravity", [component]{return component->IsGravityEnabled();}, [component](bool const& value){component->SetGravityEnabled(value);}, "Gravity"); + + if (component->IsGravityEnabled()) + SHEditorWidgets::DragFloat("Gravity Scale", [component] {return component->GetGravityScale(); }, [component](float const& value) {component->SetGravityScale(value); }, "Gravity Scale"); + //SHEditorWidgets::DragFloat("Mass", [component] {return component->GetMass(); }, [component](float const& value) {component->SetMass(value); }, "Mass"); } if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields diff --git a/SHADE_Engine/src/Physics/Interface/PhysicsObject/SHPhysicsObjectManager.cpp b/SHADE_Engine/src/Physics/Interface/PhysicsObject/SHPhysicsObjectManager.cpp index b22741e9..a0b2f7cc 100644 --- a/SHADE_Engine/src/Physics/Interface/PhysicsObject/SHPhysicsObjectManager.cpp +++ b/SHADE_Engine/src/Physics/Interface/PhysicsObject/SHPhysicsObjectManager.cpp @@ -297,6 +297,7 @@ namespace SHADE rigidBodyComponent->SetInterpolate (rigidBodyComponent->IsInterpolating()); rigidBodyComponent->SetDrag (rigidBodyComponent->GetDrag()); rigidBodyComponent->SetAngularDrag (rigidBodyComponent->GetAngularDrag()); + rigidBodyComponent->SetGravityScale (rigidBodyComponent->GetGravityScale()); rigidBodyQueue.pop(); } diff --git a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp index ee4db90d..85c798db 100644 --- a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp @@ -114,6 +114,11 @@ namespace SHADE return angularDrag; } + float SHRigidBodyComponent::GetGravityScale() const noexcept + { + return gravityScale; + } + SHVec3 SHRigidBodyComponent::GetForce() const noexcept { return rigidBody ? SHVec3{ rigidBody->getForce() } : SHVec3::Zero; @@ -297,6 +302,15 @@ namespace SHADE rigidBody->setAngularDamping(newAngularDrag); } + void SHRigidBodyComponent::SetGravityScale(float newGravityScale) noexcept + { + gravityScale = newGravityScale; + + if (rigidBody) + rigidBody->setGravityScale(newGravityScale); + } + + void SHRigidBodyComponent::SetLinearVelocity(const SHVec3& newLinearVelocity) noexcept { if (type == Type::STATIC) @@ -408,6 +422,7 @@ RTTR_REGISTRATION .property("Type" , &SHRigidBodyComponent::GetType , &SHRigidBodyComponent::SetType ) .property("Drag" , &SHRigidBodyComponent::GetDrag , &SHRigidBodyComponent::SetDrag ) .property("Angular Drag" , &SHRigidBodyComponent::GetAngularDrag , &SHRigidBodyComponent::SetAngularDrag ) + .property("Gravity Scale" , &SHRigidBodyComponent::GetGravityScale , &SHRigidBodyComponent::SetGravityScale ) .property("Use Gravity" , &SHRigidBodyComponent::IsGravityEnabled , &SHRigidBodyComponent::SetGravityEnabled ) .property("Interpolate" , &SHRigidBodyComponent::IsInterpolating , &SHRigidBodyComponent::SetInterpolate ) .property("Sleeping Enabled" , &SHRigidBodyComponent::IsAllowedToSleep , &SHRigidBodyComponent::SetIsAllowedToSleep) diff --git a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h index 6332d1e6..a1cbe786 100644 --- a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h +++ b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h @@ -93,6 +93,7 @@ namespace SHADE [[nodiscard]] float GetMass () const noexcept; [[nodiscard]] float GetDrag () const noexcept; [[nodiscard]] float GetAngularDrag () const noexcept; + [[nodiscard]] float GetGravityScale () const noexcept; [[nodiscard]] SHVec3 GetForce () const noexcept; [[nodiscard]] SHVec3 GetTorque () const noexcept; @@ -123,6 +124,7 @@ namespace SHADE void SetDrag (float newDrag) noexcept; void SetAngularDrag (float newAngularDrag) noexcept; + void SetGravityScale (float newGravityScale) noexcept; void SetLinearVelocity (const SHVec3& newLinearVelocity) noexcept; void SetAngularVelocity (const SHVec3& newAngularVelocity) noexcept; @@ -173,6 +175,7 @@ namespace SHADE // Used for storing serialised data uint8_t flags; // aZ aY aX lZ lY lX sleepEnabled gravity + float gravityScale; float drag; float angularDrag;