diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 1569a13c..f9b5cf41 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -143,18 +143,6 @@ namespace SHADE return result; } - AssetType SHAssetManager::GetType(AssetID id) noexcept - { - if (assetCollection.contains(id)) - { - return assetCollection[id].type; - } - - SHLOG_WARNING("AssetID {}, does not belong to an asset", id) - - return AssetType::INVALID; - } - std::optional SHAssetManager::GetAsset(AssetID id) noexcept { if (assetCollection.contains(id)) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 6cac6c71..9d0a0bf4 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -52,8 +52,6 @@ namespace SHADE static std::vector GetAllAssets() noexcept; static std::optional GetAsset(AssetID id) noexcept; - static AssetType GetType(AssetID id) noexcept; - /**************************************************************************** * \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM * RESOURCES CREATED BY THE ENGINE. diff --git a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp index 4c56d032..97fd8a22 100644 --- a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp +++ b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp @@ -5,7 +5,6 @@ namespace SHADE { bool SHDragDrop::hasDragDrop = false; - SHDragDrop::DragDropTag SHDragDrop::currentDragDropTag{}; bool SHDragDrop::BeginSource(ImGuiDragDropFlags const flags) { return ImGui::BeginDragDropSource(flags); } @@ -17,10 +16,6 @@ namespace SHADE { return ImGui::BeginDragDropTarget(); } void SHDragDrop::EndTarget() - { - ImGui::EndDragDropTarget(); - hasDragDrop = false; - currentDragDropTag = {}; - } + { ImGui::EndDragDropTarget(); hasDragDrop = false;} } diff --git a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp index f111eaeb..ce0615e1 100644 --- a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp +++ b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp @@ -19,13 +19,9 @@ namespace SHADE static void EndSource(); template - static bool SetPayload(DragDropTag const& type, T* object, ImGuiCond const cond = 0) + static bool SetPayload(std::string_view const type, T* object, ImGuiCond const cond = 0) { - ImGui::SetDragDropPayload(type.data(), static_cast(object), sizeof(T), cond); - - hasDragDrop = true; - currentDragDropTag = type; - + hasDragDrop = ImGui::SetDragDropPayload(type.data(), static_cast(object), sizeof(T), cond); return hasDragDrop; } @@ -36,16 +32,13 @@ namespace SHADE static void EndTarget(); template - static T* AcceptPayload(DragDropTag const& type, ImGuiDragDropFlags const flags = 0) + static T* AcceptPayload(std::string_view const type, ImGuiDragDropFlags const flags = 0) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(type.data(), flags)) - { return static_cast(payload->Data); - } return nullptr; } static bool hasDragDrop; - static DragDropTag currentDragDropTag; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 66b3c962..889c24cc 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -109,7 +109,7 @@ namespace SHADE ImVec2 vertLineEnd = vertLineStart; for (auto const& subFolder : subFolders) { - const float horizontalLineSize = (subFolder->subFolders.empty() && subFolder->files.empty()) ? 25.0f : 8.0f; + const float horizontalLineSize = 8.0f; const ImRect childRect = RecursivelyDrawTree(subFolder); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); @@ -117,7 +117,7 @@ namespace SHADE } for (auto& file : files) { - const float horizontalLineSize = (file.assetMeta && !file.assetMeta->subAssets.empty()) ? 8.0f : 25.0f; + const float horizontalLineSize = 25.0f; const ImRect childRect = DrawFile(file); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); @@ -182,10 +182,7 @@ namespace SHADE return nodeRect; } if(file.assetMeta) - { - const ImRect childRect = DrawAsset(file.assetMeta, file.ext); - return childRect; - } + DrawAsset(file.assetMeta, file.ext); } ImRect SHAssetBrowser::DrawAsset(SHAsset const* const asset, FileExt const& ext /*= ""*/) noexcept diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index 2235f831..cf545223 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -117,12 +117,9 @@ namespace SHADE { if(ImGui::IsDragDropActive()) { - if (SHDragDrop::currentDragDropTag == SHDragDrop::DRAG_EID) - { - ParentSelectedEntities(MAX_EID, draggingEntities); - draggingEntities.clear(); - ImGui::ClearDragDrop(); - } + ParentSelectedEntities(MAX_EID, draggingEntities); + draggingEntities.clear(); + ImGui::ClearDragDrop(); } } ImGui::End(); @@ -236,9 +233,8 @@ namespace SHADE { ParentSelectedEntities(eid, draggingEntities); draggingEntities.clear(); - //ImGui::ClearDragDrop(); + SHDragDrop::EndTarget(); } - SHDragDrop::EndTarget(); } //Context menu @@ -346,12 +342,17 @@ namespace SHADE SHEntityManager::CreateEntity(MAX_EID, "DefaultChild", parentEID); } - void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector const& entities) noexcept + void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector const& entities) const noexcept { auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - std::vector entitiesToParent = CleanUpEIDList(entities); - + std::vector entitiesToParent{}; + std::ranges::copy_if(entities, std::back_inserter(entitiesToParent), [&sceneGraph](EntityID const& eid) + { + if (sceneGraph.GetParent(eid)->GetEntityID() == MAX_EID) + return true; + return false; + }); //auto const editor = SHSystemManager::GetSystem(); SHEntityParentCommand::EntityParentData entityParentData; std::vector parentedEIDS; @@ -418,7 +419,14 @@ namespace SHADE void SHHierarchyPanel::CopySelectedEntities() { const auto editor = SHSystemManager::GetSystem(); - std::vector entitiesToCopy = CleanUpEIDList(editor->selectedEntities); + auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); + std::vector entitiesToCopy{}; + std::ranges::copy_if(editor->selectedEntities, std::back_inserter(entitiesToCopy), [&sceneGraph](EntityID const& eid) + { + if(sceneGraph.GetParent(eid)->GetEntityID() == MAX_EID) + return true; + return false; + }); SHClipboardUtilities::WriteToClipboard(SHSerialization::SerializeEntitiesToString(entitiesToCopy)); } @@ -431,25 +439,19 @@ namespace SHADE void SHHierarchyPanel::DeleteSelectedEntities() { const auto editor = SHSystemManager::GetSystem(); - std::vector entitiesToDelete = CleanUpEIDList(editor->selectedEntities); - SHCommandManager::PerformCommand(std::make_shared(entitiesToDelete)); - } - - std::vector SHHierarchyPanel::CleanUpEIDList(std::vector const& entities) - { - std::vector result; auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - std::ranges::copy_if(entities, std::back_inserter(result), [&sceneGraph, &entities](EntityID const& eid) + std::vector entitiesToDelete{}; + std::ranges::copy_if(editor->selectedEntities, std::back_inserter(entitiesToDelete), [&sceneGraph, &selectedEntities = editor->selectedEntities](EntityID const& eid) { EntityID parentEID = sceneGraph.GetParent(eid)->GetEntityID(); if (parentEID == MAX_EID) return true; - if (std::ranges::find(entities, parentEID) == entities.end()) + else if(std::ranges::find(selectedEntities, parentEID) == selectedEntities.end()) return true; return false; }); - return result; + SHCommandManager::PerformCommand(std::make_shared(entitiesToDelete)); } }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h index 9278a0a3..66b9ca2f 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h @@ -27,13 +27,12 @@ namespace SHADE void DrawMenuBar() const noexcept; ImRect RecursivelyDrawEntityNode(SHSceneNode* const); void CreateChildEntity(EntityID parentEID) const noexcept; - void ParentSelectedEntities(EntityID parentEID, std::vector const& entities) noexcept; + void ParentSelectedEntities(EntityID parentEID, std::vector const& entities) const noexcept; void SelectRangeOfEntities(EntityID beginEID, EntityID EndEID); void SelectAllEntities(); void CopySelectedEntities(); void PasteEntities(EntityID parentEID = MAX_EID); void DeleteSelectedEntities(); - std::vector CleanUpEIDList(std::vector const& entities); bool skipFrame = false; std::string filter; bool isAnyNodeSelected = false; diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 46ffd3bf..ebc7272a 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -290,7 +290,6 @@ namespace SHADE { SHEditorWidgets::DragVec3("Force", { "X", "Y", "Z" }, [component] {return component->GetForce(); }, [](SHVec3 const& value) {}, false, "Force", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); SHEditorWidgets::DragVec3("Torque", { "X", "Y", "Z" }, [component] {return component->GetTorque(); }, [](SHVec3 const& value) {}, false, "Torque", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly); - SHEditorWidgets::CheckBox("Is Asleep", [component] {return component->GetIsSleeping(); }, [](bool value) {}, "If the Rigid Body is asleep"); } } @@ -455,11 +454,6 @@ namespace SHADE }, [component](AssetID const& id) { - if(SHAssetManager::GetType(id) != AssetType::MESH) - { - SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!") - return; - } component->SetMesh(SHResourceManager::LoadOrGet(id)); SHResourceManager::FinaliseChanges(); }, SHDragDrop::DRAG_RESOURCE); @@ -475,11 +469,6 @@ namespace SHADE }, [component](AssetID const& id) { - if (SHAssetManager::GetType(id) != AssetType::MATERIAL) - { - SHLOG_WARNING("Attempted to assign non material asset to Renderable Mesh property!") - return; - } auto gfxSystem = SHSystemManager::GetSystem(); component->SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(SHResourceManager::LoadOrGet(id))); }, SHDragDrop::DRAG_RESOURCE); diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp index 93f4a615..564731d6 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp @@ -14,7 +14,6 @@ #include "Camera/SHCameraSystem.h" #include "FRC/SHFramerateController.h" -#include "../../SHEditorWidgets.hpp" constexpr std::string_view windowName = "\xef\x80\x95 Viewport"; @@ -194,13 +193,6 @@ namespace SHADE if (isScale) ImGui::PopStyleColor(); ImGui::EndDisabled(); - - auto camSystem = SHSystemManager::GetSystem(); - auto editorCamera = camSystem->GetEditorCamera(); - //ImGui::SetNextItemWidth(10.0f); - SHEditorWidgets::SliderFloat("CamSpeed", 0.0f, 5.0f, [editorCamera] {return editorCamera->movementSpeed; }, [editorCamera](float const& value) {editorCamera->movementSpeed = value; }); - SHEditorWidgets::DragVec3("TurnSpeed", { "X", "Y", "Z" }, [editorCamera] {return editorCamera->turnSpeed; }, [editorCamera](SHVec3 const& value) {editorCamera->turnSpeed = value; }); - ImGui::EndMenuBar(); } } diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index 2681e916..bfde7525 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -422,7 +422,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr); + bool changed = ImGui::InputText("##", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr); if(SHDragDrop::BeginTarget()) { if(T* payload = SHDragDrop::AcceptPayload(dragDropTag)) @@ -454,7 +454,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragScalar("##dragScalar", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); + const bool hasChange = ImGui::DragScalar("##", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -487,7 +487,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragFloat("##dragFloat", &value, speed, p_min, p_max, displayFormat, flags); + const bool hasChange = ImGui::DragFloat("##", &value, speed, p_min, p_max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -520,7 +520,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragInt("##dragInt", &value, speed, p_min, p_max, displayFormat, flags); + const bool hasChange = ImGui::DragInt("##", &value, speed, p_min, p_max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -553,7 +553,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool const hasChange = ImGui::SliderScalar("##sliderScalar", data_type, &value, &min, &max, displayFormat, flags); + bool const hasChange = ImGui::SliderScalar("##", data_type, &value, &min, &max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -587,8 +587,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - ImGui::SetNextItemWidth(ImGui::CalcTextSize(displayFormat).x + ImGui::GetStyle().ItemInnerSpacing.x * 2.0f); - bool const hasChange = ImGui::SliderFloat("##sliderFloat", &value, min, max, displayFormat, flags); + bool const hasChange = ImGui::SliderFloat("##", &value, min, max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -622,7 +621,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool const hasChange = ImGui::SliderInt("##sliderInt", &value, min, max, displayFormat, flags); + bool const hasChange = ImGui::SliderInt("##", &value, min, max, displayFormat, flags); static bool startRecording = false; if (hasChange) { diff --git a/SHADE_Engine/src/Math/Geometry/SHBox.cpp b/SHADE_Engine/src/Math/Geometry/SHBox.cpp index a52cf0d2..cf094a9d 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBox.cpp +++ b/SHADE_Engine/src/Math/Geometry/SHBox.cpp @@ -1,5 +1,5 @@ /**************************************************************************************** - * \file SHBox.cpp + * \file SHBoundingBox.cpp * \author Diren D Bharwani, diren.dbharwani, 390002520 * \brief Implementation for a 3-Dimensional Axis Aligned Bounding Box * diff --git a/SHADE_Engine/src/Math/Geometry/SHBox.h b/SHADE_Engine/src/Math/Geometry/SHBox.h index 19c80bd2..0ea950ab 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBox.h +++ b/SHADE_Engine/src/Math/Geometry/SHBox.h @@ -1,5 +1,5 @@ /**************************************************************************************** - * \file SHBox.h + * \file SHBoundingBox.h * \author Diren D Bharwani, diren.dbharwani, 390002520 * \brief Interface for a 3-Dimensional Axis Aligned Bounding Box * @@ -79,17 +79,17 @@ namespace SHADE [[nodiscard]] bool TestPoint (const SHVec3& point) noexcept override; [[nodiscard]] bool Raycast (const SHRay& ray, float& distance) noexcept override; - [[nodiscard]] bool Contains (const SHBox& rhs) const noexcept; - [[nodiscard]] float Volume () const noexcept; - [[nodiscard]] float SurfaceArea () const noexcept; + [[nodiscard]] bool Contains (const SHBox& rhs) const noexcept; + [[nodiscard]] float Volume () const noexcept; + [[nodiscard]] float SurfaceArea () const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] static SHBox Combine (const SHBox& lhs, const SHBox& rhs) noexcept; - [[nodiscard]] static bool Intersect (const SHBox& lhs, const SHBox& rhs) noexcept; - [[nodiscard]] static SHBox BuildFromBoxes (const SHBox* boxes, size_t numBoxes) noexcept; + [[nodiscard]] static SHBox Combine (const SHBox& lhs, const SHBox& rhs) noexcept; + [[nodiscard]] static bool Intersect (const SHBox& lhs, const SHBox& rhs) noexcept; + [[nodiscard]] static SHBox BuildFromBoxes (const SHBox* boxes, size_t numBoxes) noexcept; [[nodiscard]] static SHBox BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept; private: diff --git a/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp b/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp index f16303f4..e8379b09 100644 --- a/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp +++ b/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp @@ -16,7 +16,6 @@ // Project Headers #include "Physics/PhysicsObject/SHPhysicsObject.h" #include "Physics/System/SHPhysicsSystem.h" -#include "Scene/SHSceneManager.h" /*-------------------------------------------------------------------------------------*/ /* Local Helper Functions */ @@ -81,15 +80,10 @@ namespace SHADE { for (auto eventIter = container.begin(); eventIter != container.end();) { - const SHCollisionInfo& C_INFO = *eventIter; + const bool CLEAR_EVENT = eventIter->GetCollisionState() == SHCollisionInfo::State::EXIT + || eventIter->GetCollisionState() == SHCollisionInfo::State::INVALID; - const bool CLEAR_EVENT = C_INFO.GetCollisionState() == SHCollisionInfo::State::EXIT - || C_INFO.GetCollisionState() == SHCollisionInfo::State::INVALID; - - const bool INACTIVE_OBJECT = !SHSceneManager::CheckNodeAndComponentsActive(C_INFO.GetEntityA()) - || !SHSceneManager::CheckNodeAndComponentsActive(C_INFO.GetEntityB()); - - if (CLEAR_EVENT || INACTIVE_OBJECT) + if (CLEAR_EVENT) eventIter = container.erase(eventIter); else ++eventIter; diff --git a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp index 14743845..e63895d5 100644 --- a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp @@ -304,9 +304,6 @@ namespace SHADE const auto* RHS_BOX = reinterpret_cast(rhs); shape = new SHBox{ positionOffset, RHS_BOX->GetWorldExtents() }; - auto* lhsBox = reinterpret_cast(shape); - lhsBox->SetRelativeExtents(RHS_BOX->GetRelativeExtents()); - break; } case Type::SPHERE: @@ -314,9 +311,6 @@ namespace SHADE const auto* RHS_SPHERE = reinterpret_cast(rhs); shape = new SHSphere{ positionOffset, RHS_SPHERE->GetWorldRadius() }; - auto* lhsSphere = reinterpret_cast(shape); - lhsSphere->SetRelativeRadius(RHS_SPHERE->GetRelativeRadius()); - break; } default: break; diff --git a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp index 28b6f842..765decd8 100644 --- a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp @@ -29,6 +29,7 @@ namespace SHADE SHRigidBodyComponent::SHRigidBodyComponent() noexcept : type { Type::DYNAMIC } + , interpolate { true } , flags { 0 } , dirtyFlags { std::numeric_limits::max() } , mass { 1.0f } @@ -39,7 +40,6 @@ namespace SHADE // Initialise default flags flags |= 1U << 0; // Gravity set to true flags |= 1U << 1; // Sleeping allowed - flags |= 1U << 8; // Interpolate by default } /*-----------------------------------------------------------------------------------*/ @@ -60,16 +60,7 @@ namespace SHADE bool SHRigidBodyComponent::IsInterpolating() const noexcept { - static constexpr int FLAG_POS = 8; - return flags & (1U << FLAG_POS); - } - - bool SHRigidBodyComponent::GetIsSleeping() const noexcept - { - if (auto* physicsObject = system->GetPhysicsObject(GetEID()); physicsObject) - return physicsObject->GetRigidBody()->isSleeping(); - - return false; + return interpolate; } SHRigidBodyComponent::Type SHRigidBodyComponent::GetType() const noexcept @@ -77,6 +68,21 @@ namespace SHADE return type; } + float SHRigidBodyComponent::GetMass() const noexcept + { + return mass; + } + + float SHRigidBodyComponent::GetDrag() const noexcept + { + return drag; + } + + float SHRigidBodyComponent::GetAngularDrag() const noexcept + { + return angularDrag; + } + bool SHRigidBodyComponent::GetFreezePositionX() const noexcept { static constexpr int FLAG_POS = 2; @@ -113,27 +119,6 @@ namespace SHADE return flags & (1U << FLAG_POS); } - //bool SHRigidBodyComponent::GetAutoMass() const noexcept - //{ - // static constexpr int FLAG_POS = 9; - // return flags & (1U << FLAG_POS); - //} - - float SHRigidBodyComponent::GetMass() const noexcept - { - return mass; - } - - float SHRigidBodyComponent::GetDrag() const noexcept - { - return drag; - } - - float SHRigidBodyComponent::GetAngularDrag() const noexcept - { - return angularDrag; - } - SHVec3 SHRigidBodyComponent::GetForce() const noexcept { if (auto* physicsObject = system->GetPhysicsObject(GetEID()); physicsObject) @@ -310,18 +295,9 @@ namespace SHADE void SHRigidBodyComponent::SetInterpolate(bool allowInterpolation) noexcept { - static constexpr int FLAG_POS = 8; - allowInterpolation ? flags |= 1U << FLAG_POS : flags &= ~(1U << FLAG_POS); + interpolate = allowInterpolation; } - //void SHRigidBodyComponent::SetAutoMass(bool autoMass) noexcept - //{ - // static constexpr int FLAG_POS = 9; - // autoMass ? flags |= 1U << FLAG_POS : flags &= ~(1U << FLAG_POS); - - // dirtyFlags |= 1U << FLAG_POS; - //} - void SHRigidBodyComponent::SetMass(float newMass) noexcept { static constexpr int FLAG_POS = 9; @@ -337,9 +313,6 @@ namespace SHADE dirtyFlags |= 1U << FLAG_POS; mass = newMass; - - // Turn off automass - flags &= ~(1U << FLAG_POS); } void SHRigidBodyComponent::SetDrag(float newDrag) noexcept @@ -494,8 +467,6 @@ RTTR_REGISTRATION .property("Angular Drag" , &SHRigidBodyComponent::GetAngularDrag , &SHRigidBodyComponent::SetAngularDrag ) .property("Use Gravity" , &SHRigidBodyComponent::IsGravityEnabled , &SHRigidBodyComponent::SetGravityEnabled ) .property("Interpolate" , &SHRigidBodyComponent::IsInterpolating , &SHRigidBodyComponent::SetInterpolate ) - .property("Sleeping Enabled" , &SHRigidBodyComponent::IsAllowedToSleep , &SHRigidBodyComponent::SetIsAllowedToSleep) - //.property("Auto Mass" , &SHRigidBodyComponent::GetAutoMass , &SHRigidBodyComponent::SetAutoMass ) .property("Freeze Position X" , &SHRigidBodyComponent::GetFreezePositionX , &SHRigidBodyComponent::SetFreezePositionX ) .property("Freeze Position Y" , &SHRigidBodyComponent::GetFreezePositionY , &SHRigidBodyComponent::SetFreezePositionY ) .property("Freeze Position Z" , &SHRigidBodyComponent::GetFreezePositionZ , &SHRigidBodyComponent::SetFreezePositionZ ) diff --git a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h index d5204d94..f7062f96 100644 --- a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h +++ b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.h @@ -71,22 +71,18 @@ namespace SHADE [[nodiscard]] bool IsAllowedToSleep () const noexcept; [[nodiscard]] bool IsInterpolating () const noexcept; - [[nodiscard]] bool GetIsSleeping () const noexcept; - [[nodiscard]] Type GetType () const noexcept; - - [[nodiscard]] bool GetFreezePositionX () const noexcept; - [[nodiscard]] bool GetFreezePositionY () const noexcept; - [[nodiscard]] bool GetFreezePositionZ () const noexcept; - [[nodiscard]] bool GetFreezeRotationX () const noexcept; - [[nodiscard]] bool GetFreezeRotationY () const noexcept; - [[nodiscard]] bool GetFreezeRotationZ () const noexcept; - - //[[nodiscard]] bool GetAutoMass () const noexcept; - [[nodiscard]] float GetMass () const noexcept; [[nodiscard]] float GetDrag () const noexcept; [[nodiscard]] float GetAngularDrag () const noexcept; + + [[nodiscard]] bool GetFreezePositionX () const noexcept; + [[nodiscard]] bool GetFreezePositionY () const noexcept; + [[nodiscard]] bool GetFreezePositionZ () const noexcept; + + [[nodiscard]] bool GetFreezeRotationX () const noexcept; + [[nodiscard]] bool GetFreezeRotationY () const noexcept; + [[nodiscard]] bool GetFreezeRotationZ () const noexcept; [[nodiscard]] SHVec3 GetForce () const noexcept; [[nodiscard]] SHVec3 GetTorque () const noexcept; @@ -112,7 +108,6 @@ namespace SHADE void SetFreezeRotationY (bool freezeRotationY) noexcept; void SetFreezeRotationZ (bool freezeRotationZ) noexcept; void SetInterpolate (bool allowInterpolation) noexcept; - //void SetAutoMass (bool autoMass) noexcept; void SetMass (float newMass) noexcept; void SetDrag (float newDrag) noexcept; @@ -149,7 +144,8 @@ namespace SHADE Type type; - uint16_t flags; // 0 0 0 0 0 0 am ip aZ aY aX lZ lY lX slp g + bool interpolate; + uint8_t flags; // aZ aY aX lZ lY lX slp g uint16_t dirtyFlags; // 0 0 0 0 aD d m t aZ aY aX lZ lY lX slp g float mass; diff --git a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp index 0a0ff201..a52d3899 100644 --- a/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp +++ b/SHADE_Engine/src/Physics/PhysicsObject/SHPhysicsObject.cpp @@ -109,17 +109,8 @@ namespace SHADE { // TODO(Diren): Add more collider shapes - case SHCollisionShape::Type::BOX: - { - addBoxShape(collisionShape); - break; - } - - case SHCollisionShape::Type::SPHERE: - { - addSphereShape(collisionShape); - break; - } + case SHCollisionShape::Type::BOX: addBoxShape(collisionShape); break; + case SHCollisionShape::Type::SPHERE: addSphereShape(collisionShape); break; default: break; } @@ -254,17 +245,9 @@ namespace SHADE } case 9: // Mass { - //if (component.GetAutoMass()) - //{ - // rp3dBody->updateMassPropertiesFromColliders(); - // component.mass = rp3dBody->getMass(); - //} - //else - //{ - rp3dBody->setMass(component.mass); - rp3dBody->updateLocalCenterOfMassFromColliders(); - rp3dBody->updateLocalInertiaTensorFromColliders(); - //} + rp3dBody->setMass(component.mass); + rp3dBody->updateLocalCenterOfMassFromColliders(); + rp3dBody->updateLocalInertiaTensorFromColliders(); break; } diff --git a/SHADE_Engine/src/Physics/SHPhysicsWorld.h b/SHADE_Engine/src/Physics/SHPhysicsWorld.h index c5152c44..091ae062 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsWorld.h +++ b/SHADE_Engine/src/Physics/SHPhysicsWorld.h @@ -38,8 +38,8 @@ namespace SHADE /*-------------------------------------------------------------------------------*/ SHVec3 gravity = SHVec3{ 0.0f, -9.81f, 0.0f }; - uint16_t numVelocitySolverIterations = 10; - uint16_t numPositionSolverIterations = 5; + uint16_t numVelocitySolverIterations = 15; + uint16_t numPositionSolverIterations = 8; bool sleepingEnabled = true; }; diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp index 7ccfb225..44875289 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.cpp @@ -24,7 +24,7 @@ namespace SHADE /* Static Data Member Definitions */ /*-----------------------------------------------------------------------------------*/ - const SHPhysicsDebugDrawSystem::DebugDrawFunction SHPhysicsDebugDrawSystem::drawFunctions[NUM_FLAGS] = + const SHPhysicsDebugDrawSystem::DebugDrawFunction SHPhysicsDebugDrawSystem::drawFunctions[SHPhysicsDebugDrawSystem::NUM_FLAGS] = { SHPhysicsDebugDrawSystem::drawColliders , SHPhysicsDebugDrawSystem::drawColliderAABBs @@ -33,8 +33,6 @@ namespace SHADE , SHPhysicsDebugDrawSystem::drawContactNormals }; - SHVec3 SHPhysicsDebugDrawSystem::boxVertices[NUM_BOX_VERTICES]; - /*-----------------------------------------------------------------------------------*/ /* Constructors & Destructor Definitions */ /*-----------------------------------------------------------------------------------*/ @@ -44,7 +42,7 @@ namespace SHADE , physicsSystem { nullptr } , rp3dDebugRenderer { nullptr } { - debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER)] = SHColour::GREEN; + debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER)] = debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER_AABB)] = SHColour::YELLOW; debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::BROAD_PHASE_AABB)] = SHColour::CYAN; debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_POINTS)] = SHColour::RED; @@ -97,9 +95,6 @@ namespace SHADE SHASSERT(physicsSystem == nullptr, "Non-existent physics system attached to the physics debug draw system!") physicsSystem = SHSystemManager::GetSystem(); - - // Generate shapes - generateBox(); } void SHPhysicsDebugDrawSystem::Exit() @@ -164,20 +159,21 @@ namespace SHADE } - void SHPhysicsDebugDrawSystem::generateBox() noexcept - { - boxVertices[0] = { 0.5f, 0.5f, -0.5f }; // TOP_RIGHT_BACK - boxVertices[1] = { -0.5f, 0.5f, -0.5f }; // TOP_LEFT_BACK - boxVertices[2] = { 0.5f, -0.5f, -0.5f }; // BTM_RIGHT_BACK - boxVertices[3] = { -0.5f, -0.5f, -0.5f }; // BTM_LEFT_BACK - boxVertices[4] = { 0.5f, 0.5f, 0.5f }; // TOP_RIGHT_FRONT - boxVertices[5] = { -0.5f, 0.5f, 0.5f }; // TOP_LEFT_FRONT - boxVertices[6] = { 0.5f, -0.5f, 0.5f }; // BTM_RIGHT_FRONT - boxVertices[7] = { -0.5f, -0.5f, 0.5f }; // BTM_LEFT_FRONT - } - void SHPhysicsDebugDrawSystem::debugDrawBox(const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept { + static constexpr uint32_t NUM_BOX_VERTICES = 8; + static const SHVec3 boxVertices[NUM_BOX_VERTICES] + { + { 0.5f, 0.5f, -0.5f } // TOP_RIGHT_BACK + , { -0.5f, 0.5f, -0.5f } // TOP_LEFT_BACK + , { 0.5f, -0.5f, -0.5f } // BTM_RIGHT_BACK + , { -0.5f, -0.5f, -0.5f } // BTM_LEFT_BACK + , { 0.5f, 0.5f, 0.5f } // TOP_RIGHT_FRONT + , { -0.5f, 0.5f, 0.5f } // TOP_LEFT_FRONT + , { 0.5f, -0.5f, 0.5f } // BTM_RIGHT_FRONT + , { -0.5f, -0.5f, 0.5f } // BTM_LEFT_FRONT + }; + auto* debugDrawSystem = SHSystemManager::GetSystem(); if (debugDrawSystem == nullptr) { @@ -188,16 +184,10 @@ namespace SHADE auto* BOX = reinterpret_cast(collisionShape.GetShape()); // Calculate final position & orientation - const SHVec3 COLLIDER_POS = colliderComponent.GetPosition(); - const SHVec3 BOX_POS = collisionShape.GetPositionOffset(); - const SHQuaternion COLLIDER_ROT = colliderComponent.GetOrientation(); - const SHQuaternion BOX_ROT = SHQuaternion::FromEuler(collisionShape.GetRotationOffset()); + const SHVec3 FINAL_POS = colliderComponent.GetPosition() + collisionShape.GetPositionOffset(); + const SHQuaternion FINAL_ROT = colliderComponent.GetOrientation() * SHQuaternion::FromEuler(collisionShape.GetRotationOffset()); - - const SHMatrix COLLIDER_TR = SHMatrix::Rotate(COLLIDER_ROT) * SHMatrix::Translate(COLLIDER_POS); - const SHMatrix BOX_TRS = SHMatrix::Scale(BOX->GetWorldExtents() * 2.0f) * SHMatrix::Rotate(BOX_ROT) * SHMatrix::Translate(BOX_POS); - - const SHMatrix FINAL_TRS = BOX_TRS * COLLIDER_TR; + const SHMatrix BOX_TRS = SHMatrix::Scale(BOX->GetWorldExtents() * 2.0f) * SHMatrix::Rotate(FINAL_ROT) * SHMatrix::Translate(FINAL_POS); const SHColour COLLIDER_COLOUR = collisionShape.IsTrigger() ? SHColour::PURPLE : SHColour::GREEN; @@ -207,8 +197,8 @@ namespace SHADE const uint32_t IDX1 = i; const uint32_t IDX2 = i + NUM_BOX_VERTICES / 2; - transformedVertices[IDX1] = SHVec3::Transform(boxVertices[IDX1], FINAL_TRS); - transformedVertices[IDX2] = SHVec3::Transform(boxVertices[IDX2], FINAL_TRS); + transformedVertices[IDX1] = SHVec3::Transform(boxVertices[IDX1], BOX_TRS); + transformedVertices[IDX2] = SHVec3::Transform(boxVertices[IDX2], BOX_TRS); // Draw 4 line to connect the quads debugDrawSystem->DrawLine(COLLIDER_COLOUR, transformedVertices[IDX1], transformedVertices[IDX2]); @@ -217,7 +207,6 @@ namespace SHADE // A, B, C, D std::array backQuad { transformedVertices[0], transformedVertices[1], transformedVertices[3], transformedVertices[2] }; debugDrawSystem->DrawPoly(COLLIDER_COLOUR, backQuad.begin(), backQuad.end()); - // E, F, G, H std::array frontQuad { transformedVertices[4], transformedVertices[5], transformedVertices[7], transformedVertices[6] }; debugDrawSystem->DrawPoly(COLLIDER_COLOUR, frontQuad.begin(), frontQuad.end()); @@ -237,10 +226,8 @@ namespace SHADE const SHColour COLLIDER_COLOUR = collisionShape.IsTrigger() ? SHColour::PURPLE : SHColour::GREEN; // Calculate final position & orientation - const SHQuaternion FINAL_ROT = colliderComponent.GetOrientation() * SHQuaternion::FromEuler(collisionShape.GetRotationOffset()); - const SHMatrix TR = SHMatrix::Rotate(FINAL_ROT) * SHMatrix::Translate(colliderComponent.GetPosition()); - - debugDrawSystem->DrawSphere(COLLIDER_COLOUR, SHVec3::Transform(collisionShape.GetPositionOffset(), TR), SPHERE->GetWorldRadius()); + const SHVec3 FINAL_POS = colliderComponent.GetPosition() + collisionShape.GetPositionOffset(); + debugDrawSystem->DrawSphere(COLLIDER_COLOUR, FINAL_POS, SPHERE->GetWorldRadius()); } } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h index 149ed6c1..390e3d69 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h +++ b/SHADE_Engine/src/Physics/System/SHPhysicsDebugDrawSystem.h @@ -97,38 +97,25 @@ namespace SHADE /* Data Members */ /*---------------------------------------------------------------------------------*/ - static constexpr int NUM_FLAGS = SHUtilities::ConvertEnum(DebugDrawFlags::NUM_FLAGS); + static constexpr int NUM_FLAGS = SHUtilities::ConvertEnum(DebugDrawFlags::NUM_FLAGS); + static const DebugDrawFunction drawFunctions[NUM_FLAGS]; - // SHAPES INFO - - static constexpr size_t NUM_BOX_VERTICES = 8; - static SHVec3 boxVertices[NUM_BOX_VERTICES]; - - - uint8_t debugDrawFlags; - SHPhysicsSystem* physicsSystem; - rp3d::DebugRenderer* rp3dDebugRenderer; - SHColour debugColours[NUM_FLAGS]; + uint8_t debugDrawFlags; + SHPhysicsSystem* physicsSystem; + rp3d::DebugRenderer* rp3dDebugRenderer; + SHColour debugColours[NUM_FLAGS]; /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ - // Generic Draw Functions - static void drawColliders (rp3d::DebugRenderer* debugRenderer) noexcept; static void drawColliderAABBs (rp3d::DebugRenderer* debugRenderer) noexcept; static void drawBroadPhaseAABBs (rp3d::DebugRenderer* debugRenderer) noexcept; static void drawContactPoints (rp3d::DebugRenderer* debugRenderer) noexcept; static void drawContactNormals (rp3d::DebugRenderer* debugRenderer) noexcept; - // Shape Generation Functions - - static void generateBox () noexcept; - - // Shape Draw Functions - static void debugDrawBox (const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept; static void debugDrawSphere (const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept; }; diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index 50590e04..33ba88e7 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -154,32 +154,14 @@ namespace SHADE auto* rigidBodyComponent = SHComponentManager::GetComponent_s(entityID); auto* colliderComponent = SHComponentManager::GetComponent_s(entityID); - const auto& CURRENT_TF = physicsObject.GetRigidBody()->getTransform(); - const auto& RENDER_POS = CURRENT_TF.getPosition(); - const auto& RENDER_ROT = CURRENT_TF.getOrientation(); - - // Cache transform - physicsObject.prevTransform = CURRENT_TF; - - // Sync with physics components - if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(entityID)) - { - rigidBodyComponent->position = RENDER_POS; - rigidBodyComponent->orientation = RENDER_ROT; - } - - if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive(entityID)) - { - colliderComponent->position = RENDER_POS; - colliderComponent->orientation = RENDER_ROT; - } - - // Set transform for rendering - if (transformComponent) - { - transformComponent->SetWorldPosition(RENDER_POS); - transformComponent->SetWorldOrientation(RENDER_ROT); - } + postUpdateSyncTransforms + ( + physicsObject + , transformComponent + , rigidBodyComponent + , colliderComponent + , 1.0 // We use 1.0 here to avoid any interpolation + ); } } @@ -355,4 +337,93 @@ namespace SHADE return onStopEvent->handle; } + void SHPhysicsSystem::preUpdateSyncTransform + ( + SHPhysicsObject& physicsObject + , SHTransformComponent* transformComponent + , SHRigidBodyComponent* rigidBodyComponent + , SHColliderComponent* colliderComponent + ) noexcept + { + if (!transformComponent) + return; + + const SHVec3& WORLD_POS = transformComponent->GetWorldPosition(); + const SHQuaternion& WORLD_ROT = transformComponent->GetWorldOrientation(); + const SHVec3& WORLD_SCL = transformComponent->GetWorldScale(); + + const rp3d::Transform RP3D_TRANSFORM { WORLD_POS, WORLD_ROT }; + physicsObject.GetRigidBody()->setTransform(RP3D_TRANSFORM); + + if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) + { + rigidBodyComponent->position = WORLD_POS; + rigidBodyComponent->orientation = WORLD_ROT; + } + + if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) + { + colliderComponent->position = WORLD_POS; + colliderComponent->orientation = WORLD_ROT; + colliderComponent->scale = WORLD_SCL; + + colliderComponent->RecomputeCollisionShapes(); + } + } + + void SHPhysicsSystem::postUpdateSyncTransforms + ( + SHPhysicsObject& physicsObject + , SHTransformComponent* transformComponent + , SHRigidBodyComponent* rigidBodyComponent + , SHColliderComponent* colliderComponent + , double interpolationFactor + ) noexcept + { + const rp3d::Transform& CURRENT_TF = physicsObject.GetRigidBody()->getTransform(); + auto renderPos = CURRENT_TF.getPosition(); + auto renderRot = CURRENT_TF.getOrientation(); + + // Cache transforms + if (physicsObject.GetRigidBody()->isActive()) + physicsObject.prevTransform = CURRENT_TF; + + // Sync with rigid bodies + if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) + { + // Skip static bodies + if (rigidBodyComponent->GetType() == SHRigidBodyComponent::Type::STATIC) + return; + + // Check if transform should be interpolated + if (rigidBodyComponent->IsInterpolating()) + { + // Interpolate transforms between current and predicted next transform + + const rp3d::Transform PREV_TF = physicsObject.prevTransform; + const rp3d::Transform INTERPOLATED_TF = rp3d::Transform::interpolateTransforms(PREV_TF, CURRENT_TF, static_cast(interpolationFactor)); + + renderPos = INTERPOLATED_TF.getPosition(); + renderRot = INTERPOLATED_TF.getOrientation(); + } + + rigidBodyComponent->position = CURRENT_TF.getPosition(); + rigidBodyComponent->orientation = CURRENT_TF.getOrientation(); + } + + // Sync with colliders + if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) + { + colliderComponent->position = CURRENT_TF.getPosition(); + colliderComponent->orientation = CURRENT_TF.getOrientation(); + } + + // Set transform for rendering + if (transformComponent) + { + transformComponent->SetWorldPosition(renderPos); + transformComponent->SetWorldOrientation(renderRot); + } + } + } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h index 9638e05c..3da7094b 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h @@ -113,14 +113,6 @@ namespace SHADE void syncRigidBodyActive (EntityID eid, SHPhysicsObject& physicsObject) const noexcept; void syncColliderActive (EntityID eid, SHPhysicsObject& physicsObject) const noexcept; static void syncOnPlay (EntityID eid, SHPhysicsObject& physicsObject) noexcept; - - static void preUpdateSyncTransform - ( - SHPhysicsObject& physicsObject - , SHTransformComponent* transformComponent - , SHRigidBodyComponent* rigidBodyComponent - , SHColliderComponent* colliderComponent - ) noexcept; }; class SH_API PhysicsFixedUpdate final : public SHFixedSystemRoutine @@ -153,21 +145,6 @@ namespace SHADE /*-------------------------------------------------------------------------------*/ void Execute(double dt) noexcept override; - - private: - - /*-------------------------------------------------------------------------------*/ - /* Function Members */ - /*-------------------------------------------------------------------------------*/ - - static void postUpdateSyncTransforms - ( - SHPhysicsObject& physicsObject - , SHTransformComponent* transformComponent - , SHRigidBodyComponent* rigidBodyComponent - , SHColliderComponent* colliderComponent - , double interpolationFactor - ) noexcept; }; private: @@ -201,5 +178,24 @@ namespace SHADE SHEventHandle onPlay (SHEventPtr onPlayEvent); SHEventHandle onStop (SHEventPtr onStopEvent); + + + static void preUpdateSyncTransform + ( + SHPhysicsObject& physicsObject + , SHTransformComponent* transformComponent + , SHRigidBodyComponent* rigidBodyComponent + , SHColliderComponent* colliderComponent + ) noexcept; + + static void postUpdateSyncTransforms + ( + SHPhysicsObject& physicsObject + , SHTransformComponent* transformComponent + , SHRigidBodyComponent* rigidBodyComponent + , SHColliderComponent* colliderComponent + , double interpolationFactor + ) noexcept; + }; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index 9d860bf9..3e56ca14 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -262,94 +262,4 @@ namespace SHADE if (colliderComponent) physicsObject.SyncColliders(*colliderComponent); } - - void SHPhysicsSystem::PhysicsPreUpdate::preUpdateSyncTransform - ( - SHPhysicsObject& physicsObject - , SHTransformComponent* transformComponent - , SHRigidBodyComponent* rigidBodyComponent - , SHColliderComponent* colliderComponent - ) noexcept - { - if (!transformComponent) - return; - - const SHVec3& WORLD_POS = transformComponent->GetWorldPosition(); - const SHQuaternion& WORLD_ROT = transformComponent->GetWorldOrientation(); - const SHVec3& WORLD_SCL = transformComponent->GetWorldScale(); - - const rp3d::Transform RP3D_TRANSFORM { WORLD_POS, WORLD_ROT }; - physicsObject.GetRigidBody()->setTransform(RP3D_TRANSFORM); - physicsObject.prevTransform = RP3D_TRANSFORM; - - if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) - { - rigidBodyComponent->position = WORLD_POS; - rigidBodyComponent->orientation = WORLD_ROT; - } - - if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) - { - colliderComponent->position = WORLD_POS; - colliderComponent->orientation = WORLD_ROT; - colliderComponent->scale = WORLD_SCL; - - colliderComponent->RecomputeCollisionShapes(); - } - } - - void SHPhysicsSystem::PhysicsPostUpdate::postUpdateSyncTransforms - ( - SHPhysicsObject& physicsObject - , SHTransformComponent* transformComponent - , SHRigidBodyComponent* rigidBodyComponent - , SHColliderComponent* colliderComponent - , double interpolationFactor - ) noexcept - { - const rp3d::Transform& CURRENT_TF = physicsObject.GetRigidBody()->getTransform(); - auto renderPos = CURRENT_TF.getPosition(); - auto renderRot = CURRENT_TF.getOrientation(); - - // Cache transforms - if (physicsObject.GetRigidBody()->isActive()) - physicsObject.prevTransform = CURRENT_TF; - - // Sync with rigid bodies - if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) - { - // Skip static bodies - if (rigidBodyComponent->GetType() == SHRigidBodyComponent::Type::STATIC) - return; - - // Check if transform should be interpolated - if (rigidBodyComponent->IsInterpolating()) - { - // Interpolate transforms between current and predicted next transform - - const rp3d::Transform PREV_TF = physicsObject.prevTransform; - const rp3d::Transform INTERPOLATED_TF = rp3d::Transform::interpolateTransforms(PREV_TF, CURRENT_TF, static_cast(interpolationFactor)); - - renderPos = INTERPOLATED_TF.getPosition(); - renderRot = INTERPOLATED_TF.getOrientation(); - } - - rigidBodyComponent->position = CURRENT_TF.getPosition(); - rigidBodyComponent->orientation = CURRENT_TF.getOrientation(); - } - - // Sync with colliders - if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) - { - colliderComponent->position = CURRENT_TF.getPosition(); - colliderComponent->orientation = CURRENT_TF.getOrientation(); - } - - // Set transform for rendering - if (transformComponent) - { - transformComponent->SetWorldPosition(renderPos); - transformComponent->SetWorldOrientation(renderRot); - } - } } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index e0b87bea..84b50373 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -58,10 +58,9 @@ namespace SHADE loadFunctions(); // Generate script assembly if it hasn't been before - if (!fileExists(std::string(MANAGED_SCRIPT_LIB_NAME) + ".dll")) - { - BuildScriptAssembly(); - } +#ifndef _PUBLISH + BuildScriptAssembly(); +#endif // Initialise the CSharp Engine csEngineInit(); diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 3ed96d7d..6933fbb5 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -12,8 +12,8 @@ #include "Assets/Asset Types/SHSceneAsset.h" #include "Camera/SHCameraComponent.h" -#include "Math/Transform/SHTransformComponent.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" +#include "Math/Transform/SHTransformComponent.h" #include "Physics/Interface/SHRigidBodyComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" diff --git a/SHADE_Managed/src/Components/Collider.cxx b/SHADE_Managed/src/Components/Collider.cxx index 41910d66..1a53f9e1 100644 --- a/SHADE_Managed/src/Components/Collider.cxx +++ b/SHADE_Managed/src/Components/Collider.cxx @@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { /*---------------------------------------------------------------------------------*/ - /* CollisionShape - Constructors */ + /* ColliderBound - Constructors */ /*---------------------------------------------------------------------------------*/ CollisionShape::CollisionShape(int arrayIdx, Entity attachedEntity) : arrayIndex { arrayIdx } @@ -28,183 +28,102 @@ namespace SHADE {} /*---------------------------------------------------------------------------------*/ - /* CollisionShape - Properties */ - /*---------------------------------------------------------------------------------*/ - - bool CollisionShape::IsTrigger::get() - { - return getNativeCollisionShape().IsTrigger(); - } - - void CollisionShape::IsTrigger::set(bool value) - { - getNativeCollisionShape().SetIsTrigger(value); - } - - Vector3 CollisionShape::PositionOffset::get() - { - return Convert::ToCLI(getNativeCollisionShape().GetPositionOffset()); - } - - void CollisionShape::PositionOffset::set(Vector3 value) - { - getNativeCollisionShape().SetPositionOffset(Convert::ToNative(value)); - } - - Vector3 CollisionShape::RotationOffset::get() - { - return Convert::ToCLI(getNativeCollisionShape().GetRotationOffset()); - } - - void CollisionShape::RotationOffset::set(Vector3 value) - { - getNativeCollisionShape().SetRotationOffset(Convert::ToNative(value)); - } - - float CollisionShape::Friction::get() - { - return getNativeCollisionShape().GetFriction(); - } - - void CollisionShape::Friction::set(float value) - { - getNativeCollisionShape().SetFriction(value); - } - - float CollisionShape::Bounciness::get() - { - return getNativeCollisionShape().GetBounciness(); - } - - void CollisionShape::Bounciness::set(float value) - { - getNativeCollisionShape().SetBounciness(value); - } - - float CollisionShape::Density::get() - { - return getNativeCollisionShape().GetDensity(); - } - - void CollisionShape::Density::set(float value) - { - getNativeCollisionShape().SetDensity(value); - } - - /*---------------------------------------------------------------------------------*/ - /* CollisionShape - helper Functions */ + /* ColliderBound - Setter Functions */ /*---------------------------------------------------------------------------------*/ void CollisionShape::updateArrayIndex(int index) { arrayIndex = index; } - SHCollisionShape& SHADE::CollisionShape::getNativeCollisionShape() - { - SHColliderComponent* collider = SHComponentManager::GetComponent_s(entity); - if (!collider) - throw gcnew System::InvalidOperationException("Unable to retrieve Collider component!"); - - try - { - auto& shape = collider->GetCollisionShape(arrayIndex); - return shape; - } - catch (std::invalid_argument&) - { - throw gcnew System::IndexOutOfRangeException("Attempted to retrieve out of range CollisionShape!"); - } - } - /*---------------------------------------------------------------------------------*/ - /* BoxCollider - Constructors */ + /* BoxColliderBound - Constructors */ /*---------------------------------------------------------------------------------*/ BoxCollider::BoxCollider(int arrayIdx, Entity attachedEntity) : CollisionShape { arrayIndex, attachedEntity } {} /*---------------------------------------------------------------------------------*/ - /* BoxCollider - Properties */ + /* BoxColliderBound - Properties */ /*---------------------------------------------------------------------------------*/ Vector3 BoxCollider::Center::get() { - return Convert::ToCLI(getNativeCollisionShape().GetCenter()); + return Convert::ToCLI(getNativeBoundObject().GetCenter()); } void BoxCollider::Center::set(Vector3 value) { - getNativeCollisionShape().SetCenter(Convert::ToNative(value)); + getNativeBoundObject().SetCenter(Convert::ToNative(value)); } Vector3 BoxCollider::HalfExtents::get() { - return Convert::ToCLI(getNativeCollisionShape().GetWorldExtents()); + return Convert::ToCLI(getNativeBoundObject().GetWorldExtents()); } void BoxCollider::HalfExtents::set(Vector3 value) { - getNativeCollisionShape().SetWorldExtents(Convert::ToNative(value)); + getNativeBoundObject().SetWorldExtents(Convert::ToNative(value)); } Vector3 BoxCollider::Min::get() { - return Convert::ToCLI(getNativeCollisionShape().GetMin()); + return Convert::ToCLI(getNativeBoundObject().GetMin()); } void BoxCollider::Min::set(Vector3 value) { - getNativeCollisionShape().SetMin(Convert::ToNative(value)); + getNativeBoundObject().SetMin(Convert::ToNative(value)); } Vector3 BoxCollider::Max::get() { - return Convert::ToCLI(getNativeCollisionShape().GetMax()); + return Convert::ToCLI(getNativeBoundObject().GetMax()); } void BoxCollider::Max::set(Vector3 value) { - getNativeCollisionShape().SetMax(Convert::ToNative(value)); + getNativeBoundObject().SetMax(Convert::ToNative(value)); } /*---------------------------------------------------------------------------------*/ - /* BoxCollider - Usage Functions */ + /* BoxColliderBound - Usage Functions */ /*---------------------------------------------------------------------------------*/ bool BoxCollider::TestPoint(Vector3 point) { - return getNativeCollisionShape().TestPoint(Convert::ToNative(point)); + return getNativeBoundObject().TestPoint(Convert::ToNative(point)); } bool BoxCollider::Raycast(Ray ray, float maxDistance) { - return getNativeCollisionShape().Raycast(Convert::ToNative(ray), maxDistance); + return getNativeBoundObject().Raycast(Convert::ToNative(ray), maxDistance); } /*---------------------------------------------------------------------------------*/ - /* SphereCollider - Properties */ + /* BoxColliderBound - Properties */ /*---------------------------------------------------------------------------------*/ Vector3 SphereCollider::Center::get() { - return Convert::ToCLI(getNativeCollisionShape().GetCenter()); + return Convert::ToCLI(getNativeBoundObject().GetCenter()); } void SphereCollider::Center::set(Vector3 value) { - getNativeCollisionShape().SetCenter(Convert::ToNative(value)); + getNativeBoundObject().SetCenter(Convert::ToNative(value)); } float SphereCollider::Radius::get() { - return getNativeCollisionShape().GetWorldRadius(); + return getNativeBoundObject().GetWorldRadius(); } void SphereCollider::Radius::set(float value) { - getNativeCollisionShape().SetWorldRadius(value); + getNativeBoundObject().SetWorldRadius(value); } /*---------------------------------------------------------------------------------*/ - /* SphereCollider - Usage Functions */ + /* SphereColliderBound - Usage Functions */ /*---------------------------------------------------------------------------------*/ bool SphereCollider::TestPoint(Vector3 point) { - return getNativeCollisionShape().TestPoint(Convert::ToNative(point)); + return getNativeBoundObject().TestPoint(Convert::ToNative(point)); } bool SphereCollider::Raycast(Ray ray, float maxDistance) { - return getNativeCollisionShape().Raycast(Convert::ToNative(ray), maxDistance); + return getNativeBoundObject().Raycast(Convert::ToNative(ray), maxDistance); } /*---------------------------------------------------------------------------------*/ - /* SphereCollider - Constructors */ + /* SphereColliderBound - Constructors */ /*---------------------------------------------------------------------------------*/ SphereCollider::SphereCollider(int arrayIndex, Entity attachedEntity) : CollisionShape{ arrayIndex, attachedEntity } @@ -235,7 +154,7 @@ namespace SHADE } /*---------------------------------------------------------------------------------*/ - /* Collider - Collider Functions */ + /* Collider - ColliderBound Functions */ /*---------------------------------------------------------------------------------*/ CollisionShape^ Collider::GetCollisionShape(int index) { @@ -247,7 +166,7 @@ namespace SHADE // Check if valid if (index < 0 || index >= subColliderList->Count) - throw gcnew System::ArgumentException("[Collider] Invalid index for Collision Shape retrieval."); + throw gcnew System::ArgumentException("[Collider] Invalid index for Collider Bound retrieval."); // Return the bound return subColliderList[index]; @@ -298,7 +217,7 @@ namespace SHADE { collidersList->Remove(wr); } - SAFE_NATIVE_CALL_END("Collider.OnCollisionShapeChanged") + SAFE_NATIVE_CALL_END("Collider.OnColliderBoundChanged") } void Collider::updateSubColliderList() diff --git a/SHADE_Managed/src/Components/Collider.h++ b/SHADE_Managed/src/Components/Collider.h++ index 8ea648aa..6e165619 100644 --- a/SHADE_Managed/src/Components/Collider.h++ +++ b/SHADE_Managed/src/Components/Collider.h++ @@ -19,7 +19,7 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { template - CollisionShapeType& SHADE::CollisionShape::getNativeCollisionShape() + CollisionShapeType& SHADE::CollisionShape::getNativeBoundObject() { SHColliderComponent* collider = SHComponentManager::GetComponent_s(entity); if (!collider) @@ -29,13 +29,13 @@ namespace SHADE { auto& shape = collider->GetCollisionShape(arrayIndex); if (shape.GetType() != SHCollisionShape::Type::BOX) - throw gcnew System::InvalidOperationException("Attempted to retrieve invalid CollisionShape."); + throw gcnew System::InvalidOperationException("Attempted to retrieve invalid ColliderBound."); return reinterpret_cast(shape); } catch (std::invalid_argument&) { - throw gcnew System::IndexOutOfRangeException("Attempted to retrieve out of range CollisionShape!"); + throw gcnew System::IndexOutOfRangeException("Attempted to retrieve out of range ColliderBound!"); } } } diff --git a/SHADE_Managed/src/Components/Collider.hxx b/SHADE_Managed/src/Components/Collider.hxx index a649483f..1711e8b9 100644 --- a/SHADE_Managed/src/Components/Collider.hxx +++ b/SHADE_Managed/src/Components/Collider.hxx @@ -30,61 +30,6 @@ namespace SHADE public ref class CollisionShape abstract { public: - /*-----------------------------------------------------------------------------*/ - /* Properties */ - /*-----------------------------------------------------------------------------*/ - - /// - /// Whether or not this CollisionShape is a trigger. - /// - property bool IsTrigger - { - bool get(); - void set(bool value); - } - /// - /// The positional offset of this collision shape from the transform's position. - /// - property Vector3 PositionOffset - { - Vector3 get(); - void set(Vector3 value); - } - /// - /// The rotational offset of this collision shape from the transform's rotation. - /// - property Vector3 RotationOffset - { - Vector3 get(); - void set(Vector3 value); - } - - // TODO(Diren): Swap this to Physics Materials once asset implementation for that is done - /// - /// The frictional coefficient of the shape. Clamped between 0 and 1. - /// - property float Friction - { - float get(); - void set(float value); - } - /// - /// The bounciness factor of the shape. Clamped between 0 and 1. - /// - property float Bounciness - { - float get(); - void set(float value); - } - /// - /// The mass density of this shape. Cannot be negative. - /// - property float Density - { - float get(); - void set(float value); - } - /*-----------------------------------------------------------------------------*/ /* Usage Functions */ /*-----------------------------------------------------------------------------*/ @@ -111,25 +56,20 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - int arrayIndex; // Index into the colliders vector on the native object - Entity entity; // Entity holding the collider component that this collider bounds is on + int arrayIndex; // Index into the colliders vector on the native object + Entity entity; // Entity holding the collider component that this collider bounds is on /*-----------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------*/ template - CollisionShapeType& getNativeCollisionShape(); + CollisionShapeType& getNativeBoundObject(); internal: /*-----------------------------------------------------------------------------*/ /* Setter Functions */ /*-----------------------------------------------------------------------------*/ void updateArrayIndex(int index); - - /*-----------------------------------------------------------------------------*/ - /* Helper Functions */ - /*-----------------------------------------------------------------------------*/ - SHCollisionShape& getNativeCollisionShape(); }; /// @@ -265,18 +205,18 @@ namespace SHADE /* Usage Functions */ /*-----------------------------------------------------------------------------*/ /// - /// Retrieves a CollisionShape at the specified index in the CollisionShapes list. + /// Retrieves a ColliderBound at the specified index in the ColliderBound list. /// /// Index to retrieve a ColliderBound from. /// ColliderBound for the specified index. CollisionShape^ GetCollisionShape(int index); /// - /// Retrieves a CollisionShape at the specified index in the CollisionShapes list + /// Retrieves a ColliderBound at the specified index in the ColliderBound list /// and casts it to the appropriate type. /// - /// Type of the CollisionShape to cast to. - /// Index to retrieve a CollisionShape from. - /// CollisionShape for the specified index. + /// Type of the ColliderBound to cast to. + /// Index to retrieve a ColliderBound from. + /// ColliderBound for the specified index. generic where T:CollisionShape T GetCollisionShape(int index);