From 3a9ce033186cf349b6285cbba92b1add8494ac3b Mon Sep 17 00:00:00 2001 From: Myles Busig Date: Tue, 30 Jul 2024 11:49:07 -0600 Subject: [PATCH] Add initial vector4 implementation --- include/mtl/vec4.hpp | 34 ++++++++++++++++++++++++++++++++++ src/vec4.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 include/mtl/vec4.hpp create mode 100644 src/vec4.cpp diff --git a/include/mtl/vec4.hpp b/include/mtl/vec4.hpp new file mode 100644 index 0000000..d6c4d5c --- /dev/null +++ b/include/mtl/vec4.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "mtl/target.hpp" + +#include "mtl/fixed.hpp" + +TARGET_ARM_MODE + +namespace mtl { + +class vec4 { +public: + fixed x, y, z, w; + + constexpr vec4(fixed _x = 0, fixed _y = 0, fixed _z = 0, fixed _w = 0) + : x(_x), y(_y), z(_z), w(_w) {} + + vec4 operator+(const vec4& rhs) const; + vec4 operator-(const vec4& rhs) const; + + vec4 operator*(fixed rhs) const; + friend vec4 operator*(fixed lhs, const vec4& rhs) { + return rhs * lhs; + } + + fixed operator*(const vec4& rhs) const; + + fixed magnitude_sqr() const; +}; + +} // namespace mtl + +TARGET_END_MODE + diff --git a/src/vec4.cpp b/src/vec4.cpp new file mode 100644 index 0000000..0b95e8e --- /dev/null +++ b/src/vec4.cpp @@ -0,0 +1,29 @@ +#include "mtl/vec4.hpp" + +TARGET_ARM_MODE + +namespace mtl { + +GBA_IWRAM vec4 vec4::operator+(const vec4& rhs) const { + return vec4(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w); +} +GBA_IWRAM vec4 vec4::operator-(const vec4& rhs) const { + return vec4(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w); +} + +GBA_IWRAM vec4 vec4::operator*(fixed rhs) const { + return vec4(x * rhs, y * rhs, z * rhs, w * rhs); +} + +GBA_IWRAM fixed vec4::operator*(const vec4& rhs) const { + return x * rhs.x + y * rhs.y + z * rhs.z + w * rhs.w; +} + +GBA_IWRAM fixed vec4::magnitude_sqr() const { + return x * x + y * y + z * z + w * w; +} + +} // namespace mtl + +TARGET_END_MODE +