From 7dd9c9ea6f462d0e9dee51d62f9aa185f46a8ef0 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Wed, 20 Dec 2023 13:22:31 -0500 Subject: mVec and Egg Math (Quat, Vector3f, Matrix34f) --- src/egg/math/eggVector.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/egg/math/eggVector.cpp (limited to 'src/egg/math/eggVector.cpp') diff --git a/src/egg/math/eggVector.cpp b/src/egg/math/eggVector.cpp new file mode 100644 index 00000000..f90a7e4c --- /dev/null +++ b/src/egg/math/eggVector.cpp @@ -0,0 +1,60 @@ +#include + +namespace EGG { + +const Vector2f Vector2f::zero(0.0f, 0.0f); +const Vector2f Vector2f::ex(1.0f, 0.0f); +const Vector2f Vector2f::ey(0.0f, 1.0f); + +const Vector3f Vector3f::zero(0.0f, 0.0f, 0.0f); +const Vector3f Vector3f::ex(1.0f, 0.0f, 0.0f); +const Vector3f Vector3f::ey(0.0f, 1.0f, 0.0f); +const Vector3f Vector3f::ez(0.0f, 0.0f, 1.0f); + +const Vector3s Vector3s::zero(0, 0, 0); +const Vector3s Vector3s::ex(1, 0, 0); +const Vector3s Vector3s::ey(0, 1, 0); +const Vector3s Vector3s::ez(0, 0, 1); + +f32 Vector3f::normalise() { + f32 len = length(); + if (len > 0.0f) { + x *= 1.0f / len; + y *= 1.0f / len; + z *= 1.0f / len; + } + return len; +} + +f32 Vector3f::setLength(const Vector3f &src, f32 len) { + const f32 mag = src.length(); + + if (mag <= FLT_EPSILON) { + z = 0.0f; + y = 0.0f; + x = 0.0f; + return 0.0f; + } + + x = src.x * (len / mag); + y = src.y * (len / mag); + z = src.z * (len / mag); + + return mag; +} + +f32 Vector3f::setLength(f32 len) { + const f32 mag = length(); + + if (mag <= FLT_EPSILON) { + return 0.0f; + } + + x *= len / mag; + y *= len / mag; + z *= len / mag; + + return mag; +} + +} // namespace EGG \ No newline at end of file -- cgit v1.2.3