Add initial vector4 implementation

This commit is contained in:
Madeline Busig 2024-07-30 11:49:07 -06:00
parent 2181557d9d
commit 233512f5b4
2 changed files with 63 additions and 0 deletions

34
include/mtl/vec4.hpp Normal file
View File

@ -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

29
src/vec4.cpp Normal file
View File

@ -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