diff --git a/CMakeLists.txt b/CMakeLists.txt index db503cf..dba887d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project(OpenEngineProject) +add_definitions(-DOE_DEBUG_TOOLS=1) add_subdirectory(open_engine) -add_subdirectory(application - ./bin +add_subdirectory(editor + ./editor ) diff --git a/conanfile.txt b/conanfile.txt index e5bf227..f9c2b4a 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,6 +1,7 @@ [requires] imgui/1.92.5-docking spdlog/1.16.0 +entt/3.16.0 [generators] CMakeDeps diff --git a/editor/include/editor.hpp b/editor/include/editor.hpp index d90b4cc..86904d7 100755 --- a/editor/include/editor.hpp +++ b/editor/include/editor.hpp @@ -27,16 +27,16 @@ namespace OpenEngine { { auto delta = Time::DeltaTime(); - auto& transform = GetComponent(); + auto& position = GetComponent().translation; if (Input::IsKeyPressed(KeyCode::Up)) - transform.transform[3][1] += 5.0 * delta; + position.y += 5.0 * delta; if (Input::IsKeyPressed(KeyCode::Down)) - transform.transform[3][1] -= 5.0 * delta; + position.y -= 5.0 * delta; if (Input::IsKeyPressed(KeyCode::Right)) - transform.transform[3][0] += 5.0 * delta; + position.x += 5.0 * delta; if (Input::IsKeyPressed(KeyCode::Left)) - transform.transform[3][0] -= 5.0 * delta; + position.x -= 5.0 * delta; }; void OnDestroy() diff --git a/editor/include/panels/scene_hierarchy.hpp b/editor/include/panels/scene_hierarchy.hpp index c7ea4b4..d69c950 100644 --- a/editor/include/panels/scene_hierarchy.hpp +++ b/editor/include/panels/scene_hierarchy.hpp @@ -2,6 +2,7 @@ #define SCENE_HIERARCHY_HPP #include "imgui.h" +#include #include namespace OpenEngine { diff --git a/editor/src/panels/scene_hierarchy.cpp b/editor/src/panels/scene_hierarchy.cpp index 44200cc..178222c 100644 --- a/editor/src/panels/scene_hierarchy.cpp +++ b/editor/src/panels/scene_hierarchy.cpp @@ -1,8 +1,7 @@ -#include "open_engine/scene/components.hpp" -#include -#include #include +#include +#include #include namespace OpenEngine { @@ -137,14 +136,3 @@ namespace OpenEngine { DrawComponentDrawer(entity, "Camera"); } } - -/* - if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight | ImGuiPopupFlags_NoOpenOverItems)) - { - if (ImGui::MenuItem("Create Empty Entity")) - { - // m_Context->CreateEntity("Empty Entity"); - } - ImGui::EndPopup(); - } - */ diff --git a/imgui.ini b/imgui.ini index 1f3c2d7..bdd10b7 100644 --- a/imgui.ini +++ b/imgui.ini @@ -22,38 +22,38 @@ DockId=0x00000008,0 [Window][Viewport] Pos=406,0 -Size=629,1386 -Collapsed=0 -DockId=0x00000006,0 - -[Window][Dear ImGui Demo] -Pos=1037,0 -Size=235,1386 -Collapsed=0 -DockId=0x00000007,0 - -[Window][Scene] -Pos=0,151 -Size=404,264 +Size=391,1059 Collapsed=0 DockId=0x00000009,0 -[Window][Properties] -Pos=0,417 -Size=404,969 +[Window][Dear ImGui Demo] +Pos=406,1061 +Size=391,325 Collapsed=0 DockId=0x0000000A,0 -[Docking][Data] -DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,0 Size=1272,1386 Split=X - DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=1035,1386 Split=X - DockNode ID=0x00000005 Parent=0x00000003 SizeRef=404,1386 Split=Y Selected=0x553E127E - DockNode ID=0x00000001 Parent=0x00000005 SizeRef=274,149 Selected=0x553E127E - DockNode ID=0x00000002 Parent=0x00000005 SizeRef=274,1235 Split=Y Selected=0xE601B12F - DockNode ID=0x00000009 Parent=0x00000002 SizeRef=498,264 Selected=0xE601B12F - DockNode ID=0x0000000A Parent=0x00000002 SizeRef=498,969 Selected=0x8C72BEA8 - DockNode ID=0x00000006 Parent=0x00000003 SizeRef=629,1386 CentralNode=1 Selected=0xC450F867 - DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=235,1386 Split=Y Selected=0x5E5F7166 - DockNode ID=0x00000007 Parent=0x00000004 SizeRef=235,305 Selected=0x5E5F7166 - DockNode ID=0x00000008 Parent=0x00000004 SizeRef=235,1079 Selected=0xA5FF3A7A +[Window][Scene] +Pos=0,151 +Size=404,1235 +Collapsed=0 +DockId=0x00000002,0 + +[Window][Properties] +Pos=799,0 +Size=473,1386 +Collapsed=0 +DockId=0x00000007,0 + +[Docking][Data] +DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,0 Size=1272,1386 Split=X + DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=2085,1386 Split=X + DockNode ID=0x00000005 Parent=0x00000003 SizeRef=404,1386 Split=Y Selected=0x553E127E + DockNode ID=0x00000001 Parent=0x00000005 SizeRef=274,149 Selected=0x553E127E + DockNode ID=0x00000002 Parent=0x00000005 SizeRef=274,1235 Selected=0xE601B12F + DockNode ID=0x00000006 Parent=0x00000003 SizeRef=1679,1386 Split=Y Selected=0xC450F867 + DockNode ID=0x00000009 Parent=0x00000006 SizeRef=629,1067 CentralNode=1 Selected=0xC450F867 + DockNode ID=0x0000000A Parent=0x00000006 SizeRef=629,325 Selected=0x5E5F7166 + DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=473,1386 Split=Y Selected=0x5E5F7166 + DockNode ID=0x00000007 Parent=0x00000004 SizeRef=235,305 Selected=0x8C72BEA8 + DockNode ID=0x00000008 Parent=0x00000004 SizeRef=235,1079 Selected=0xA5FF3A7A diff --git a/open_engine/include/open_engine/scene/components.hpp b/open_engine/include/open_engine/scene/components.hpp index d94c1e5..00eca68 100644 --- a/open_engine/include/open_engine/scene/components.hpp +++ b/open_engine/include/open_engine/scene/components.hpp @@ -5,13 +5,20 @@ #include "open_engine/scene/scene_camera.hpp" #include -#include +#include #include +#include +#include +#include #include #include namespace OpenEngine { - + + void DrawVec3Control(const char* label, glm::vec3& values, + float reset_value = 0.0f, float column_width = 100.0f, + const std::array labels = {"x", "y", "z"}); + struct TagComponent { std::string tag; @@ -36,19 +43,33 @@ namespace OpenEngine { struct TransformComponent { - glm::mat4 transform{ 1.0f }; + glm::vec3 translation = { 0.0f, 0.0f, 0.0f }; + glm::vec3 rotation = { 0.0f, 0.0f, 0.0f }; + glm::vec3 scale = { 1.0f, 1.0f, 1.0f }; TransformComponent() = default; TransformComponent(const TransformComponent&) = default; - TransformComponent(const glm::mat4& transform_mat) - : transform(transform_mat) {} + TransformComponent(const glm::vec3& position) + : translation(position) {} - operator glm::mat4() { return transform; }; - operator const glm::mat4() const { return transform; }; + glm::mat4 GetTransform() const + { + glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation); + + transform *= glm::rotate(glm::mat4(1.0f), rotation.x, { 1, 0, 0 }) + * glm::rotate(glm::mat4(1.0f), rotation.y, { 0, 1, 0 }) + * glm::rotate(glm::mat4(1.0f), rotation.z, { 0, 0, 1 }); + + transform *= glm::scale(glm::mat4(1.0f), scale); + + return transform; + }; void OnImGuiRender(Entity& entity) { - ImGui::DragFloat3("Position", glm::value_ptr(transform[3]), 0.1f); + DrawVec3Control("Position", translation); + DrawVec3Control("Rotation", rotation); + DrawVec3Control("Scale", scale); }; }; diff --git a/open_engine/include/open_engine/scene/scene_camera.hpp b/open_engine/include/open_engine/scene/scene_camera.hpp index 026275f..2e9df08 100644 --- a/open_engine/include/open_engine/scene/scene_camera.hpp +++ b/open_engine/include/open_engine/scene/scene_camera.hpp @@ -67,7 +67,7 @@ namespace OpenEngine { float fov = 45.0f; float perspective_near = 0.01f, perspective_far = 1000.0f; - float aspect_ratio = 0.0f; + float aspect_ratio = 16.0f/9.0f; }; } diff --git a/open_engine/src/open_engine/imgui/imgui_layer.cpp b/open_engine/src/open_engine/imgui/imgui_layer.cpp index 1b94f24..8be40dd 100644 --- a/open_engine/src/open_engine/imgui/imgui_layer.cpp +++ b/open_engine/src/open_engine/imgui/imgui_layer.cpp @@ -160,10 +160,11 @@ namespace OpenEngine { const ImVec4 mauve = ImVec4(0.796f, 0.698f, 0.972f, 1.0f); // #cba6f7 const ImVec4 peach = ImVec4(0.980f, 0.709f, 0.572f, 1.0f); // #fab387 const ImVec4 yellow = ImVec4(0.980f, 0.913f, 0.596f, 1.0f); // #f9e2af + const ImVec4 red = ImVec4(0.953f, 0.545f, 0.659f, 1.0f); // #f38ba8 const ImVec4 green = ImVec4(0.650f, 0.890f, 0.631f, 1.0f); // #a6e3a1 + const ImVec4 blue = ImVec4(0.533f, 0.698f, 0.976f, 1.0f); // #89b4fa const ImVec4 teal = ImVec4(0.580f, 0.886f, 0.819f, 1.0f); // #94e2d5 const ImVec4 sapphire = ImVec4(0.458f, 0.784f, 0.878f, 1.0f); // #74c7ec - const ImVec4 blue = ImVec4(0.533f, 0.698f, 0.976f, 1.0f); // #89b4fa const ImVec4 lavender = ImVec4(0.709f, 0.764f, 0.980f, 1.0f); // #b4befe // Main window and backgrounds diff --git a/open_engine/src/open_engine/scene/components.cpp b/open_engine/src/open_engine/scene/components.cpp new file mode 100644 index 0000000..eed0051 --- /dev/null +++ b/open_engine/src/open_engine/scene/components.cpp @@ -0,0 +1,74 @@ +#include "imgui.h" +#include + +#include + +namespace OpenEngine { + + void DrawVec3Control(const char* label, glm::vec3& values, + float reset_value, float column_width, + const std::array labels) + { + ImGui::PushID(label); + ImVec2 item_spacing = { 15.0f, 0.0f }; + ImGui::Columns(2); + ImGui::SetColumnWidth(0, column_width); + ImGui::Text("%s", label); + if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered()) + values = glm::vec3(reset_value); + ImGui::NextColumn(); + + ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 }); + + float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f; + ImVec2 button_size = { line_height + 3.0f, line_height }; + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0f, 0.8f, 0.9f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f }); + if (ImGui::Button(labels[0], button_size)) + values.x = reset_value; + ImGui::PopStyleColor(4); + + ImGui::SameLine(); + ImGui::DragFloat("##X", &values.x, 0.1f); + ImGui::PopItemWidth(); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing); + ImGui::SameLine(); + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 1.0f, 0.9f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f }); + if (ImGui::Button(labels[1], button_size)) + values.y = reset_value; + ImGui::PopStyleColor(4); + ImGui::PopStyleVar(); + + ImGui::SameLine(); + ImGui::DragFloat("##Y", &values.y, 0.1f); + ImGui::PopItemWidth(); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing); + ImGui::SameLine(); + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.7f, 0.9f, 1.0f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f }); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f }); + if (ImGui::Button(labels[2], button_size)) + values.z = reset_value; + ImGui::PopStyleColor(4); + ImGui::PopStyleVar(1); + + ImGui::SameLine(); + ImGui::DragFloat("##Z", &values.z, 0.1f); + ImGui::PopItemWidth(); + + ImGui::PopStyleVar(); + + ImGui::Columns(1); + ImGui::PopID(); + } +} diff --git a/open_engine/src/open_engine/scene/scene.cpp b/open_engine/src/open_engine/scene/scene.cpp index 36834cc..5af0159 100644 --- a/open_engine/src/open_engine/scene/scene.cpp +++ b/open_engine/src/open_engine/scene/scene.cpp @@ -34,8 +34,8 @@ namespace OpenEngine { }); } - Camera* main_camera = nullptr; - glm::mat4* main_transform = nullptr; + SceneCamera* main_camera = nullptr; + glm::mat4 main_transform{ 1.0f }; { auto camera_view = registry.view(); for (auto entity : camera_view) { @@ -43,19 +43,19 @@ namespace OpenEngine { if (camera_component.primary) { main_camera = &camera_component.camera; - main_transform = &transform.transform; + main_transform = transform.GetTransform(); break; } } if (main_camera) { - Renderer2D::BeginScene(main_camera->GetProjection(), *main_transform); + Renderer2D::BeginScene(main_camera->GetProjection(), main_transform); auto view = registry.view(); for (const auto& entity : view) { auto [transform, sprite] = view.get(entity); - Renderer2D::DrawQuad(transform.transform, sprite.color); + Renderer2D::DrawQuad(transform.GetTransform(), sprite.color); } Renderer2D::EndScene();