Skip to content

Commit

Permalink
fix(gizmos): correctly calculate perpendiculars
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoMendonc-a committed Mar 8, 2024
1 parent ae4fe9e commit 0b60c04
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
27 changes: 22 additions & 5 deletions engine/src/gizmos/types/cut_cone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
26 changes: 21 additions & 5 deletions engine/src/gizmos/types/ring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 0b60c04

Please sign in to comment.