summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-03 01:25:15 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-03 01:25:15 +0000
commit253a0b73f0975d8f14c3a3f2a06675b53c736071 (patch)
tree71cd0bf5604f7dfb07ed7022c1358a8e2aa91f6a /lib
parentCreate and use a shader program for things with absolute position (diff)
downloadilt-253a0b73f0975d8f14c3a3f2a06675b53c736071.tar.bz2
ilt-253a0b73f0975d8f14c3a3f2a06675b53c736071.tar.xz
ilt-253a0b73f0975d8f14c3a3f2a06675b53c736071.zip
Simplify a lot of code with sincosf
Diffstat (limited to 'lib')
-rw-r--r--lib/maths.cpp12
-rw-r--r--lib/maths.h14
2 files changed, 12 insertions, 14 deletions
diff --git a/lib/maths.cpp b/lib/maths.cpp
index 60413f4..5800b1b 100644
--- a/lib/maths.cpp
+++ b/lib/maths.cpp
@@ -112,11 +112,7 @@ find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye)
if (as == bs) {
return {as, false};
}
- const auto perps = entrys + half_pi;
- const auto perpe = entrye - half_pi;
- const glm::vec2 ad {std::sin(perps), std::cos(perps)};
- const glm::vec2 bd {std::sin(perpe), std::cos(perpe)};
- return find_arc_centre(as, ad, bs, bd);
+ return find_arc_centre(as, sincosf(entrys + half_pi), bs, sincosf(entrye - half_pi));
}
std::pair<glm::vec2, bool>
@@ -135,11 +131,7 @@ std::pair<float, float>
find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye)
{
const auto getrad = [&](float leftOrRight) {
- const auto perps = entrys + leftOrRight;
- const auto perpe = entrye + leftOrRight;
- const glm::vec2 ad {std::sin(perps), std::cos(perps)};
- const glm::vec2 bd {std::sin(perpe), std::cos(perpe)};
- return find_arcs_radius(start, ad, end, bd);
+ return find_arcs_radius(start, sincosf(entrys + leftOrRight), end, sincosf(entrye + leftOrRight));
};
return {getrad(-half_pi), getrad(half_pi)};
}
diff --git a/lib/maths.h b/lib/maths.h
index d304b65..a3a391d 100644
--- a/lib/maths.h
+++ b/lib/maths.h
@@ -37,11 +37,11 @@ sincosf(float a, float & s, float & c)
return sincosf(a, &s, &c);
}
-inline std::pair<float, float>
+inline glm::vec2
sincosf(float a)
{
- std::pair<float, float> sc;
- sincosf(a, &sc.first, &sc.second);
+ glm::vec2 sc;
+ sincosf(a, sc.x, sc.y);
return sc;
}
@@ -62,9 +62,15 @@ operator!(const glm::vec3 & v)
}
constexpr inline glm::vec3
+operator^(const glm::vec2 & v, float y)
+{
+ return {v.x, y, v.y};
+}
+
+constexpr inline glm::vec3
operator!(const glm::vec2 & v)
{
- return {v.x, 0, v.y};
+ return v ^ 0.F;
}
constexpr inline float