diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 357babaa5..53850c631 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -9,6 +9,9 @@ #include +template class NzVector3; +template class NzVector4; + template class NzVector2 { @@ -19,6 +22,8 @@ class NzVector2 NzVector2(const T vec[2]); template explicit NzVector2(const NzVector2& vec); NzVector2(const NzVector2& vec) = default; + explicit NzVector2(const NzVector3& vec); + explicit NzVector2(const NzVector4& vec); ~NzVector2() = default; T AbsDotProduct(const NzVector2& vec) const; @@ -48,6 +53,8 @@ class NzVector2 NzVector2& Set(T scale); NzVector2& Set(const T vec[2]); NzVector2& Set(const NzVector2& vec); + NzVector2& Set(const NzVector3& vec); + NzVector2& Set(const NzVector4& vec); template NzVector2& Set(const NzVector2& vec); T SquaredDistance(const NzVector2& vec) const; diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 227d95425..f97786610 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -36,6 +36,18 @@ NzVector2::NzVector2(const NzVector2& vec) Set(vec); } +template +NzVector2::NzVector2(const NzVector3& vec) +{ + Set(vec); +} + +template +NzVector2::NzVector2(const NzVector4& vec) +{ + Set(vec); +} + template T NzVector2::AbsDotProduct(const NzVector2& vec) const { @@ -208,6 +220,24 @@ NzVector2& NzVector2::Set(const NzVector2& vec) return *this; } +template +NzVector2& NzVector2::Set(const NzVector3& vec) +{ + x = vec.x; + y = vec.y; + + return *this; +} + +template +NzVector2& NzVector2::Set(const NzVector4& vec) +{ + x = vec.x; + y = vec.y; + + return *this; +} + template T NzVector2::SquaredDistance(const NzVector2& vec) const { diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 875662270..e8fe8f7d0 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -8,18 +8,23 @@ #define NAZARA_VECTOR3_HPP #include -#include -template class NzVector3 +template class NzVector2; +template class NzVector4; + +template +class NzVector3 { public: NzVector3() = default; NzVector3(T X, T Y, T Z); + NzVector3(T X, const NzVector2& vec); explicit NzVector3(T scale); NzVector3(const T vec[3]); NzVector3(const NzVector2& vec, T Z = 0.0); template explicit NzVector3(const NzVector3& vec); NzVector3(const NzVector3& vec) = default; + explicit NzVector3(const NzVector4& vec); ~NzVector3() = default; T AbsDotProduct(const NzVector3& vec) const; @@ -56,11 +61,13 @@ template class NzVector3 NzVector3& Normalize(T* length = nullptr); NzVector3& Set(T X, T Y, T Z); + NzVector3& Set(T X, const NzVector2& vec); NzVector3& Set(T scale); NzVector3& Set(const T vec[3]); NzVector3& Set(const NzVector2& vec, T Z = 0.0); NzVector3& Set(const NzVector3& vec); template NzVector3& Set(const NzVector3& vec); + NzVector3& Set(const NzVector4& vec); T SquaredDistance(const NzVector3& vec) const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index f300330b8..fb395a748 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -17,6 +17,12 @@ NzVector3::NzVector3(T X, T Y, T Z) Set(X, Y, Z); } +template +NzVector3::NzVector3(T X, const NzVector2& vec) +{ + Set(X, vec); +} + template NzVector3::NzVector3(T scale) { @@ -42,6 +48,12 @@ NzVector3::NzVector3(const NzVector3& vec) Set(vec); } +template +NzVector3::NzVector3(const NzVector4& vec) +{ + Set(vec); +} + template T NzVector3::AbsDotProduct(const NzVector3& vec) const { @@ -255,6 +267,16 @@ NzVector3& NzVector3::Set(T X, T Y, T Z) return *this; } +template +NzVector3& NzVector3::Set(T X, const NzVector2& vec) +{ + x = X; + y = vec.x; + z = vec.y; + + return *this; +} + template NzVector3& NzVector3::Set(T scale) { @@ -302,6 +324,16 @@ NzVector3& NzVector3::Set(const NzVector3& vec) return *this; } +template +NzVector3& NzVector3::Set(const NzVector4& vec) +{ + x = vec.x; + y = vec.y; + z = vec.z; + + return *this; +} + template T NzVector3::SquaredDistance(const NzVector3& vec) const { diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 5b71081d8..7bad9b918 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -8,16 +8,23 @@ #define NAZARA_VECTOR4_HPP #include -#include -template class NzVector4 +template class NzVector2; +template class NzVector3; + +template +class NzVector4 { public: NzVector4() = default; NzVector4(T X, T Y, T Z, T W = 1.0); + NzVector4(T X, T Y, const NzVector2& vec); + NzVector4(T X, const NzVector2& vec, T W); + NzVector4(T X, const NzVector3& vec); explicit NzVector4(T scale); NzVector4(const T vec[4]); - NzVector4(const NzVector3& vec, T W = 1.0); + NzVector4(const NzVector2& vec, T Z = 0.0, T W = 1.0); + NzVector4(const NzVector3& vec, T W = 0.0); template explicit NzVector4(const NzVector4& vec); NzVector4(const NzVector4& vec) = default; ~NzVector4() = default; @@ -39,8 +46,12 @@ template class NzVector4 NzVector4& Normalize(T* length = nullptr); NzVector4& Set(T X, T Y, T Z, T W = 1.0); + NzVector4& Set(T X, T Y, const NzVector2& vec); + NzVector4& Set(T X, const NzVector2& vec, T W); + NzVector4& Set(T X, const NzVector3& vec); NzVector4& Set(T scale); NzVector4& Set(const T vec[4]); + NzVector4& Set(const NzVector2& vec, T Z = 0.0, T W = 1.0); NzVector4& Set(const NzVector3& vec, T W = 1.0); NzVector4& Set(const NzVector4& vec); template NzVector4& Set(const NzVector4& vec); diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 2f6002fbc..c1d7f4d1c 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -18,6 +18,24 @@ NzVector4::NzVector4(T X, T Y, T Z, T W) Set(X, Y, Z, W); } +template +NzVector4::NzVector4(T X, T Y, const NzVector2& vec) +{ + Set(X, Y, vec); +} + +template +NzVector4::NzVector4(T X, const NzVector2& vec, T W) +{ + Set(X, vec, W); +} + +template +NzVector4::NzVector4(T X, const NzVector3& vec) +{ + Set(X, vec); +} + template NzVector4::NzVector4(T scale) { @@ -30,6 +48,12 @@ NzVector4::NzVector4(const T vec[4]) Set(vec); } +template +NzVector4::NzVector4(const NzVector2& vec, T Z, T W) +{ + Set(vec, Z, W); +} + template NzVector4::NzVector4(const NzVector3& vec, T W) { @@ -155,10 +179,43 @@ NzVector4& NzVector4::Normalize(T* length) template NzVector4& NzVector4::Set(T X, T Y, T Z, T W) { - w = W; x = X; y = Y; z = Z; + w = W; + + return *this; +} + +template +NzVector4& NzVector4::Set(T X, T Y, const NzVector2& vec) +{ + x = X; + y = Y; + z = vec.x; + w = vec.y; + + return *this; +} + +template +NzVector4& NzVector4::Set(T X, const NzVector2& vec, T W) +{ + x = X; + y = vec.x; + z = vec.y; + w = W; + + return *this; +} + +template +NzVector4& NzVector4::Set(T X, const NzVector3& vec) +{ + x = X; + y = vec.x; + z = vec.y; + w = vec.z; return *this; } @@ -166,10 +223,10 @@ NzVector4& NzVector4::Set(T X, T Y, T Z, T W) template NzVector4& NzVector4::Set(T scale) { - w = scale; x = scale; y = scale; z = scale; + w = scale; return *this; } @@ -182,6 +239,17 @@ NzVector4& NzVector4::Set(const T vec[4]) return *this; } +template +NzVector4& NzVector4::Set(const NzVector2& vec, T Z, T W) +{ + x = vec.x; + y = vec.y; + z = Z; + w = W; + + return *this; +} + template NzVector4& NzVector4::Set(const NzVector3& vec, T W) { @@ -205,10 +273,10 @@ template template NzVector4& NzVector4::Set(const NzVector4& vec) { - w = F(vec.w); x = F(vec.x); y = F(vec.y); z = F(vec.z); + w = F(vec.w); return *this; }