diff options
| author | Mel <einebeere@gmail.com> | 2024-01-25 11:25:29 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2024-01-25 11:25:29 +0100 |
| commit | 66e436d0f2cf3c33105d8a5bce43bf64d5e72255 (patch) | |
| tree | 3ee36001907453336cf96a57d8ec0154a9ae3135 /src/Math/Vector.hpp | |
| parent | efd17623627607a26f33dac8f7ef1a1ddc931907 (diff) | |
| download | meowcraft-66e436d0f2cf3c33105d8a5bce43bf64d5e72255.tar.zst meowcraft-66e436d0f2cf3c33105d8a5bce43bf64d5e72255.zip | |
Mostly functioning world collisions
Diffstat (limited to 'src/Math/Vector.hpp')
| -rw-r--r-- | src/Math/Vector.hpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Math/Vector.hpp b/src/Math/Vector.hpp index acbfa98..7d07d5c 100644 --- a/src/Math/Vector.hpp +++ b/src/Math/Vector.hpp @@ -68,8 +68,12 @@ struct Vector { return reduce([](auto x, auto y) { return x + y; }); } + T magnitude_squared() const { + return map([](auto x) { return x * x;}).sum(); + } + T magnitude() const { - return sqrt(map([](auto x) { return x * x;}).sum()); + return sqrt(magnitude_squared()); } Vector normalize() const { @@ -81,6 +85,10 @@ struct Vector { return (*this - other).magnitude(); } + T distance_squared(const Vector other) const { + return (*this - other).magnitude_squared(); + } + Vector<3, T> any_orthogonal() { if (Vector a{y(), -x(), 0.0f}; a != zero()) return a; if (Vector b{z(), 0.0f, -x()}; b != zero()) return b; |
