From e9852fe0e7f1b739ccb77deeec5529289b101c52 Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Mon, 8 May 2023 22:06:01 +0200 Subject: [PATCH] Implementing started properly implementing Gizmo Adding GetTransform to the transform component such that the proper view transform can be calculated for any scene camera --- Editor/src/Views/Viewport.cpp | 35 +++++++++++++++++++++++------ YoggieEngine/src/Scene/Components.h | 7 ++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Editor/src/Views/Viewport.cpp b/Editor/src/Views/Viewport.cpp index 0dea0b3..6fb0d7b 100644 --- a/Editor/src/Views/Viewport.cpp +++ b/Editor/src/Views/Viewport.cpp @@ -34,16 +34,37 @@ void Viewport::Draw() { ); + + ImGuizmo::Enable(true); - ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y, ContentRegionMax.x, ContentRegionMax.y); + ImGuizmo::SetOrthographic(false); + ImGuizmo::SetDrawlist(); - glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix); - isFocused = ImGui::IsWindowFocused(); + float windowWidth = (float)ImGui::GetWindowWidth(); + float windowHeight = (float)ImGui::GetWindowHeight(); + ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, windowWidth, windowHeight); - //ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f); - //ImGuizmo::ViewManipulate(glm::value_ptr(cam.ViewMatrix), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC); + const auto& ProjMatrix = camera.projection; + glm::mat4& cameraView = glm::mat4(1.0f);//glm::inverse(glm::translate(glm::mat4(1.0f) , cam.Position) * glm::toMat4(glm::quat(cam.Rotation)) ); - // Matrix is the model matrix we would want to manipulate - //ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix)); + ImGuizmo::DrawGrid(glm::value_ptr(cameraView), glm::value_ptr(ProjMatrix), glm::value_ptr(cameraDelta), 100.0f); + ImGuizmo::ViewManipulate(glm::value_ptr(cameraView), 1, ImGui::GetWindowPos(), {90,90}, 0x22CCCCCC); + + if (selected == nullptr) + return; + + if (selected->isValid()) { + + auto& tc = selected->GetComponent(); + glm::mat4 transform = tc.GetTransform(); + + ImGuizmo::Manipulate( + glm::value_ptr(cameraView), + glm::value_ptr(ProjMatrix), + ImGuizmo::TRANSLATE, ImGuizmo::LOCAL, + glm::value_ptr(transform), nullptr, nullptr); + } + + } \ No newline at end of file diff --git a/YoggieEngine/src/Scene/Components.h b/YoggieEngine/src/Scene/Components.h index 2140d47..544b39a 100644 --- a/YoggieEngine/src/Scene/Components.h +++ b/YoggieEngine/src/Scene/Components.h @@ -1,5 +1,6 @@ #pragma once #include "Entity.h" +#include namespace YoggieEngine { struct IdentifierComponent { std::string name; @@ -13,6 +14,12 @@ namespace YoggieEngine { glm::mat4 LocalTransform = glm::mat4(1.0f); + glm::mat4 GetTransform() const { + glm::mat4 rotation = glm::toMat4(glm::quat(Rotation)); + return glm::translate(glm::mat4(1.0f), Position) * rotation * glm::scale(glm::mat4(1.0f), Scale); + } + + }; struct RelationComponent {