aboutsummaryrefslogtreecommitdiff
path: root/src/math/utils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/utils.hpp')
-rw-r--r--src/math/utils.hpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/math/utils.hpp b/src/math/utils.hpp
new file mode 100644
index 0000000..5ec5959
--- /dev/null
+++ b/src/math/utils.hpp
@@ -0,0 +1,24 @@
+#ifndef MATH_UTILS_HPP
+#define MATH_UTILS_HPP
+
+#include <array>
+#include <utility>
+#include "math/vector.hpp"
+
+namespace engine::math::utils {
+
+template<size_t size> struct Vector;
+template<> struct Vector<2> { using type = engine::math::Vector2; };
+template<> struct Vector<3> { using type = engine::math::Vector3; };
+template<> struct Vector<4> { using type = engine::math::Vector4; };
+
+template<size_t vector_size>
+constexpr Vector<vector_size>::type array_to_vec(const std::array<float, vector_size>& coords) {
+ return [&]<size_t... i>(std::index_sequence<i...>) constexpr -> Vector<vector_size>::type {
+ return { coords[i] ... };
+ }(std::make_index_sequence<vector_size>());
+}
+
+}
+
+#endif // MATH_UTILS_HPP