X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=libs%2Fmath%2Fvector.h;h=15c31def3aaf871ef252c3a910c591c9b7d223df;hp=a9d2a80905ef1d954e7a6f51caf462576e8aa2ef;hb=0d98822b3c7232c4859c9605653685a7dab86ba8;hpb=3591d7dc01732577ebbb25f3818ccec8f440338f diff --git a/libs/math/vector.h b/libs/math/vector.h index a9d2a809..15c31def 100644 --- a/libs/math/vector.h +++ b/libs/math/vector.h @@ -25,6 +25,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /// \file /// \brief Vector data types and related operations. +#include "generic/vector.h" + #if 0 #define lrint(dbl) ((int)((dbl) + 0.5)) @@ -58,7 +60,6 @@ inline int lrint (double flt) #endif #include -#include #include #include @@ -115,48 +116,6 @@ inline Element float_mod(const Element& self, const ModulusElement& modulus) } -template -class BasicVector2 -{ - Element m_elements[2]; -public: - BasicVector2() - { - } - BasicVector2(const Element& x_, const Element& y_) - { - x() = x_; - y() = y_; - } - - Element& x() - { - return m_elements[0]; - } - const Element& x() const - { - return m_elements[0]; - } - Element& y() - { - return m_elements[1]; - } - const Element& y() const - { - return m_elements[1]; - } - - const Element& operator[](std::size_t i) const - { - return m_elements[i]; - } - Element& operator[](std::size_t i) - { - return m_elements[i]; - } -}; - - template inline BasicVector2 vector2_added(const BasicVector2& self, const BasicVector2& other) { @@ -335,79 +294,6 @@ inline double vector2_cross(const BasicVector2& self, const BasicVector return self.x() * other.y() - self.y() * other.x(); } -typedef BasicVector2 Vector2; - -/// \brief A 3-element vector. -template -class BasicVector3 -{ - Element m_elements[3]; -public: - - BasicVector3() - { - } - template - BasicVector3(const BasicVector3& other) - { - x() = static_cast(other.x()); - y() = static_cast(other.y()); - z() = static_cast(other.z()); - } - BasicVector3(const Element& x_, const Element& y_, const Element& z_) - { - x() = x_; - y() = y_; - z() = z_; - } - - Element& x() - { - return m_elements[0]; - } - const Element& x() const - { - return m_elements[0]; - } - Element& y() - { - return m_elements[1]; - } - const Element& y() const - { - return m_elements[1]; - } - Element& z() - { - return m_elements[2]; - } - const Element& z() const - { - return m_elements[2]; - } - - const Element& operator[](std::size_t i) const - { - return m_elements[i]; - } - Element& operator[](std::size_t i) - { - return m_elements[i]; - } - - operator BasicVector2&() - { - return reinterpret_cast&>(*this); - } - operator const BasicVector2&() const - { - return reinterpret_cast&>(*this); - } -}; - -/// \brief A 3-element vector stored in single-precision floating-point. -typedef BasicVector3 Vector3; - const Vector3 g_vector3_identity(0, 0, 0); const Vector3 g_vector3_max = Vector3(FLT_MAX, FLT_MAX, FLT_MAX); const Vector3 g_vector3_axis_x(1, 0, 0); @@ -416,26 +302,6 @@ const Vector3 g_vector3_axis_z(0, 0, 1); const Vector3 g_vector3_axes[3] = { g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z }; -inline Vector3& vector3_from_array(float* array) -{ - return *reinterpret_cast(array); -} -inline const Vector3& vector3_from_array(const float* array) -{ - return *reinterpret_cast(array); -} - -template -inline Element* vector3_to_array(BasicVector3& self) -{ - return reinterpret_cast(&self); -} -template -inline const Element* vector3_to_array(const BasicVector3& self) -{ - return reinterpret_cast(&self); -} - template inline void vector3_swap(BasicVector3& self, BasicVector3& other) { @@ -743,98 +609,6 @@ inline Vector3 vector3_for_spherical(double theta, double phi) } -/// \brief A 4-element vector. -template -class BasicVector4 -{ - Element m_elements[4]; -public: - - BasicVector4() - { - } - BasicVector4(Element x_, Element y_, Element z_, Element w_) - { - x() = x_; - y() = y_; - z() = z_; - w() = w_; - } - BasicVector4(const BasicVector3& self, Element w_) - { - x() = self.x(); - y() = self.y(); - z() = self.z(); - w() = w_; - } - - Element& x() - { - return m_elements[0]; - } - Element x() const - { - return m_elements[0]; - } - Element& y() - { - return m_elements[1]; - } - Element y() const - { - return m_elements[1]; - } - Element& z() - { - return m_elements[2]; - } - Element z() const - { - return m_elements[2]; - } - Element& w() - { - return m_elements[3]; - } - Element w() const - { - return m_elements[3]; - } - - Element index(std::size_t i) const - { - return m_elements[i]; - } - Element& index(std::size_t i) - { - return m_elements[i]; - } - Element operator[](std::size_t i) const - { - return m_elements[i]; - } - Element& operator[](std::size_t i) - { - return m_elements[i]; - } - - operator BasicVector3&() - { - return reinterpret_cast&>(*this); - } - operator const BasicVector3&() const - { - return reinterpret_cast&>(*this); - } - - bool operator==(const BasicVector4& other) const - { - return x() == other.x() && y() == other.y() && z() == other.z() && w() == other.w(); - } -}; - -/// \brief A 4-element vector stored in single-precision floating-point. -typedef BasicVector4 Vector4; template @@ -862,28 +636,6 @@ inline bool vector4_equal_epsilon(const BasicVector4& self, const Basic && float_equal_epsilon(self.w(), other.w(), epsilon); } -template -inline Element* vector4_to_array(BasicVector4& self) -{ - return reinterpret_cast(&self); -} -template -inline const float* vector4_to_array(const BasicVector4& self) -{ - return reinterpret_cast(&self); -} - -template -inline Vector3& vector4_to_vector3(BasicVector4& self) -{ - return reinterpret_cast&>(self); -} -template -inline const Vector3& vector4_to_vector3(const BasicVector4& self) -{ - return reinterpret_cast&>(self); -} - template inline BasicVector4 vector4_added(const BasicVector4& self, const BasicVector4& other) {