summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/pch.hh2
-rw-r--r--core/vectors.hh49
2 files changed, 50 insertions, 1 deletions
diff --git a/core/pch.hh b/core/pch.hh
index a2199a2..9bd9c43 100644
--- a/core/pch.hh
+++ b/core/pch.hh
@@ -34,8 +34,8 @@
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
-#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <physfs.h>
diff --git a/core/vectors.hh b/core/vectors.hh
new file mode 100644
index 0000000..e6e185a
--- /dev/null
+++ b/core/vectors.hh
@@ -0,0 +1,49 @@
+#ifndef CORE_VECTORS_HH
+#define CORE_VECTORS_HH 1
+#pragma once
+
+// cxvectors.hh - because NO ONE would POSSIBLY
+// need integer-based distance calculations in a
+// game about voxels. That would be INSANE! :D
+
+namespace cxvectors
+{
+template<typename value_type>
+constexpr static inline const value_type length2(const glm::vec<2, value_type> &vector);
+template<typename value_type>
+constexpr static inline const value_type length2(const glm::vec<3, value_type> &vector);
+template<typename value_type>
+constexpr static inline const value_type distance2(const glm::vec<2, value_type> &vector_a, const glm::vec<2, value_type> &vector_b);
+template<typename value_type>
+constexpr static inline const value_type distance2(const glm::vec<3, value_type> &vector_a, const glm::vec<3, value_type> &vector_b);
+} // namespace cxvectors
+
+template<typename value_type>
+constexpr static inline const value_type cxvectors::length2(const glm::vec<2, value_type> &vector)
+{
+ static_assert(std::is_arithmetic_v<value_type>);
+ return (vector.x * vector.x) + (vector.y * vector.y);
+}
+
+template<typename value_type>
+constexpr static inline const value_type cxvectors::length2(const glm::vec<3, value_type> &vector)
+{
+ static_assert(std::is_arithmetic_v<value_type>);
+ return (vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z);
+}
+
+template<typename value_type>
+constexpr static inline const value_type cxvectors::distance2(const glm::vec<2, value_type> &vector_a, const glm::vec<2, value_type> &vector_b)
+{
+ static_assert(std::is_arithmetic_v<value_type>);
+ return cxvectors::length2(vector_a - vector_b);
+}
+
+template<typename value_type>
+constexpr static inline const value_type cxvectors::distance2(const glm::vec<3, value_type> &vector_a, const glm::vec<3, value_type> &vector_b)
+{
+ static_assert(std::is_arithmetic_v<value_type>);
+ return cxvectors::length2(vector_a - vector_b);
+}
+
+#endif /* CORE_VECTORS_HH */