From 8c9c6c21dfd7a43ed1a44509f800faf4d41033b5 Mon Sep 17 00:00:00 2001 From: antopilo Date: Wed, 8 Mar 2023 20:21:50 -0500 Subject: [PATCH] Added sphere collider --- .../src/ComponentsPanel/SphereColliderPanel.h | 38 +++++++++++++++++++ Editor/src/Windows/EditorSelectionPanel.cpp | 2 +- Editor/src/Windows/EditorSelectionPanel.h | 2 + Nuake/src/Scene/Systems/PhysicsSystem.cpp | 16 ++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 Editor/src/ComponentsPanel/SphereColliderPanel.h diff --git a/Editor/src/ComponentsPanel/SphereColliderPanel.h b/Editor/src/ComponentsPanel/SphereColliderPanel.h new file mode 100644 index 00000000..0a92c5cd --- /dev/null +++ b/Editor/src/ComponentsPanel/SphereColliderPanel.h @@ -0,0 +1,38 @@ +#pragma once +#include "ComponentPanel.h" +#include +#include +#include + +class SphereColliderPanel : ComponentPanel { +public: + SphereColliderPanel() {} + + void Draw(Nuake::Entity entity) override + { + if (!entity.HasComponent()) + return; + + auto& component = entity.GetComponent(); + BeginComponentTable(SPHERE COLLIDER, Nuake::SphereColliderComponent); + { + { + ImGui::Text("Size"); + ImGui::TableNextColumn(); + ImGui::DragFloat("##Radius", &component.Radius); + ImGui::TableNextColumn(); + ComponentTableReset(component.Radius, 0.5f); + } + ImGui::TableNextColumn(); + { + ImGui::Text("Is Trigger"); + ImGui::TableNextColumn(); + + ImGui::Checkbox("##isTrigger", &component.IsTrigger); + ImGui::TableNextColumn(); + ComponentTableReset(component.IsTrigger, false); + } + } + EndComponentTable(); + } +}; \ No newline at end of file diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 3c77548c..531306a9 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -100,7 +100,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) mCameraPanel.Draw(entity); mRigidbodyPanel.Draw(entity); mBoxColliderPanel.Draw(entity); - + mSphereColliderPanel.Draw(entity); /* if (Selection.Entity.HasComponent()) { diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 4f525755..f4ea99a1 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -13,6 +13,7 @@ #include "../ComponentsPanel/CameraPanel.h" #include "../ComponentsPanel/RigidbodyPanel.h" #include "../ComponentsPanel/BoxColliderPanel.h" +#include "../ComponentsPanel/SphereColliderPanel.h" class EditorSelectionPanel { private: @@ -24,6 +25,7 @@ private: CameraPanel mCameraPanel; RigidbodyPanel mRigidbodyPanel; BoxColliderPanel mBoxColliderPanel; + SphereColliderPanel mSphereColliderPanel; Ref currentFile; Ref selectedResource; diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 6756506c..c55592ab 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -1,6 +1,7 @@ #include "PhysicsSystem.h" #include "src/Scene/Scene.h" #include "src/Scene/Components/BoxCollider.h" +#include "src/Scene/Components/SphereCollider.h" #include #include "src/Scene/Entities/Entity.h" @@ -25,7 +26,7 @@ namespace Nuake { auto [transform, rigidbody] = view.get(e); Entity ent = Entity({ e, m_Scene }); - + Ref rigidBody; if (ent.HasComponent()) { float mass = rigidbody.Mass; @@ -33,9 +34,18 @@ namespace Nuake BoxColliderComponent& boxComponent = ent.GetComponent(); Ref boxShape = CreateRef(boxComponent.Size); - Ref btRigidbody = CreateRef(mass, transform.GetGlobalPosition(), boxShape); + rigidBody = CreateRef(mass, transform.GetGlobalPosition(), boxShape, ent); + } - PhysicsManager::Get()->RegisterBody(btRigidbody); + if (ent.HasComponent()) + { + float mass = rigidbody.Mass; + + const auto& component = ent.GetComponent(); + auto shape = CreateRef(component.Radius); + + rigidBody = CreateRef(mass, transform.GetGlobalPosition(), shape, ent); + PhysicsManager::Get()->RegisterBody(rigidBody); } }