From 0b60c04fc7ca16560a10913170c12300e8f0b5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Mendon=C3=A7a?= Date: Fri, 8 Mar 2024 14:46:55 +0000 Subject: [PATCH] fix(gizmos): correctly calculate perpendiculars --- engine/src/gizmos/types/cut_cone.hpp | 27 ++++++++++++++++++++++----- engine/src/gizmos/types/ring.hpp | 26 +++++++++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/engine/src/gizmos/types/cut_cone.hpp b/engine/src/gizmos/types/cut_cone.hpp index a3125e69b..37d94eb3d 100644 --- a/engine/src/gizmos/types/cut_cone.hpp +++ b/engine/src/gizmos/types/cut_cone.hpp @@ -47,19 +47,36 @@ namespace cubos::engine glm::vec3 n = glm::normalize(mPointB - mPointA); glm::vec3 p; - if (n[0] != n[1]) + + if (n[0] != 0 && n[1] != 0) { - p = {n[1], -n[0], n[2]}; + p = {-n[1], n[0], 0}; } - else if (n[0] != n[2]) + else if (n[0] == 0 && n[1] != 0) { - p = {-n[2], n[1], n[0]}; + if (n[2] != 0) + { + p = {1, 0, -n[1] / n[2]}; + } + else + { + p = {1, 0, 0}; + } } else { - p = {n[0], -n[2], n[1]}; + if (n[2] != 0) + { + p = {0, 1, -n[1] / n[2]}; + } + else + { + p = {0, 1, 0}; + } } + p = glm::normalize(p); + glm::vec3 pA = p * mRadiusA; for (int i = 0; i < GizmosRenderer::CutConeVertsPerBase; i++) diff --git a/engine/src/gizmos/types/ring.hpp b/engine/src/gizmos/types/ring.hpp index 1416db063..c79ff9065 100644 --- a/engine/src/gizmos/types/ring.hpp +++ b/engine/src/gizmos/types/ring.hpp @@ -47,19 +47,35 @@ namespace cubos::engine glm::vec3 n = glm::normalize(mPointB - mPointA); glm::vec3 p; - if (n[0] != n[1]) + if (n[0] != 0 && n[1] != 0) { - p = {n[1], -n[0], n[2]}; + p = {-n[1], n[0], 0}; } - else if (n[0] != n[2]) + else if (n[0] == 0 && n[1] != 0) { - p = {-n[2], n[1], n[0]}; + if (n[2] != 0) + { + p = {1, 0, -n[1] / n[2]}; + } + else + { + p = {1, 0, 0}; + } } else { - p = {n[0], -n[2], n[1]}; + if (n[2] != 0) + { + p = {0, 1, -n[1] / n[2]}; + } + else + { + p = {0, 1, 0}; + } } + p = glm::normalize(p); + glm::vec3 pA = p * mRadiusOuter; glm::vec3 pB = p * mRadiusInner;