diff --git a/Editor/src/ComponentsPanel/CharacterControllerPanel.h b/Editor/src/ComponentsPanel/CharacterControllerPanel.h new file mode 100644 index 00000000..645611f3 --- /dev/null +++ b/Editor/src/ComponentsPanel/CharacterControllerPanel.h @@ -0,0 +1,48 @@ +#pragma once +#include "ComponentPanel.h" +#include +#include + +class CharacterControllerPanel : ComponentPanel { + +public: + CharacterControllerPanel() {} + + void Draw(Nuake::Entity entity) override + { + if (!entity.HasComponent()) + return; + + auto& component = entity.GetComponent(); + BeginComponentTable(CHARACTER CONTROLLER, Nuake::CharacterControllerComponent); + { + { + ImGui::Text("Height"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##Height", &component.Height, 0.01f, 0.1f, 100.0f); + ImGui::TableNextColumn(); + ComponentTableReset(component.Height, 1.0f) + } + ImGui::TableNextColumn(); + { + ImGui::Text("Radius"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##Radius", &component.Radius, 0.01f, 0.1f, 10.0f); + ImGui::TableNextColumn(); + ComponentTableReset(component.Radius, 0.25f) + } + ImGui::TableNextColumn(); + { + ImGui::Text("Mass"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##Mass", &component.Mass, 0.001f, 0.00001f, 10.0f); + ImGui::TableNextColumn(); + ComponentTableReset(component.Mass, 0.001f) + } + } + EndComponentTable() + } +}; \ No newline at end of file diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index a25845f5..4c5dc429 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -102,255 +102,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) mBoxColliderPanel.Draw(entity); mSphereColliderPanel.Draw(entity); mMeshColliderPanel.Draw(entity); - - /* - if (Selection.Entity.HasComponent()) - { - std::string icon = ICON_FA_MALE; - if (ImGui::CollapsingHeader((icon + " " + "Mesh").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Mesh properties"); - auto& component = Selection.Entity.GetComponent(); - // Path - std::string path = component.ModelPath; - char pathBuffer[256]; - - memset(pathBuffer, 0, sizeof(pathBuffer)); - std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer)); - - std::string oldPath = component.ModelPath; - ImGui::Text("Model: "); - ImGui::SameLine(); - if (ImGui::InputText("##ModelPath", pathBuffer, sizeof(pathBuffer))) - path = FileSystem::AbsoluteToRelative(std::string(pathBuffer)); - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Model")) - { - char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 256); - path = FileSystem::AbsoluteToRelative(fullPath); - } - ImGui::EndDragDropTarget(); - } - - if (component.ModelPath != path) - { - component.ModelPath = path; - component.LoadModel(); - } - - ImGui::SameLine(); - - if (ImGui::Button("Reimport")) - { - component.LoadModel(); - } - - ImGui::Indent(16.0f); - if (ImGui::CollapsingHeader("Meshes")) - { - ImGui::Indent(16.0f); - uint16_t index = 0; - for (auto& m : component.meshes) - { - if (ImGui::CollapsingHeader(std::to_string(index).c_str())) - { - std::string materialName = "No material"; - if (m->m_Material) - materialName = m->m_Material->GetName(); - - ImGui::Indent(16.0f); - if (ImGui::CollapsingHeader(materialName.c_str())) - { - //if (ImGui::BeginChild("Material child", ImVec2(0, 0), true, ImGuiWindowFlags_AlwaysAutoResize)) - //{ - ImGui::Indent(16.0f); - DrawMaterialEditor(m->m_Material); - //} - //ImGui::EndChild(); - } - - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Material")) - { - char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 256); - path = FileSystem::AbsoluteToRelative(fullPath); - } - ImGui::EndDragDropTarget(); - } - } - - index++; - } - - } - - ImGui::Separator(); - } - - } - - - - if (Selection.Entity.HasComponent()) { - std::string icon = ICON_FA_FILE; - if (ImGui::CollapsingHeader((icon + " " + "Wren Script").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Script properties"); - auto& component = Selection.Entity.GetComponent(); - - // Path - std::string path = component.Script; - char pathBuffer[256]; - - memset(pathBuffer, 0, sizeof(pathBuffer)); - std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer)); - - ImGui::Text("Script: "); - ImGui::SameLine(); - if (ImGui::InputText("##ScriptPath", pathBuffer, sizeof(pathBuffer))) - path = FileSystem::AbsoluteToRelative(std::string(pathBuffer)); - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script")) - { - char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 256); - path = FileSystem::AbsoluteToRelative(fullPath); - } - ImGui::EndDragDropTarget(); - } - - - component.Script = path; - - // Class - std::string module = component.Class; - - char classBuffer[256]; - - memset(classBuffer, 0, sizeof(classBuffer)); - std::strncpy(classBuffer, module.c_str(), sizeof(classBuffer)); - - ImGui::Text("Class: "); - ImGui::SameLine(); - if (ImGui::InputText("##ScriptModule", classBuffer, sizeof(classBuffer))) - module = std::string(classBuffer); - - component.Class = module; - ImGui::Separator(); - } - } - - if (Selection.Entity.HasComponent()) { - - std::string icon = ICON_FA_LIGHTBULB; - if (ImGui::CollapsingHeader((icon + " " + "Camera").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Camera properties"); - Selection.Entity.GetComponent().DrawEditor(); - ImGui::Separator(); - } - - } - - if (Selection.Entity.HasComponent()) - { - if (ImGui::CollapsingHeader("Character controller", ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Character controller properties"); - auto& c = Selection.Entity.GetComponent(); - ImGui::InputFloat("Height", &c.Height); - ImGui::InputFloat("Radius", &c.Radius); - ImGui::InputFloat("Mass", &c.Mass); - ImGui::Separator(); - } - } - if (Selection.Entity.HasComponent()) - { - std::string icon = ICON_FA_BOWLING_BALL; - if (ImGui::CollapsingHeader((icon + " Rigidbody").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Rigidbody properties"); - RigidBodyComponent& rbComponent = Selection.Entity.GetComponent(); - ImGui::DragFloat("Mass", &rbComponent.mass, 0.1, 0.0); - ImGui::Separator(); - } - } - if (Selection.Entity.HasComponent()) - { - std::string icon = ICON_FA_BOX; - if (ImGui::CollapsingHeader((icon + " Box collider").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Box collider properties"); - BoxColliderComponent& component = Selection.Entity.GetComponent(); - ImGuiHelper::DrawVec3("Size", &component.Size); - ImGui::Checkbox("Is trigger", &component.IsTrigger); - - ImGui::Separator(); - } - } - if (Selection.Entity.HasComponent()) - { - std::string icon = ICON_FA_CIRCLE; - if (ImGui::CollapsingHeader((icon + " Sphere collider").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Sphere properties"); - SphereColliderComponent& component = Selection.Entity.GetComponent(); - ImGui::DragFloat("Radius", &component.Radius, 0.1f, 0.0f, 100.0f); - ImGui::Checkbox("Is trigger", &component.IsTrigger); - - ImGui::Separator(); - } - } - if (Selection.Entity.HasComponent()) - { - - std::string icon = ICON_FA_BROOM; - if (ImGui::CollapsingHeader((icon + " " + "Quake map").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Quake map properties"); - auto& component = Selection.Entity.GetComponent(); - std::string path = component.Path; - - - char pathBuffer[256]; - memset(pathBuffer, 0, sizeof(pathBuffer)); - std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer)); - ImGui::Text("Map file: "); - ImGui::SameLine(); - if (ImGui::InputText("##MapPath", pathBuffer, sizeof(pathBuffer))) - { - path = std::string(pathBuffer); - } - - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map")) - { - char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 256); - path = FileSystem::AbsoluteToRelative(fullPath); - } - ImGui::EndDragDropTarget(); - } - - component.Path = path; - - ImGui::InputFloat("Scale factor", &component.ScaleFactor, 0.01f, 0.1f); - - ImGui::Checkbox("Build collisions", &component.HasCollisions); - if (ImGui::Button("Build Geometry")) - { - QuakeMapBuilder mapBuilder; - mapBuilder.BuildQuakeMap(Selection.Entity); - } - ImGui::Separator(); - } - }*/ + mCharacterControllerPanel.Draw(entity); } void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity) @@ -366,15 +118,18 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity) if (ImGui::BeginPopup("ComponentPopup")) { - MenuItemComponent("Wren Script", Nuake::WrenScriptComponent); - MenuItemComponent("Camera", Nuake::CameraComponent); - MenuItemComponent("Light", Nuake::LightComponent); - MenuItemComponent("Model", Nuake::ModelComponent); - MenuItemComponent("Rigid body", Nuake::RigidBodyComponent); - MenuItemComponent("Box collider", Nuake::BoxColliderComponent); - MenuItemComponent("Sphere collider", Nuake::SphereColliderComponent); - MenuItemComponent("Mesh collider", Nuake::MeshColliderComponent); - MenuItemComponent("Quake map", Nuake::QuakeMapComponent); + MenuItemComponent("Wren Script", Nuake::WrenScriptComponent) + MenuItemComponent("Camera", Nuake::CameraComponent) + MenuItemComponent("Light", Nuake::LightComponent) + MenuItemComponent("Model", Nuake::ModelComponent) + ImGui::Separator(); + MenuItemComponent("Character Controller", Nuake::CharacterControllerComponent) + MenuItemComponent("Rigid body", Nuake::RigidBodyComponent) + MenuItemComponent("Box collider", Nuake::BoxColliderComponent) + MenuItemComponent("Sphere collider", Nuake::SphereColliderComponent) + MenuItemComponent("Mesh collider", Nuake::MeshColliderComponent) + ImGui::Separator(); + MenuItemComponent("Quake map", Nuake::QuakeMapComponent) ImGui::EndPopup(); } ImGui::Separator(); diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 291e71a3..a99a0544 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -15,6 +15,7 @@ #include "../ComponentsPanel/BoxColliderPanel.h" #include "../ComponentsPanel/SphereColliderPanel.h" #include "../ComponentsPanel/MeshColliderPanel.h" +#include "../ComponentsPanel/CharacterControllerPanel.h" class EditorSelectionPanel { private: @@ -28,6 +29,7 @@ private: BoxColliderPanel mBoxColliderPanel; SphereColliderPanel mSphereColliderPanel; MeshColliderPanel mMeshColliderPanel; + CharacterControllerPanel mCharacterControllerPanel; Ref currentFile; Ref selectedResource; diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index 94f357a6..ef474bcd 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -41,7 +41,7 @@ namespace Nuake Renderer2D::Init(); Logger::Log("2D renderer initialized"); - Logger::Log("Engine initialized succesfully!"); + Logger::Log("Engine initialized successfully!"); } void Engine::Tick() diff --git a/Nuake/src/Core/Physics/DynamicWorld.cpp b/Nuake/src/Core/Physics/DynamicWorld.cpp index 13843a78..f06cf928 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.cpp +++ b/Nuake/src/Core/Physics/DynamicWorld.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace Nuake { @@ -356,6 +357,12 @@ namespace Nuake void DynamicWorld::AddCharacterController(Ref cc) { + auto settings = new JPH::CharacterSettings(); + settings->mMaxSlopeAngle = JPH::DegreesToRadians(45.0f); + settings->mLayer = Layers::MOVING; + settings->mFriction = 0.5f; + + // Shape here } RaycastResult DynamicWorld::Raycast(glm::vec3 from, glm::vec3 to) diff --git a/Nuake/src/Scene/Components/CharacterControllerComponent.h b/Nuake/src/Scene/Components/CharacterControllerComponent.h index b35df9b2..f01233a2 100644 --- a/Nuake/src/Scene/Components/CharacterControllerComponent.h +++ b/Nuake/src/Scene/Components/CharacterControllerComponent.h @@ -5,7 +5,7 @@ namespace Nuake { class CharacterControllerComponent { public: - Ref < Physics::CharacterController> CharacterController; + Ref CharacterController; float Height = 1.0f; float Radius = 0.2f; diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 038e96b3..47976466 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -75,6 +75,13 @@ namespace Nuake } } + const auto characterControllerView = m_Scene->m_Registry.view(); + for (auto e : characterControllerView) + { + auto [transformComponent, characterControllerComponent] = view.get(e); + + } + //// character controllers //auto ccview = m_Scene->m_Registry.view(); //for (auto e : ccview)