summaryrefslogtreecommitdiff
path: root/src/Math
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-08-06 04:27:07 +0200
committerMel <einebeere@gmail.com>2023-08-06 04:27:07 +0200
commit5a1b126f1f6d55226c2b5068d0c17c428fd29ba8 (patch)
tree3acc0240cd8dedd0764eeae6df04e134b04584c8 /src/Math
parente6f5f9e03f673db796f1babb308609ca2576db2f (diff)
downloadmeowcraft-5a1b126f1f6d55226c2b5068d0c17c428fd29ba8.tar.zst
meowcraft-5a1b126f1f6d55226c2b5068d0c17c428fd29ba8.zip
Create separate Player entity and add bad collision system
Diffstat (limited to 'src/Math')
-rw-r--r--src/Math/AABB.hpp25
-rw-r--r--src/Math/Matrix.hpp3
-rw-r--r--src/Math/Rotation.hpp25
-rw-r--r--src/Math/Vector.hpp4
4 files changed, 42 insertions, 15 deletions
diff --git a/src/Math/AABB.hpp b/src/Math/AABB.hpp
index 2c02abf..11d26a8 100644
--- a/src/Math/AABB.hpp
+++ b/src/Math/AABB.hpp
@@ -1,10 +1,27 @@
#pragma once
-#include "Vector.hpp"
-namespace Math {
+#include <array>
+#include "Vector.hpp"
struct AABB {
+ AABB() = default;
+ AABB(Vector<3> min, Vector<3> max) : min(min), max(max) {}
+ explicit AABB(Vector<3> max) : max(max) {}
+
+ std::array<Vector<3>, 8> corners() const {
+ return {{
+ {min.x(), min.y(), min.z()},
+ {min.x(), min.y(), max.z()},
+ {min.x(), max.y(), min.z()},
+ {min.x(), max.y(), max.z()},
+ {max.x(), min.y(), min.z()},
+ {max.x(), min.y(), max.z()},
+ {max.x(), max.y(), min.z()},
+ {max.x(), max.y(), max.z()},
+ }};
+ }
+
+ AABB offset(Vector<3> by) const { return {min + by, max + by}; }
+
Vector<3> min, max;
};
-
-}
diff --git a/src/Math/Matrix.hpp b/src/Math/Matrix.hpp
index 41d3661..c4532c3 100644
--- a/src/Math/Matrix.hpp
+++ b/src/Math/Matrix.hpp
@@ -3,7 +3,6 @@
#include <sstream>
#include "../Common/Sizes.hpp"
#include "Rotation.hpp"
-#include "Trig.hpp"
template <uint R, uint C, typename T = Real>
struct Matrix {
@@ -47,7 +46,7 @@ struct Matrix {
}
static Matrix<4, 4, T> rotation(Rotation angles) {
- auto radians = angles.vector.map([](auto a) { return Math::radians(a); });
+ auto radians = angles.radians();
auto c = radians.map([](auto a) { return cos(a); });
auto s = radians.map([](auto a) { return sin(a); });
diff --git a/src/Math/Rotation.hpp b/src/Math/Rotation.hpp
index 83c1109..d5bc023 100644
--- a/src/Math/Rotation.hpp
+++ b/src/Math/Rotation.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <cmath>
+#include "Trig.hpp"
#include "Vector.hpp"
struct Rotation {
@@ -14,10 +15,19 @@ struct Rotation {
vector = wrap({pitch, yaw, roll });
}
+ Vector<3> radians() const {
+ return vector.map([](auto a) { return Math::radians(a); });
+ }
+
Rotation operator+(Rotation other) const {
return wrap(vector + other.vector);
}
+ Rotation& operator+=(const Rotation& other) {
+ *this = *this + other;
+ return *this;
+ }
+
std::string string() const {
return vector.string();
}
@@ -26,17 +36,14 @@ struct Rotation {
return v.map([](auto a) { return fmod(a, 360.0f); });
}
- Real& pitch() {
- return vector[0];
- }
+ Real& pitch() { return vector.x(); }
+ const Real& pitch() const { return vector.x(); }
- Real& yaw() {
- return vector[1];
- }
+ Real& yaw() { return vector.y(); }
+ const Real& yaw() const { return vector.y(); }
- Real& roll() {
- return vector[2];
- }
+ Real& roll() { return vector.z(); }
+ const Real& roll() const { return vector.z(); }
Vector<3> vector;
}; \ No newline at end of file
diff --git a/src/Math/Vector.hpp b/src/Math/Vector.hpp
index 3d9cb0e..a7c3782 100644
--- a/src/Math/Vector.hpp
+++ b/src/Math/Vector.hpp
@@ -190,3 +190,7 @@ struct Vector {
T elements[S];
};
+
+using Vec2 = Vector<2, Real>;
+using Vec3 = Vector<3, Real>;
+using Vec4 = Vector<4, Real>; \ No newline at end of file