Add initial vector4 implementation
This commit is contained in:
parent
94706bed33
commit
3a9ce03318
34
include/mtl/vec4.hpp
Normal file
34
include/mtl/vec4.hpp
Normal 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
29
src/vec4.cpp
Normal 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
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user