diff --git a/Engine/Source/Runtime/Core/public/Math/Boilerplate.h b/Engine/Source/Runtime/Core/public/Math/Boilerplate.h index e00696a..bed7074 100644 --- a/Engine/Source/Runtime/Core/public/Math/Boilerplate.h +++ b/Engine/Source/Runtime/Core/public/Math/Boilerplate.h @@ -10,7 +10,7 @@ #else #include - + #include #endif diff --git a/Engine/Source/Runtime/Core/public/Math/Detail/Vector3Decl.inl b/Engine/Source/Runtime/Core/public/Math/Detail/Vector3Decl.inl new file mode 100644 index 0000000..8d1d810 --- /dev/null +++ b/Engine/Source/Runtime/Core/public/Math/Detail/Vector3Decl.inl @@ -0,0 +1,211 @@ +#pragma once + +#include "Core/public/Math/Boilerplate.h" + +namespace Phanes::Core::Math::Detail +{ + template + struct construct_vec3 {}; + + template + struct compute_vec3_add {}; + + template + struct compute_vec3_sub {}; + + template + struct compute_vec3_mul {}; + + template + struct compute_vec3_div {}; + + template + struct compute_vec3_eq {}; + + template + struct compute_vec3_ieq {}; + + template + struct compute_vec3_inc {}; + + template + struct compute_vec3_dec {}; + + + + template + struct construct_vec3 + { + static constexpr void map(Phanes::Core::Math::TVector3& v1, const TVector3& v2) + { + v1.x = v2.x; + v1.y = v2.y; + v1.z = v2.z; + v1.w = (T)0.0; + } + + + static constexpr void map(Phanes::Core::Math::TVector3& v1, T s) + { + v1.x = s; + v1.y = s; + v1.z = s; + v1.w = (T)0.0; + } + + static constexpr void map(Phanes::Core::Math::TVector3& v1, T x, T y, T z) + { + v1.x = x; + v1.y = y; + v1.z = z; + v1.w = (T)0.0; + } + + /*static constexpr void map(Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector2& v2, const Phanes::Core::Math::TVector2& v3) + { + v1.x = v2.x; + v1.y = v2.y; + v1.z = v3.x; + v1.w = v3.y; + } + + static constexpr void map(Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector2& v2, const Phanes::Core::Math::TVector2& v3) + { + v1.x = v2.x; + v1.y = v2.y; + v1.z = v3.x; + v1.w = v3.y; + }*/ + + static constexpr void map(Phanes::Core::Math::TVector3& v1, const T* comp) + { + v1.x = comp[0]; + v1.y = comp[1]; + v1.z = comp[2]; + v1.w = (T)0.0; + } + }; + + + template + struct compute_vec3_add + { + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector3& v2) + { + r.x = v1.x + v2.x; + r.y = v1.y + v2.y; + r.z = v1.z + v2.z; + } + + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, T s) + { + r.x = v1.x + s; + r.y = v1.y + s; + r.z = v1.z + s; + } + }; + + + template + struct compute_vec3_sub + { + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector3& v2) + { + r.x = v1.x - v2.x; + r.y = v1.y - v2.y; + r.z = v1.z - v2.z; + } + + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, T s) + { + r.x = v1.x - s; + r.y = v1.y - s; + r.z = v1.z - s; + } + }; + + + template + struct compute_vec3_mul + { + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector3& v2) + { + r.x = v1.x * v2.x; + r.y = v1.y * v2.y; + r.z = v1.z * v2.z; + } + + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, T s) + { + r.x = v1.x * s; + r.y = v1.y * s; + r.z = v1.z * s; + } + }; + + + template + struct compute_vec3_div + { + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector3& v2) + { + r.x = v1.x / v2.x; + r.y = v1.y / v2.y; + r.z = v1.z / v2.z; + } + + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1, T s) + { + s = (T)1.0 / s; + + r.x = v1.x * s; + r.y = v1.y * s; + r.z = v1.z * s; + } + }; + + template + struct compute_vec3_eq + { + static constexpr bool map(const Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector3& v2) + { + return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC && + Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC && + Phanes::Core::Math::Abs(v1.z - v2.z) < P_FLT_INAC); + } + }; + + template + struct compute_vec3_ieq + { + static constexpr bool map(const Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector3& v2) + { + return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC || + Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC || + Phanes::Core::Math::Abs(v1.z - v2.z) > P_FLT_INAC); + } + }; + + template + struct compute_vec3_inc + { + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1) + { + r.x = v1.x + 1; + r.y = v1.y + 1; + r.z = v1.z + 1; + } + }; + + template + struct compute_vec3_dec + { + static constexpr void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1) + { + r.x = v1.x - 1; + r.y = v1.y - 1; + r.z = v1.z - 1; + } + }; +} + diff --git a/Engine/Source/Runtime/Core/public/Math/Detail/Vector4Decl.inl b/Engine/Source/Runtime/Core/public/Math/Detail/Vector4Decl.inl index 4ed98b3..631ef4c 100644 --- a/Engine/Source/Runtime/Core/public/Math/Detail/Vector4Decl.inl +++ b/Engine/Source/Runtime/Core/public/Math/Detail/Vector4Decl.inl @@ -1,36 +1,34 @@ #pragma once #include "Core/public/Math/Boilerplate.h" -#include "Core/public/Math/MathCommon.hpp" -#include "Core/public/Math/MathFwd.h" namespace Phanes::Core::Math::Detail { - template + template struct construct_vec4 {}; - template + template struct compute_vec4_add {}; - template + template struct compute_vec4_sub {}; - template + template struct compute_vec4_mul {}; - template + template struct compute_vec4_div {}; - template - struct compute_vec4_eq{}; + template + struct compute_vec4_eq {}; - template + template struct compute_vec4_ieq {}; - template + template struct compute_vec4_inc {}; - template + template struct compute_vec4_dec {}; diff --git a/Engine/Source/Runtime/Core/public/Math/Include.h b/Engine/Source/Runtime/Core/public/Math/Include.h new file mode 100644 index 0000000..c0ad70c --- /dev/null +++ b/Engine/Source/Runtime/Core/public/Math/Include.h @@ -0,0 +1,4 @@ +#pragma once + +#include "Core/public/Math/Vector3.hpp" +#include "Core/public/Math/Vector4.hpp" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/public/Math/MathFwd.h b/Engine/Source/Runtime/Core/public/Math/MathFwd.h index 1025fc1..33aae52 100644 --- a/Engine/Source/Runtime/Core/public/Math/MathFwd.h +++ b/Engine/Source/Runtime/Core/public/Math/MathFwd.h @@ -27,7 +27,6 @@ namespace Phanes::Core::Math { template struct TColor; template struct TLinearColor; template struct TVector2; - template struct TVector3; template struct TRay; template struct TLine; template struct TPlane; @@ -45,7 +44,8 @@ namespace Phanes::Core::Math { template struct TIntPoint2; template struct TIntPoint3; template struct TIntPoint4; - template struct TVector4; + template struct TVector3; + template struct TVector4; /** * Specific instantiation of forward declarations. @@ -58,13 +58,6 @@ namespace Phanes::Core::Math { typedef std::vector Vector2List; typedef std::vector Vector2Listd; - // TVector3 - typedef TVector3 Vector3; - typedef TVector3 Vector3d; - - typedef std::vector Vector3List; - typedef std::vector Vector3Listd; - // TIntVector2 diff --git a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp index 9e4294b..e42d65f 100644 --- a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp +++ b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp @@ -5,22 +5,77 @@ #include "Core/public/Math/SIMD/PhanesSIMDTypes.h" #include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" - - -#include - // -> For IntelliSense +#include "Core/public/Math/Vector3.hpp" + #include "Core/public/Math/Vector4.hpp" // ========== // // Common // // ========== // - -Phanes::Core::Types::Vec4f32Reg vec4_abs(const Phanes::Core::Types::Vec4f32Reg& v) +namespace Phanes::Core::Math::SIMD { - return _mm_and_ps(v, _mm_castsi128_ps(_mm_set1_epi32(0x7FFFFFFF))); + /// + /// Adds all scalars of the vector. + /// + /// Vector + /// Sum stored in v[0:31]. + Phanes::Core::Types::Vec4f32Reg vec4_hadd(const Phanes::Core::Types::Vec4f32Reg v) + { + __m128 shufl = _mm_movehdup_ps(v); + __m128 sum = _mm_add_ps(v, shufl); + shufl = _mm_movehl_ps(sum, sum); + return _mm_add_ss(sum, shufl); + } + + /// + /// Adds all scalars of the vector. + /// + /// Vector + /// Sum of components. + float vec4_hadd_cvtf32(const Phanes::Core::Types::Vec4f32Reg v) + { + __m128 shufl = _mm_movehdup_ps(v); + __m128 sum = _mm_add_ps(v, shufl); + shufl = _mm_movehl_ps(sum, sum); + sum = _mm_add_ss(sum, shufl); + + return _mm_cvtss_f32(sum); + } + + /// + /// Gets the absolute value of each scalar in the vector. + /// + /// Vector + /// Vector with all components positive. + Phanes::Core::Types::Vec4f32Reg vec4_abs(const Phanes::Core::Types::Vec4f32Reg v) + { + return _mm_and_ps(v, _mm_castsi128_ps(_mm_set1_epi32(0x7FFFFFFF))); + } + + /// + /// Gets the dot product of the + /// + /// + /// + /// + Phanes::Core::Types::Vec4f32Reg vec4_dot(const Phanes::Core::Types::Vec4f32Reg v1, const Phanes::Core::Types::Vec4f32Reg v2) + { + return vec4_hadd(_mm_mul_ps(v1, v2)); + } + + /// + /// Gets the dot product of the + /// + /// + /// + /// + float vec4_dot_cvtf32(const Phanes::Core::Types::Vec4f32Reg v1, const Phanes::Core::Types::Vec4f32Reg v2) + { + return vec4_hadd_cvtf32(_mm_mul_ps(v1, v2)); + } } @@ -41,7 +96,7 @@ namespace Phanes::Core::Math::Detail { static FORCEINLINE void map(Phanes::Core::Math::TVector4& v1, const TVector4& v2) { - v1.comp = _mm_set_ps(v2.x, v2.y, v2.z, v2.w); + v1.comp = _mm_setr_ps(v2.x, v2.y, v2.z, v2.w); } @@ -52,7 +107,7 @@ namespace Phanes::Core::Math::Detail static FORCEINLINE void map(Phanes::Core::Math::TVector4& v1, float x, float y, float z, float w) { - v1.comp = _mm_set_ps(x, y, z, w); + v1.comp = _mm_setr_ps(x, y, z, w); } /*static constexpr void map(Phanes::Core::Math::TVector4& v1, const Phanes::Core::Math::TVector2& v2, const Phanes::Core::Math::TVector2& v3) @@ -83,6 +138,11 @@ namespace Phanes::Core::Math::Detail { r.comp = _mm_add_ps(v1.comp, v2.comp); } + + static FORCEINLINE void map(Phanes::Core::Math::TVector4& r, const Phanes::Core::Math::TVector4& v1, float s) + { + r.comp = _mm_add_ps(v1.comp, _mm_set_ps1(s)); + } }; template<> @@ -92,6 +152,11 @@ namespace Phanes::Core::Math::Detail { r.comp = _mm_sub_ps(v1.comp, v2.comp); } + + static FORCEINLINE void map(Phanes::Core::Math::TVector4& r, const Phanes::Core::Math::TVector4& v1, float s) + { + r.comp = _mm_sub_ps(v1.comp, _mm_set_ps1(s)); + } }; template<> @@ -101,6 +166,11 @@ namespace Phanes::Core::Math::Detail { r.comp = _mm_mul_ps(v1.comp, v2.comp); } + + static FORCEINLINE void map(Phanes::Core::Math::TVector4& r, const Phanes::Core::Math::TVector4& v1, float s) + { + r.comp = _mm_mul_ps(v1.comp, _mm_set_ps1(s)); + } }; template<> @@ -110,6 +180,29 @@ namespace Phanes::Core::Math::Detail { r.comp = _mm_div_ps(v1.comp, v2.comp); } + + static FORCEINLINE void map(Phanes::Core::Math::TVector4& r, const Phanes::Core::Math::TVector4& v1, float s) + { + r.comp = _mm_div_ps(v1.comp, _mm_set_ps1(s)); + } + }; + + template<> + struct compute_vec4_inc + { + static FORCEINLINE void map(Phanes::Core::Math::TVector4& r, const Phanes::Core::Math::TVector4& v1) + { + r.comp = _mm_add_ps(v1.comp, _mm_set_ps1(1.0f)); + } + }; + + template<> + struct compute_vec4_dec + { + static FORCEINLINE void map(Phanes::Core::Math::TVector4& r, const Phanes::Core::Math::TVector4& v1) + { + r.comp = _mm_sub_ps(v1.comp, _mm_set_ps1(1.0f)); + } }; template<> @@ -133,5 +226,63 @@ namespace Phanes::Core::Math::Detail return (r == 0xffffffff) ? true : false; } }; -} + + //// ============ // + //// TVector3 // + //// ============ // + + + template<> + struct construct_vec3 + { + static FORCEINLINE void map(Phanes::Core::Math::TVector3& v1, const TVector3& v2) + { + v1.comp = _mm_setr_ps(v2.x, v2.y, v2.z, 0.0f); + } + + + static FORCEINLINE void map(Phanes::Core::Math::TVector3& v1, float s) + { + v1.comp = _mm_set_ps1(s); + } + + static FORCEINLINE void map(Phanes::Core::Math::TVector3& v1, float x, float y, float z) + { + v1.comp = _mm_setr_ps(x, y, z, 0.0f); + } + + /*static FORCEINLINE void map(Phanes::Core::Math::TVector3& v1, const Phanes::Core::Math::TVector2& v2, float s) + { + v1.comp = _mm_set_ps(v2.x, v2.y, v3.x, v3.y); + }*/ + + static FORCEINLINE void map(Phanes::Core::Math::TVector3& v1, const float* s) + { + v1.comp = _mm_setr_ps(s[0], s[1], s[2], 0.0f); + + } + }; + + + template<> + struct compute_vec3_inc + { + static FORCEINLINE void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1) + { + r.comp = _mm_add_ps(v1.comp, _mm_set_ps(1.0f, 1.0f, 1.0f, 0.0f)); + } + }; + + + template<> + struct compute_vec3_dec + { + static FORCEINLINE void map(Phanes::Core::Math::TVector3& r, const Phanes::Core::Math::TVector3& v1) + { + r.comp = _mm_sub_ps(v1.comp, _mm_set_ps(1.0f, 1.0f, 1.0f, 0.0f)); + } + }; + + template<> struct compute_vec3_add : public compute_vec4_add {}; +} \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/public/Math/SIMD/Storage.h b/Engine/Source/Runtime/Core/public/Math/SIMD/Storage.h index 1e2d7b5..2ea8f17 100644 --- a/Engine/Source/Runtime/Core/public/Math/SIMD/Storage.h +++ b/Engine/Source/Runtime/Core/public/Math/SIMD/Storage.h @@ -17,7 +17,6 @@ namespace Phanes::Core::Math::SIMD typedef struct type { T data[L]; } type; - }; template diff --git a/Engine/Source/Runtime/Core/public/Math/Vector3.hpp b/Engine/Source/Runtime/Core/public/Math/Vector3.hpp index 679eb36..4e4a3a5 100644 --- a/Engine/Source/Runtime/Core/public/Math/Vector3.hpp +++ b/Engine/Source/Runtime/Core/public/Math/Vector3.hpp @@ -6,10 +6,11 @@ #include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" -#include "Core/public/Math/MathAbstractTypes.h" #include "Core/public/Math/MathFwd.h" #include "Core/public/Math/SIMD/Storage.h" +#include "Core/public/Math/Vector4.hpp" + #ifndef P_DEBUG #pragma warning(disable : 4244) #endif @@ -30,128 +31,83 @@ namespace Phanes::Core::Math { // Basic 3D vector (x, y, z) - template - struct TVector3 { + template + struct TVector3 : public TVector4 { public: - + //using Real = T; + //union + //{ + // struct { + // /// + // /// X component of vector + // /// + // Real x; + + // /// + // /// X component of vector + // /// + // Real y; + + // /// + // /// Z component of vector + // /// + // Real z; + + // /// + // /// W component of vector + // /// + // Real w; + + // }; + // /// + // /// Wraps components in one array / xmm register. + // /// + // union + // { + // typename SIMD::Storage<4, Real, SIMD::use_simd::value>::type comp; + // typename SIMD::Storage<4, Real, SIMD::use_simd::value>::type data; + // }; + //}; + using Real = T; - union - { - struct - { - - /** X component of vector - * - * @ref [FIELD]components - * @note x does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real x; - - /** Y component of vector - * - * @ref [FIELD]components - * - * @note y does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real y; - - /** Z component of vector - * - * @ref [FIELD]components - * - * @note Z does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real z; - - }; - - /** Components array holding the data - * - * @ref [FIELD]x - * @ref [FIELD]y - * @ref [FIELD]z - * - * @note Components are split into x, y and z. Access and manipulation is possible by these variables. - */ - - Real comp[3]; - }; - - public: - - /** - * Default contructor without initialization - */ - + /// + /// Default constructor. + /// TVector3() = default; + /// + /// Copy constructor. + /// + /// + TVector3(const TVector3& v); - /** - * Copy contructor - */ + /// + /// Broadcast s into x, y, z. + /// + /// + TVector3(const Real s); - TVector3(const TVector3& v) - { - memcpy(this->comp, comp, sizeof(T) * 3); - } + /// + /// Construct from x, y, z. + /// + /// X component + /// Y component + /// Z component + TVector3(const Real x, const Real y, const Real z); - /** - * Move contructor - */ + /// + /// Construct 3d vector from array of components + /// + /// + TVector3(const Real* comp); - TVector3(TVector3&& v) - { - this->comp = v.comp; - v.comp = nullptr; - } - - /** - * Convert other type of vector - */ - - template - explicit TVector3(const TVector3& v) : x((T)v.x), y((T)v.y) {}; - - /** - * Construct vector from xy components. - * - * @param x X component - * @param y Y component - * @param z Z component - */ - - TVector3(const Real x, const Real y, const Real z) - { - this->x = x; - this->y = y; - this->z = z; - } - - /** - * Contructor vector from two component array - * - * @param comp Array of components - */ - - TVector3(const Real* comp) - { - memcpy(this->comp, comp, sizeof(T) * 3); - } - - /** - * Constructs a vector pointing from start to end. - * - * @param(start) Startingpoint - * @param(end) Endpoint - */ - - TVector3(const TPoint3& start, const TPoint3& end) - { - this->x = end.x - start.x; - this->y = end.y - start.y; - this->z = end.z - start.z; - }; + /// + /// Construct vector from 2d Vector and a scalar. + /// + /// Vector + /// Scalar + TVector3(const TVector2& v, Real s); }; @@ -160,73 +116,49 @@ namespace Phanes::Core::Math { // TVector3 operators // // ====================== // - /** - * Coponentwise addition of floating point to 3D vector - * - * @param(v1) vector to add to - * @param(s) floating point to add - */ + /// + /// Vector addition. + /// + /// Type of vector + /// Vector is aligned? + /// Vector one + /// Vector two + /// Copy of v1. + template + inline TVector3 operator+= (TVector3& v1, const TVector3& v2); - template - inline TVector3 operator+= (TVector3& v1, T s) - { - v1.x += s; - v1.y += s; - v1.z += s; + /// + /// Vector - scalar addition. + /// + /// Type of vector + /// Vector is aligned? + /// Vector one + /// Vector two + /// Copy of v1. + template + inline TVector3 operator+= (TVector3& v1, T s); + + /// + /// Vector substraction. + /// + /// Type of vector + /// Vector is aligned? + /// Vector one + /// Vector two + /// Copy of v1. + template + inline TVector3 operator-= (TVector3& v1, T s); - return v1; - } - - /** - * Coponentwise addition of 3D vector to 3D vector - * - * @param(v1) vector to add to - * @param(v2) vector to add - */ - - template - inline TVector3 operator+= (TVector3& v1, const TVector3& v2) - { - v1.x += v2.x; - v1.y += v2.y; - v1.z += v2.z; - - return v1; - } - - /** - * Coponentwise substraction of floating point of 3D vector - * - * @param(v1) vector to substract from - * @param(s) floating point to substract - */ - - template - inline TVector3 operator-= (TVector3& v1, T s) - { - v1.x -= s; - v1.y -= s; - v1.z -= s; - - return v1; - } - - /** - * Coponentwise substraction of 3D vector to 3D vector - * - * @param(v1) vector to substract from - * @param(v2) vector to substract with - */ - - template - inline TVector3 operator-= (TVector3& v1, const TVector3& v2) - { - v1.x -= v2.x; - v1.y -= v2.y; - v1.z -= v2.z; - - return v1; - } + /// + /// Vector - scalar substraction + /// + /// Type of vector + /// Vector is aligned? + /// Vector one + /// Vector two + /// Copy of v1. + template + inline TVector3 operator-= (TVector3& v1, const TVector3& v2); /** * Dot product between two 3D Vectors @@ -235,15 +167,8 @@ namespace Phanes::Core::Math { * @param(s) floating point */ - template - inline TVector3 operator*= (TVector3& v1, T s) - { - v1.x *= s; - v1.y *= s; - v1.z *= s; - - return v1; - } + template + inline TVector3 operator*= (TVector3& v1, T s); /** * Coponentwise division of 3D vector with floating point @@ -252,16 +177,8 @@ namespace Phanes::Core::Math { * @param(s) floating point to divide with */ - template - inline TVector3 operator/= (TVector3& v1, T s) - { - s = (T)1.0 / s; - v1.x *= s; - v1.y *= s; - v1.z *= s; - - return v1; - } + template + inline TVector3 operator/= (TVector3& v1, T s); /** * Coponentwise multiplication of 3D Vectors with floating point @@ -272,11 +189,8 @@ namespace Phanes::Core::Math { * @return Resulting vector */ - template - TVector3 operator* (const TVector3& v1, T s) - { - return TVector3(v1.x * s, v1.y * s, v1.z * s); - } + template + TVector3 operator* (const TVector3& v1, T s); /** * Coponentwise division of 3D Vectors with floating point @@ -287,12 +201,8 @@ namespace Phanes::Core::Math { * @return Resulting vector */ - template - TVector3 operator/ (const TVector3& v1, T s) - { - s = (T)1.0 / s; - return TVector3(v1.x * s, v1.y * s, v1.z * s); - } + template + TVector3 operator/ (const TVector3& v1, T s); /** * Coponentwise multiplication of 3D Vectors with floating point @@ -303,11 +213,8 @@ namespace Phanes::Core::Math { * @return Resultion vector */ - template - FORCEINLINE TVector3 operator* (T s, const TVector3& v1) - { - return v1 * s; - } + template + FORCEINLINE TVector3 operator* (T s, const TVector3& v1) { return v1 * s; }; /** * Coponentwise multiplication of 3D Vectors with floating point @@ -318,11 +225,8 @@ namespace Phanes::Core::Math { * @return Resultion vector */ - template - FORCEINLINE TVector3 operator/ (T s, const TVector3& v1) - { - return v1 / s; - } + template + FORCEINLINE TVector3 operator/ (T s, const TVector3& v1) { return v1 / s; }; /** * Dot product between two 3D Vectors @@ -333,11 +237,8 @@ namespace Phanes::Core::Math { * @return Dot product of Vectors */ - template - inline T operator* (const TVector3& v1, const TVector3& v2) - { - return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; - } + template + inline T operator* (const TVector3& v1, const TVector3& v2); /** * Coponentwise addition of floating point to 3D vector @@ -348,11 +249,8 @@ namespace Phanes::Core::Math { * @return Resulting vector */ - template - TVector3 operator+ (const TVector3& v1, T s) - { - return TVector3(v1.x + s, v1.y + s, v1.z + s); - } + template + TVector3 operator+ (const TVector3& v1, T s); /** * Coponentwise addition of 3D vector to 3D vector @@ -363,11 +261,8 @@ namespace Phanes::Core::Math { * @return Resulting vector */ - template - TVector3 operator+ (const TVector3& v1, const TVector3& v2) - { - return TVector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); - } + template + TVector3 operator+ (const TVector3& v1, const TVector3& v2); /** * Coponentwise substraction of floating point of 3D vector @@ -378,11 +273,8 @@ namespace Phanes::Core::Math { * @return Resulting vector */ - template - TVector3 operator- (const TVector3& v1, T s) - { - return TVector3(v1.x - s, v1.y - s, v1.z - s); - } + template + TVector3 operator- (const TVector3& v1, T s); /** * Coponentwise substraction of floating point of 3D vector @@ -393,23 +285,8 @@ namespace Phanes::Core::Math { * @return Resulting vector */ - template - TVector3 operator- (const TVector3& v1, const TVector3& v2) - { - return TVector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); - } - - /** - * Negates vector - * - * @param(v1) Vector to negate - */ - - template - TVector3 operator- (const TVector3& v1) - { - return TVector3(-v1.x, -v1.y, -v1.z); - } + template + TVector3 operator- (const TVector3& v1, const TVector3& v2); /** * Tests two 3D vectors for equality. @@ -424,11 +301,8 @@ namespace Phanes::Core::Math { * @note Uses [MACRO]P_FLT_INAC */ - template - inline bool operator== (const TVector3& v1, const TVector3& v2) - { - return (abs(v1.x - v2.x) < P_FLT_INAC && abs(v1.y - v2.y) < P_FLT_INAC && abs(v1.z - v2.z) < P_FLT_INAC); - } + template + inline bool operator== (const TVector3& v1, const TVector3& v2); /** * Tests two 3D vectors for inequality. @@ -439,11 +313,8 @@ namespace Phanes::Core::Math { * @return True if inequal, false if not. */ - template - inline bool operator!= (const TVector3& v1, const TVector3& v2) - { - return (abs(v1.x - v2.x) > P_FLT_INAC || abs(v1.y - v2.y) > P_FLT_INAC || abs(v1.z - v2.z) > P_FLT_INAC); - } + template + inline bool operator!= (const TVector3& v1, const TVector3& v2); // ==================================== // @@ -459,7 +330,7 @@ namespace Phanes::Core::Math { */ template - inline T Magnitude(const TVector3& v1) + inline T Magnitude(const TVector3& v1) { return sqrt(DotP(v1, v1)); } @@ -469,7 +340,7 @@ namespace Phanes::Core::Math { */ template - FORCEINLINE T Length(const TVector3& v1) { return Magnitude(v1); }; + FORCEINLINE T Length(const TVector3& v1) { return Magnitude(v1); }; /** * Gets square magnitude of vector @@ -480,7 +351,7 @@ namespace Phanes::Core::Math { */ template - inline T SqrMagnitude(const TVector3& v1) + inline T SqrMagnitude(const TVector3& v1) { return DotP(v1, v1); } @@ -490,7 +361,7 @@ namespace Phanes::Core::Math { */ template - FORCEINLINE T SqrLength(const TVector3& v1) + FORCEINLINE T SqrLength(const TVector3& v1) { return SqrMagnitude(v1); } @@ -504,7 +375,7 @@ namespace Phanes::Core::Math { */ template - TVector3 NormalizeV(TVector3& v1) + TVector3 NormalizeV(TVector3& v1) { float vecNorm = Magnitude(v1); v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm; @@ -521,7 +392,7 @@ namespace Phanes::Core::Math { */ template - TVector3 UnsafeNormalizeV(TVector3& v1) + TVector3 UnsafeNormalizeV(TVector3& v1) { v1 /= Magnitude(v1); @@ -536,7 +407,7 @@ namespace Phanes::Core::Math { */ template - TVector3 ReflectV(TVector3& v1, const TVector3& normal) + TVector3 ReflectV(TVector3& v1, const TVector3& normal) { Set(v1, v1 - (2 * (v1 * normal) * normal)); @@ -553,7 +424,7 @@ namespace Phanes::Core::Math { */ template - T Angle(const TVector3& v1, const TVector3& v2) + T Angle(const TVector3& v1, const TVector3& v2) { return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2))); } @@ -568,7 +439,7 @@ namespace Phanes::Core::Math { */ template - inline T DotP(const TVector3& v1, const TVector3& v2) + inline T DotP(const TVector3& v1, const TVector3& v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } @@ -582,7 +453,7 @@ namespace Phanes::Core::Math { */ template - void Orthogonalize(TVector3& v1, TVector3& v2, TVector3& v3) + void Orthogonalize(TVector3& v1, TVector3& v2, TVector3& v3) { Set(v2, Reject(v2, v1)); Set(v3, Reject(Reject(v3, v1), v2)); @@ -599,7 +470,7 @@ namespace Phanes::Core::Math { */ template - void OrthoNormalize(TVector3& v1, TVector3& v2, TVector3& v3) + void OrthoNormalize(TVector3& v1, TVector3& v2, TVector3& v3) { Set(v2, Reject(v2, v1)); Set(v3, Reject(Reject(v3, v1), v2)); @@ -618,9 +489,9 @@ namespace Phanes::Core::Math { */ template - TVector3 SignVector(const TVector3& v1) + TVector3 SignVector(const TVector3& v1) { - return TVector3((v1.x >= 0) ? 1 : -1, + return TVector3((v1.x >= 0) ? 1 : -1, (v1.y >= 0) ? 1 : -1, (v1.z >= 0) ? 1 : -1); } @@ -636,7 +507,7 @@ namespace Phanes::Core::Math { */ template - inline bool Equals(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC) + inline bool Equals(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC) { return (abs(v1.x - v2.x) < threshold && abs(v1.y - v2.y) < threshold && abs(v1.z - v2.z) < threshold); } @@ -648,7 +519,7 @@ namespace Phanes::Core::Math { */ template - TVector3 PerspectiveDivideV(TVector3& v1) + TVector3 PerspectiveDivideV(TVector3& v1) { float _z = (T)1.0 / v1.z; v1.x *= _z; @@ -667,7 +538,7 @@ namespace Phanes::Core::Math { */ template - TVector3 CrossPV(TVector3& v1, const TVector3& v2) + TVector3 CrossPV(TVector3& v1, const TVector3& v2) { float x = v1.x; float y = v1.y; @@ -690,7 +561,7 @@ namespace Phanes::Core::Math { */ template - TVector3 MaxV(TVector3& v1, const TVector3& v2) + TVector3 MaxV(TVector3& v1, const TVector3& v2) { v1.x = Max(v1.x, v2.x); v1.y = Max(v1.y, v2.y); @@ -709,7 +580,7 @@ namespace Phanes::Core::Math { */ template - TVector3 MinV(TVector3& v1, const TVector3& v2) + TVector3 MinV(TVector3& v1, const TVector3& v2) { v1.x = Min(v1.x, v2.x); v1.y = Min(v1.y, v2.y); @@ -727,7 +598,7 @@ namespace Phanes::Core::Math { */ template - TVector3 NegateV(TVector3& v1) + TVector3 NegateV(TVector3& v1) { v1.x = -v1.x; v1.y = -v1.y; @@ -746,7 +617,7 @@ namespace Phanes::Core::Math { */ template - TVector3 ScaleV(TVector3& v1, const TVector3& v2) + TVector3 ScaleV(TVector3& v1, const TVector3& v2) { v1.x *= v2.x; v1.y *= v2.y; @@ -765,7 +636,7 @@ namespace Phanes::Core::Math { */ template - TVector3 ProjectV(TVector3& v1, const TVector3& v2) + TVector3 ProjectV(TVector3& v1, const TVector3& v2) { float x = (v1 * v2) / (v2 * v2); v1 = x * v2; @@ -781,7 +652,7 @@ namespace Phanes::Core::Math { */ template - TVector3 RejectV(TVector3& v1, const TVector3& v2) + TVector3 RejectV(TVector3& v1, const TVector3& v2) { float x = (v1 * v2) / (v2 * v2); v1 -= x * v2; @@ -797,7 +668,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Set(TVector3& v1, const TVector3& v2) + TVector3 Set(TVector3& v1, const TVector3& v2) { v1 = v2; @@ -814,7 +685,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Set(TVector3& v1, T x, T y, T z) + TVector3 Set(TVector3& v1, T x, T y, T z) { v1.x = x; v1.y = y; @@ -834,7 +705,7 @@ namespace Phanes::Core::Math { */ template - TVector3 ClampMagnitudeV(TVector3& v1, T min, T max) + TVector3 ClampMagnitudeV(TVector3& v1, T min, T max) { T magnitude = Magnitude(v1); @@ -856,7 +727,7 @@ namespace Phanes::Core::Math { */ template - TVector3 CompInverseV(TVector3& v1) + TVector3 CompInverseV(TVector3& v1) { v1.x = 1.0f / v1.x; v1.y = 1.0f / v1.y; @@ -876,7 +747,7 @@ namespace Phanes::Core::Math { */ template - TVector3 ClampToCubeV(TVector3 v1, T cubeRadius) + TVector3 ClampToCubeV(TVector3 v1, T cubeRadius) { v1.x = Clamp(v1.x, -cubeRadius, cubeRadius); v1.y = Clamp(v1.y, -cubeRadius, cubeRadius); @@ -895,7 +766,7 @@ namespace Phanes::Core::Math { */ template - TVector3 RotateAroundAxisV(TVector3& v1, const TVector3& axisNormal, T angle) + TVector3 RotateAroundAxisV(TVector3& v1, const TVector3& axisNormal, T angle) { T sinAngle = sin(angle); T cosAngle = cos(angle); @@ -914,7 +785,7 @@ namespace Phanes::Core::Math { */ template - TVector3 ScaleToMagnitudeV(TVector3& v1, T magnitude) + TVector3 ScaleToMagnitudeV(TVector3& v1, T magnitude) { NormalizeV(v1) *= magnitude; @@ -928,7 +799,7 @@ namespace Phanes::Core::Math { */ template - TVector3 SignVectorV(TVector3& v1) + TVector3 SignVectorV(TVector3& v1) { v1.x = (v1.x >= 0) ? 1 : -1; v1.y = (v1.y >= 0) ? 1 : -1; @@ -949,7 +820,7 @@ namespace Phanes::Core::Math { */ template - T ScalarTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3) + T ScalarTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3) { return CrossP(v1, v2) * v3; } @@ -965,7 +836,7 @@ namespace Phanes::Core::Math { */ template - T CosineAngle(const TVector3& v1, const TVector3& v2) + T CosineAngle(const TVector3& v1, const TVector3& v2) { return (v1 * v2) / (Magnitude(v1) * Magnitude(v2)); } @@ -981,7 +852,7 @@ namespace Phanes::Core::Math { */ template - TVector3 VectorTripleV(TVector3& v1, const TVector3& v2, const TVector3& v3) + TVector3 VectorTripleV(TVector3& v1, const TVector3& v2, const TVector3& v3) { CrossPV(CrossPV(v1, v2), v3); @@ -999,7 +870,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsPerpendicular(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC) + inline bool IsPerpendicular(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC) { return (abs(DotP(v1, v2)) < threshold); } @@ -1015,7 +886,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsParallel(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC) + inline bool IsParallel(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC) { return (abs(DotP(v1, v2)) > threshold); } @@ -1031,7 +902,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsCoincident(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC) + inline bool IsCoincident(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC) { return (DotP(v1, v2) > threshold); } @@ -1046,7 +917,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsNormalized(const TVector3& v1, T threshold = P_FLT_INAC) + inline bool IsNormalized(const TVector3& v1, T threshold = P_FLT_INAC) { return (SqrMagnitude(v1) < threshold); } @@ -1063,7 +934,7 @@ namespace Phanes::Core::Math { */ template - inline bool IsCoplanar(const TVector3& v1, const TVector3& v2, const TVector3& v3, T threshold = P_FLT_INAC) + inline bool IsCoplanar(const TVector3& v1, const TVector3& v2, const TVector3& v3, T threshold = P_FLT_INAC) { return (ScalarTriple(v1, v2, v3) < threshold); } @@ -1078,7 +949,7 @@ namespace Phanes::Core::Math { */ // - //Matrix3 OuterProduct(const TVector3& v1, const TVector3& v2); + //Matrix3 OuterProduct(const TVector3& v1, const TVector3& v2); // ============ // // WITH RETURN: // @@ -1093,7 +964,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Normalize(const TVector3& v1) + TVector3 Normalize(const TVector3& v1) { float vecNorm = Magnitude(v1); return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm; @@ -1108,7 +979,7 @@ namespace Phanes::Core::Math { */ template - TVector3 UnsafeNormalize(const TVector3& v1) + TVector3 UnsafeNormalize(const TVector3& v1) { return v1 / Magnitude(v1); } @@ -1123,7 +994,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Reflect(const TVector3& v1, const TVector3& normal) + TVector3 Reflect(const TVector3& v1, const TVector3& normal) { return v1 - (2 * (v1 * normal) * normal); } @@ -1138,10 +1009,10 @@ namespace Phanes::Core::Math { */ template - TVector3 PerspectiveDivide(const TVector3& v1) + TVector3 PerspectiveDivide(const TVector3& v1) { float _z = (T)1.0 / v1.z; - return TVector3(v1.x * _z, v1.y * _z, (T)0.0); + return TVector3(v1.x * _z, v1.y * _z, (T)0.0); } /** @@ -1154,9 +1025,9 @@ namespace Phanes::Core::Math { */ template - TVector3 CrossP(const TVector3& v1, const TVector3& v2) + TVector3 CrossP(const TVector3& v1, const TVector3& v2) { - return TVector3((v1.y * v2.z) - (v1.z * v2.y), + return TVector3((v1.y * v2.z) - (v1.z * v2.y), (v1.z * v2.x) - (v1.x * v2.z), (v1.x * v2.y) - (v1.y * v2.x)); } @@ -1172,7 +1043,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Lerp(const TVector3& start, const TVector3& dest, T t) + TVector3 Lerp(const TVector3& start, const TVector3& dest, T t) { t = Clamp(t, (T)0.0, (T), 1.0); return (1 - t) * start + t * dest; @@ -1190,7 +1061,7 @@ namespace Phanes::Core::Math { */ template - TVector3 LerpUnclamped(const TVector3& start, const TVector3& dest, T t) + TVector3 LerpUnclamped(const TVector3& start, const TVector3& dest, T t) { return (1 - t) * start + t * dest; } @@ -1205,9 +1076,9 @@ namespace Phanes::Core::Math { */ template - TVector3 Max(const TVector3& v1, const TVector3& v2) + TVector3 Max(const TVector3& v1, const TVector3& v2) { - return TVector3((v1.x > v2.x) ? v1.x : v2.x, + return TVector3((v1.x > v2.x) ? v1.x : v2.x, (v1.y > v2.y) ? v1.y : v2.y, (v1.z > v2.z) ? v1.z : v2.z); } @@ -1222,9 +1093,9 @@ namespace Phanes::Core::Math { */ template - TVector3 Min(const TVector3& v1, const TVector3& v2) + TVector3 Min(const TVector3& v1, const TVector3& v2) { - return TVector3((v1.x < v2.x) ? v1.x : v2.x, + return TVector3((v1.x < v2.x) ? v1.x : v2.x, (v1.y < v2.y) ? v1.y : v2.y, (v1.z < v2.z) ? v1.z : v2.z); } @@ -1238,9 +1109,9 @@ namespace Phanes::Core::Math { */ template - TVector3 Negate(const TVector3& v1) + TVector3 Negate(const TVector3& v1) { - return TVector3(-v1.x, -v1.y, -v1.z); + return TVector3(-v1.x, -v1.y, -v1.z); } /** @@ -1253,9 +1124,9 @@ namespace Phanes::Core::Math { */ template - TVector3 Scale(const TVector3& v1, const TVector3& v2) + TVector3 Scale(const TVector3& v1, const TVector3& v2) { - return TVector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); + return TVector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); } /** @@ -1269,11 +1140,11 @@ namespace Phanes::Core::Math { */ template - TVector3 ClampMagnitude(const TVector3& v1, T min, T max) + TVector3 ClampMagnitude(const TVector3& v1, T min, T max) { T magnitude = Magnitude(v1); - const TVector3 unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); + const TVector3 unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); Clamp(magnitude, min, max); @@ -1290,12 +1161,12 @@ namespace Phanes::Core::Math { */ template - TVector3 ClampToCube(const TVector3& v1, T cubeRadius) + TVector3 ClampToCube(const TVector3& v1, T cubeRadius) { - return TVector3( + return TVector3( Clamp(v1.x, -cubeRadius, cubeRadius), Clamp(v1.y, -cubeRadius, cubeRadius), - Clamp(v1.z, -cubeRadius, cubeRadius), + Clamp(v1.z, -cubeRadius, cubeRadius) ); }; @@ -1308,7 +1179,7 @@ namespace Phanes::Core::Math { */ template - TVector3 ScaleToMagnitude(const TVector3& v1, T magnitude) + TVector3 ScaleToMagnitude(const TVector3& v1, T magnitude) { return Normalize(v1) * magnitude; } @@ -1322,9 +1193,9 @@ namespace Phanes::Core::Math { */ template - TVector3 CompInverse(const TVector3& v1) + TVector3 CompInverse(const TVector3& v1) { - return TVector3((T)1.0f / v1.x, (T)1.0f / v1.y, (T)1.0f / v1.z); + return TVector3((T)1.0f / v1.x, (T)1.0f / v1.y, (T)1.0f / v1.z); } /** @@ -1338,7 +1209,7 @@ namespace Phanes::Core::Math { */ template - TVector3 RotateAroundAxis(const TVector3& v1, const TVector3& axisNormal, T angle) + TVector3 RotateAroundAxis(const TVector3& v1, const TVector3& axisNormal, T angle) { T sinAngle = sin(angle); T cosAngle = cos(angle); @@ -1357,7 +1228,7 @@ namespace Phanes::Core::Math { */ template - TVector3 VectorTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3) + TVector3 VectorTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3) { return CrossP(CrossP(v1, v2), v3); } @@ -1372,7 +1243,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Project(const TVector3& v1, const TVector3& v2) + TVector3 Project(const TVector3& v1, const TVector3& v2) { return (DotP(v1, v2) / DotP(v2, v2)) * v2; } @@ -1387,7 +1258,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Reject(const TVector3& v1, const TVector3& v2) + TVector3 Reject(const TVector3& v1, const TVector3& v2) { return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2; } @@ -1403,7 +1274,7 @@ namespace Phanes::Core::Math { */ template - TVector3 Slerp(const TVector3& v1, const TVector3& v2, T t) {}; + TVector3 Slerp(const TVector3& v1, const TVector3& v2, T t) {}; /** * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. @@ -1417,9 +1288,11 @@ namespace Phanes::Core::Math { */ template - TVector3 SlerpUnclamped(const TVector3& v1, const TVector3& v2, T t) {}; + TVector3 SlerpUnclamped(const TVector3& v1, const TVector3& v2, T t) {}; } // phanes #endif // !VECTOR3_H + +#include "Core/public/Math/Vector3.inl" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/public/Math/Vector3.inl b/Engine/Source/Runtime/Core/public/Math/Vector3.inl new file mode 100644 index 0000000..4e87bdc --- /dev/null +++ b/Engine/Source/Runtime/Core/public/Math/Vector3.inl @@ -0,0 +1,211 @@ +#pragma once + +#include "Core/public/Math/Boilerplate.h" + +#include "Core/public/Math/Detail/Vector3Decl.inl" +#include "Core/public/Math/SIMD/SIMDIntrinsics.h" + +#include "Core/public/Math/SIMD/PhanesSIMDTypes.h" + + + +namespace Phanes::Core::Math +{ + template + TVector3::TVector3(const TVector3& v) + { + Detail::construct_vec3::value>::map(*this, v); + } + + template + TVector3::TVector3(Real _x, Real _y, Real _z) + { + Detail::construct_vec3::value>::map(*this, _x, _y, _z); + } + + template + TVector3::TVector3(Real s) + { + Detail::construct_vec3::value>::map(*this, s); + } + + template + TVector3::TVector3(const TVector2& v1, Real s) + { + Detail::construct_vec3::value>::map(*this, v1.x, v1.y, s); + } + + template + TVector3::TVector3(const Real* comp) + { + Detail::construct_vec3::value>::map(*this, comp); + } + + + + + template + TVector3 operator+=(TVector3& v1, const TVector3& v2) + { + Detail::compute_vec3_add::value>::map(v1, v1, v2); + return v1; + } + + template + TVector3 operator+=(TVector3& v1, T s) + { + Detail::compute_vec3_add::value>::map(v1, v1, s); + return v1; + } + + template + TVector3 operator-=(TVector3& v1, const TVector3& v2) + { + Detail::compute_vec3_sub::value>::map(v1, v1, v2); + return v1; + } + + template + TVector3 operator-=(TVector3& v1, T s) + { + Detail::compute_vec3_sub::value>::map(v1, v1, s); + return v1; + } + + template + TVector3 operator*=(TVector3& v1, const TVector3& v2) + { + Detail::compute_vec3_mul::value>::map(v1, v1, v2); + return v1; + } + + template + TVector3 operator*=(TVector3& v1, T s) + { + Detail::compute_vec3_mul::value>::map(v1, v1, s); + return v1; + } + + template + TVector3 operator/=(TVector3& v1, const TVector3& v2) + { + Detail::compute_vec3_div::value>::map(v1, v1, v2); + return v1; + } + + template + TVector3 operator/=(TVector3& v1, T s) + { + Detail::compute_vec3_div::value>::map(v1, v1, s); + return v1; + } + + template + TVector3 operator+(TVector3& v1, const TVector3& v2) + { + TVector3 r; + Detail::compute_vec3_add::value>::map(r, v1, v2); + return r; + } + + template + TVector3 operator+(TVector3& v1, T s) + { + TVector3 r; + Detail::compute_vec3_add::value>::map(r, v1, s); + return r; + } + + template + TVector3 operator-(TVector3& v1, const TVector3& v2) + { + TVector3 r; + Detail::compute_vec3_sub::value>::map(r, v1, v2); + return r; + } + + template + TVector3 operator-(TVector3& v1, T s) + { + TVector3 r; + Detail::compute_vec3_sub::value>::map(r, v1, s); + return r; + } + + template + TVector3 operator*(TVector3& v1, const TVector3& v2) + { + TVector3 r; + Detail::compute_vec3_mul::value>::map(r, v1, v2); + return r; + } + + template + TVector3 operator*(TVector3& v1, T s) + { + TVector3 r; + Detail::compute_vec3_mul::value>::map(r, v1, s); + return r; + } + + template + TVector3 operator/(TVector3& v1, const TVector3& v2) + { + TVector3 r; + Detail::compute_vec3_div::value>::map(r, v1, v2); + return r; + } + + template + TVector3 operator/(TVector3& v1, T s) + { + TVector3 r; + Detail::compute_vec3_div::value>::map(r, v1, s); + return r; + } + + // Comparision + + template + bool operator==(const TVector3& v1, const TVector3& v2) + { + return Detail::compute_vec3_eq::value>::map(v1, v2); + } + + template + bool operator!=(const TVector3& v1, const TVector3& v2) + { + return Detail::compute_vec3_ieq::value>::map(v1, v2); + } + + + + // Inc- / Decrement + + + template + TVector3& operator++(TVector3& v1) + { + Detail::compute_vec3_inc::value>::map(v1); + return v1; + } + + template + TVector3& operator--(TVector3& v1) + { + Detail::compute_vec3_inc::value>::map(v1); + return v1; + } + + template + TVector3& operator++(TVector3& v1, int) + { + return ++v1; + } + + template + TVector3& operator--(TVector3& v1, int) + { + return --v1; + } +} \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/public/Math/Vector4.hpp b/Engine/Source/Runtime/Core/public/Math/Vector4.hpp index 0283756..abad58d 100644 --- a/Engine/Source/Runtime/Core/public/Math/Vector4.hpp +++ b/Engine/Source/Runtime/Core/public/Math/Vector4.hpp @@ -7,6 +7,7 @@ #include "Core/public/Math/MathFwd.h" + #include "Core/public/Math/Vector2.hpp" namespace Phanes::Core::Math @@ -14,7 +15,7 @@ namespace Phanes::Core::Math /// 4D Vector defined with x, y, z, w. /// Alignment allows for possible simd optimization. - template + template struct TVector4 { public: @@ -48,8 +49,8 @@ namespace Phanes::Core::Math /// union { - typename Phanes::Core::Math::SIMD::Storage<4, Real, SIMD::use_simd::value>::type comp; - typename Phanes::Core::Math::SIMD::Storage<4, Real, SIMD::use_simd::value>::type data; + typename SIMD::Storage<4, Real, SIMD::use_simd::value>::type comp; + typename SIMD::Storage<4, Real, SIMD::use_simd::value>::type data; }; }; @@ -58,7 +59,7 @@ namespace Phanes::Core::Math TVector4() = default; /// Copy constructor - TVector4(const TVector4& v); + TVector4(const TVector4& v); /// /// Construct vector from one scalar. diff --git a/Engine/Source/Runtime/Core/public/Math/Vector4.inl b/Engine/Source/Runtime/Core/public/Math/Vector4.inl index faff256..0ff1b1c 100644 --- a/Engine/Source/Runtime/Core/public/Math/Vector4.inl +++ b/Engine/Source/Runtime/Core/public/Math/Vector4.inl @@ -5,13 +5,9 @@ #include "Core/public/Math/Detail/Vector4Decl.inl" #include "Core/public/Math/SIMD/SIMDIntrinsics.h" -#include "Core/public/Math/Vector4.hpp" - #include "Core/public/Math/SIMD/PhanesSIMDTypes.h" -#include - namespace Phanes::Core::Math { template @@ -48,56 +44,56 @@ namespace Phanes::Core::Math template TVector4 operator+=(TVector4& v1, const TVector4& v2) { - Detail::compute_vec4_add::map(v1, v1, v2); + Detail::compute_vec4_add::value>::map(v1, v1, v2); return v1; } template TVector4 operator+=(TVector4& v1, T s) { - Detail::compute_vec4_add::map(v1, v1, s); + Detail::compute_vec4_add::value>::map(v1, v1, s); return v1; } template TVector4 operator-=(TVector4& v1, const TVector4& v2) { - Detail::compute_vec4_sub::map(v1, v1, v2); + Detail::compute_vec4_sub::value>::map(v1, v1, v2); return v1; } template TVector4 operator-=(TVector4& v1, T s) { - Detail::compute_vec4_sub::map(v1, v1, s); + Detail::compute_vec4_sub::value>::map(v1, v1, s); return v1; } template TVector4 operator*=(TVector4& v1, const TVector4& v2) { - Detail::compute_vec4_mul::map(v1, v1, v2); + Detail::compute_vec4_mul::value>::map(v1, v1, v2); return v1; } template TVector4 operator*=(TVector4& v1, T s) { - Detail::compute_vec4_mul::map(v1, v1, s); + Detail::compute_vec4_mul::value>::map(v1, v1, s); return v1; } template TVector4 operator/=(TVector4& v1, const TVector4& v2) { - Detail::compute_vec4_div::map(v1, v1, v2); + Detail::compute_vec4_div::value>::map(v1, v1, v2); return v1; } template TVector4 operator/=(TVector4& v1, T s) { - Detail::compute_vec4_div::map(v1, v1, s); + Detail::compute_vec4_div::value>::map(v1, v1, s); return v1; } @@ -105,7 +101,7 @@ namespace Phanes::Core::Math TVector4 operator+(TVector4& v1, const TVector4& v2) { TVector4 r; - Detail::compute_vec4_add::map(r, v1, v2); + Detail::compute_vec4_add::value>::map(r, v1, v2); return r; } @@ -113,7 +109,7 @@ namespace Phanes::Core::Math TVector4 operator+(TVector4& v1, T s) { TVector4 r; - Detail::compute_vec4_add::map(r, v1, s); + Detail::compute_vec4_add::value>::map(r, v1, s); return r; } @@ -121,7 +117,7 @@ namespace Phanes::Core::Math TVector4 operator-(TVector4& v1, const TVector4& v2) { TVector4 r; - Detail::compute_vec4_sub::map(r, v1, v2); + Detail::compute_vec4_sub::value>::map(r, v1, v2); return r; } @@ -129,7 +125,7 @@ namespace Phanes::Core::Math TVector4 operator-(TVector4& v1, T s) { TVector4 r; - Detail::compute_vec4_sub::map(r, v1, s); + Detail::compute_vec4_sub::value>::map(r, v1, s); return r; } @@ -137,7 +133,7 @@ namespace Phanes::Core::Math TVector4 operator*(TVector4& v1, const TVector4& v2) { TVector4 r; - Detail::compute_vec4_mul::map(r, v1, v2); + Detail::compute_vec4_mul::value>::map(r, v1, v2); return r; } @@ -145,7 +141,7 @@ namespace Phanes::Core::Math TVector4 operator*(TVector4& v1, T s) { TVector4 r; - Detail::compute_vec4_mul::map(r, v1, s); + Detail::compute_vec4_mul::value>::map(r, v1, s); return r; } @@ -153,7 +149,7 @@ namespace Phanes::Core::Math TVector4 operator/(TVector4& v1, const TVector4& v2) { TVector4 r; - Detail::compute_vec4_div::map(r, v1, v2); + Detail::compute_vec4_div::value>::map(r, v1, v2); return r; } @@ -161,7 +157,7 @@ namespace Phanes::Core::Math TVector4 operator/(TVector4& v1, T s) { TVector4 r; - Detail::compute_vec4_div::map(r, v1, s); + Detail::compute_vec4_div::value>::map(r, v1, s); return r; } @@ -170,13 +166,13 @@ namespace Phanes::Core::Math template bool operator==(const TVector4& v1, const TVector4& v2) { - return Detail::compute_vec4_eq::map(v1, v2); + return Detail::compute_vec4_eq::value>::map(v1, v2); } template bool operator!=(const TVector4& v1, const TVector4& v2) { - return Detail::compute_vec4_ieq::map(v1, v2); + return Detail::compute_vec4_ieq::value>::map(v1, v2); } @@ -187,22 +183,14 @@ namespace Phanes::Core::Math template TVector4& operator++(TVector4& v1) { - ++v1.x; - ++v1.y; - ++v1.z; - ++v1.w; - + Detail::compute_vec4_inc::value>::map(v1); return v1; } template TVector4& operator--(TVector4& v1) { - --v1.x; - --v1.y; - --v1.z; - --v1.w; - + Detail::compute_vec4_dec::value>::map(v1); return v1; }