From 0fd36c292c4db72532d56c18b055d48926a8b46c Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Fri, 8 Sep 2023 17:21:01 -0400 Subject: [PATCH] Work --- Editor/src/Misc/GizmoDrawer.cpp | 27 ++++++- Editor/src/Windows/FileSystemUI.cpp | 12 ++- Nuake/src/Core/Maths.cpp | 112 +++++++++++++++------------- Nuake/src/Core/Maths.h | 2 + 4 files changed, 95 insertions(+), 58 deletions(-) diff --git a/Editor/src/Misc/GizmoDrawer.cpp b/Editor/src/Misc/GizmoDrawer.cpp index 66f993a9..77ee319b 100644 --- a/Editor/src/Misc/GizmoDrawer.cpp +++ b/Editor/src/Misc/GizmoDrawer.cpp @@ -279,10 +279,35 @@ void GizmoDrawer::DrawGizmos(Ref scene) auto camView = scene->m_Registry.view(); for (auto e : camView) { - auto [transform, cam] = scene->m_Registry.get(e); + auto& [transform, cam] = scene->m_Registry.get(e); renderList.AddToRenderList(_gizmos["cam"]->GetMeshes()[0], transform.GetGlobalTransform()); + + auto view = transform.GetGlobalTransform(); + Frustum& frustum = cam.CameraInstance->GetFrustum(); + auto& frustumCorners = frustum.GetPoints(); + + constexpr int frustumEdges[12][2] = { + {0, 1}, {1, 3}, {3, 2}, {2, 0}, // Near plane edges + {4, 5}, {5, 7}, {7, 6}, {6, 4}, // Far plane edges + {0, 4}, {1, 5}, {2, 6}, {3, 7} // Connection lines + }; + + glBegin(GL_LINES); + + for (int i = 0; i < 12; ++i) { + int startIdx = frustumEdges[i][0]; + int endIdx = frustumEdges[i][1]; + const Vector3& startCorner = view * Vector4(frustumCorners[startIdx], 1.0f); + const Vector3& endCorner = frustumCorners[endIdx]; + glVertex3f(startCorner.x, startCorner.y, startCorner.z); + glVertex3f(endCorner.x, endCorner.y, endCorner.z); + } + + glEnd(); + } + renderList.Flush(flatShader, true); // Lights diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index ba74e00e..a0b54fd6 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -64,11 +64,14 @@ namespace Nuake ImGui::PushFont(FontManager::GetFont(Icons)); const char* icon = ICON_FA_FOLDER; const std::string id = ICON_FA_FOLDER + std::string("##") + directory->name; + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); if (ImGui::Button(id.c_str(), ImVec2(100, 100))) { m_CurrentDirectory = directory; } + ImGui::PopStyleVar(); + const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId); if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1)) { @@ -669,11 +672,12 @@ namespace Nuake bool child = ImGui::BeginChild("Content", avail); ImGui::PopStyleVar(); + ImGui::SameLine(); if (child) { int width = avail.x; - ImVec2 buttonSize = ImVec2(80, 80); - int amount = (int)(width / 100); + ImVec2 buttonSize = ImVec2(110, 110); + int amount = (int)(width / buttonSize.x); if (amount <= 0) amount = 1; int i = 1; // current amount of item per row. @@ -683,7 +687,7 @@ namespace Nuake if (m_CurrentDirectory && m_CurrentDirectory != FileSystem::RootDirectory && m_CurrentDirectory->Parent) { ImGui::TableNextColumn(); - if (ImGui::Button("..", ImVec2(100, 100))) + if (ImGui::Button("..", buttonSize)) m_CurrentDirectory = m_CurrentDirectory->Parent; i++; } @@ -711,7 +715,7 @@ namespace Nuake { if(m_SearchKeyword.empty() || f->GetName().find(String::Sanitize(m_SearchKeyword)) != std::string::npos) { - if (i - 1 % amount != 0 || i == 1) + if (i + 1 % amount != 0 || i == 1) { ImGui::TableNextColumn(); } diff --git a/Nuake/src/Core/Maths.cpp b/Nuake/src/Core/Maths.cpp index 0b66c7a8..e2402703 100644 --- a/Nuake/src/Core/Maths.cpp +++ b/Nuake/src/Core/Maths.cpp @@ -1,63 +1,69 @@ #include "src/Core/Maths.h" -using namespace Nuake; - -Quat Nuake::LookAt(Vector3 sourcePoint, Vector3 destPoint) +namespace Nuake { - Vector3 forwardVector = glm::normalize(destPoint - sourcePoint); + Quat Nuake::LookAt(Vector3 sourcePoint, Vector3 destPoint) + { + Vector3 forwardVector = glm::normalize(destPoint - sourcePoint); - float dot = glm::dot(Vector3(0, 0, 1), forwardVector); - if (glm::abs(dot - (-1.0f)) < 0.000001f) - { - return Quat(0, 1, 0, 3.1415926535897932f); - } - if (glm::abs(dot - (1.0f)) < 0.000001f) - { - return Quat(); // identity + float dot = glm::dot(Vector3(0, 0, 1), forwardVector); + if (glm::abs(dot - (-1.0f)) < 0.000001f) + { + return Quat(0, 1, 0, 3.1415926535897932f); + } + if (glm::abs(dot - (1.0f)) < 0.000001f) + { + return Quat(); // identity + } + + float rotAngle = acos(dot); + Vector3 rotAxis = glm::cross(Vector3(0, 0, 1), forwardVector); + rotAxis = glm::normalize(rotAxis); + return CreateFromAxisAngle(rotAxis, rotAngle); } - float rotAngle = acos(dot); - Vector3 rotAxis = glm::cross(Vector3(0, 0, 1), forwardVector); - rotAxis = glm::normalize(rotAxis); - return CreateFromAxisAngle(rotAxis, rotAngle); -} + // just in case you need that function also + Quat Nuake::CreateFromAxisAngle(Vector3 axis, float angle) + { + float halfAngle = angle * .5f; + float s = sin(halfAngle); + Quat q; + q.x = axis.x * s; + q.y = axis.y * s; + q.z = axis.z * s; + q.w = cos(halfAngle); + return q; + } -// just in case you need that function also -Quat Nuake::CreateFromAxisAngle(Vector3 axis, float angle) -{ - float halfAngle = angle * .5f; - float s = sin(halfAngle); - Quat q; - q.x = axis.x * s; - q.y = axis.y * s; - q.z = axis.z * s; - q.w = cos(halfAngle); - return q; -} + Quat Nuake::QuatFromEuler(float x, float y, float z) + { + Quat pitchQuat = glm::angleAxis(Rad(x), Vector3(1.0f, 0.0f, 0.0f)); + Quat yawQuat = glm::angleAxis(Rad(y), Vector3(0.0f, 1.0f, 0.0f)); + Quat rollQuat = glm::angleAxis(Rad(z), Vector3(0.0f, 0.0f, -1.0f)); + Quat orientation = yawQuat * pitchQuat * rollQuat; -Quat Nuake::QuatFromEuler(float x, float y, float z) -{ - Quat pitchQuat = glm::angleAxis(Rad(x), Vector3(1.0f, 0.0f, 0.0f)); - Quat yawQuat = glm::angleAxis(Rad(y), Vector3(0.0f, 1.0f, 0.0f)); - Quat rollQuat = glm::angleAxis(Rad(z), Vector3(0.0f, 0.0f, -1.0f)); - Quat orientation = yawQuat * pitchQuat * rollQuat; - - return glm::normalize(orientation); -} + return glm::normalize(orientation); + } -Vector3 Nuake::QuatToDirection(const Quat& quat) -{ - return glm::normalize(quat * Vector3(0, 0, -1)); -} + Vector3 Nuake::QuatToDirection(const Quat& quat) + { + return glm::normalize(quat * Vector3(0, 0, -1)); + } -void Nuake::Decompose(const Matrix4& m, Vector3& pos, Quat& rot, Vector3& scale) -{ - pos = m[3]; - for (int i = 0; i < 3; i++) - scale[i] = glm::length(Vector3(m[i])); - const Matrix3 rotMtx( - Vector3(m[0]) / scale[0], - Vector3(m[1]) / scale[1], - Vector3(m[2]) / scale[2]); - rot = glm::quat_cast(rotMtx); -} \ No newline at end of file + void Nuake::Decompose(const Matrix4& m, Vector3& pos, Quat& rot, Vector3& scale) + { + pos = m[3]; + for (int i = 0; i < 3; i++) + scale[i] = glm::length(Vector3(m[i])); + const Matrix3 rotMtx( + Vector3(m[0]) / scale[0], + Vector3(m[1]) / scale[1], + Vector3(m[2]) / scale[2]); + rot = glm::quat_cast(rotMtx); + } + + const Matrix4& Nuake::TransformToCameraTransform(const Matrix4& mat) + { + return mat; + } +} diff --git a/Nuake/src/Core/Maths.h b/Nuake/src/Core/Maths.h index ba3b1c18..c43bc2c1 100644 --- a/Nuake/src/Core/Maths.h +++ b/Nuake/src/Core/Maths.h @@ -25,4 +25,6 @@ namespace Nuake Quat QuatFromEuler(float x, float y, float z); Vector3 QuatToDirection(const Quat& quat); void Decompose(const Matrix4& m, Vector3& pos, Quat& rot, Vector3& scale); + + const Matrix4& TransformToCameraTransform(const Matrix4& mat); }