From a8915d636974e8452b6fd9881ba0dad4f30936f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Mendon=C3=A7a?= Date: Mon, 26 Feb 2024 19:52:08 +0000 Subject: [PATCH] fix(tools): draw transform gizmo on global position --- .../src/tesseratos/transform_gizmo/plugin.cpp | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/tools/tesseratos/src/tesseratos/transform_gizmo/plugin.cpp b/tools/tesseratos/src/tesseratos/transform_gizmo/plugin.cpp index 6033f307a2..d196fe1c15 100644 --- a/tools/tesseratos/src/tesseratos/transform_gizmo/plugin.cpp +++ b/tools/tesseratos/src/tesseratos/transform_gizmo/plugin.cpp @@ -23,6 +23,7 @@ using cubos::engine::Camera; using cubos::engine::Cubos; using cubos::engine::Gizmos; using cubos::engine::Input; +using cubos::engine::LocalToWorld; using cubos::engine::Position; using cubos::engine::Rotation; using cubos::engine::Scale; @@ -69,31 +70,18 @@ static void checkMovement(Position& position, glm::vec3 transformVector, glm::ve position.vec += (mousePosWorld - oldMousePosWorld) * transformVector; } -static void drawTransformGizmo(Query, Opt> cameraQuery, - Query positionQuery, Gizmos& gizmos, const Input& input, const Window& window, - Entity cameraEntity, Entity selectedEntity) +static void drawTransformGizmo(Query cameraQuery, + Query positionQuery, Gizmos& gizmos, const Input& input, + const Window& window, Entity cameraEntity, Entity selectedEntity) { - auto [camera, rotation, scale] = *cameraQuery.at(cameraEntity); + auto [camera, cameraLtw] = *cameraQuery.at(cameraEntity); - auto [position] = *positionQuery.at(selectedEntity); + auto [position, localToWorld] = *positionQuery.at(selectedEntity); - auto cameraPosition = glm::vec3(0.0F); - if (positionQuery.at(cameraEntity)) - { - auto [cameraPositionComponent] = *positionQuery.at(cameraEntity); - cameraPosition = cameraPositionComponent.vec; - } + auto cameraPosition = cameraLtw.worldPosition(); - auto pv = glm::mat4(1.0F); - if (rotation) - { - pv *= glm::toMat4(rotation->quat); - } + auto pv = cameraLtw.mat; - if (scale) - { - pv = glm::scale(pv, glm::vec3(scale->factor)); - } pv = glm::inverse(pv); pv = glm::perspective(glm::radians(camera.fovY), (float)window->size().x / (float)window->size().y, camera.zNear, @@ -143,24 +131,28 @@ static void drawTransformGizmo(Query, Opt positionQuery, - Query, Opt> cameraQuery) { + const Input& input, Gizmos& gizmos, Query positionQuery, + Query cameraQuery) { if (entitySelector.selection.isNull()) { return;