Implementing started properly implementing Gizmo

Adding GetTransform to the transform component such that the proper view transform can be calculated for any scene camera
This commit is contained in:
Nigel Barink 2023-05-08 22:06:01 +02:00
parent 8e202f9d59
commit e9852fe0e7
2 changed files with 35 additions and 7 deletions

View File

@ -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<YoggieEngine::TransformComponent>();
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);
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "Entity.h"
#include <glm/gtx/quaternion.hpp>
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 {