diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index fb76ee95f..874768f43 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -62,7 +62,7 @@ template T NzSphere::Distance(T X, T Y, T Z) const { NzVector3 distance(X-x, Y-y, Z-z); - return distance.Length() - radius; + return distance.GetLength() - radius; } template diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index c2de14db4..01100e450 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -28,10 +28,10 @@ class NzVector2 T DotProduct(const NzVector2& vec) const; - NzVector2 GetNormal() const; - - T Length() const; - float Lengthf() const; + T GetLength() const; + float GetLengthf() const; + NzVector2 GetNormal(T* length = nullptr) const; + T GetSquaredLength() const; NzVector2& MakeUnitX(); NzVector2& MakeUnitY(); @@ -49,7 +49,6 @@ class NzVector2 template NzVector2& Set(const NzVector2& vec); T SquaredDistance(const NzVector2& vec) const; - T SquaredLength() const; NzString ToString() const; diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 5b09a1f13..f92e74bca 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -73,24 +73,30 @@ T NzVector2::DotProduct(const NzVector2& vec) const } template -NzVector2 NzVector2::GetNormal() const +T NzVector2::GetLength() const +{ + return std::sqrt(GetSquaredLength()); +} + +template +float NzVector2::GetLengthf() const +{ + return std::sqrt(static_cast(GetSquaredLength())); +} + +template +NzVector2 NzVector2::GetNormal(T* length) const { NzVector2 vec(*this); - vec.Normalize(); + vec.Normalize(length); return vec; } template -T NzVector2::Length() const +T NzVector2::GetSquaredLength() const { - return std::sqrt(SquaredLength()); -} - -template -float NzVector2::Lengthf() const -{ - return std::sqrt(static_cast(SquaredLength())); + return x*x + y*y; } template @@ -138,7 +144,7 @@ NzVector2& NzVector2::Minimize(const NzVector2& vec) template NzVector2& NzVector2::Normalize(T* length) { - T norm = std::sqrt(SquaredLength()); + T norm = std::sqrt(GetSquaredLength()); T invNorm = F(1.0) / length; x *= invNorm; @@ -197,13 +203,7 @@ NzVector2& NzVector2::Set(const NzVector2& vec) template T NzVector2::SquaredDistance(const NzVector2& vec) const { - return operator-(vec).SquaredLength(); -} - -template -T NzVector2::SquaredLength() const -{ - return x*x + y*y; + return operator-(vec).GetSquaredLength(); } template diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index d49bc5f44..ea323611b 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -31,10 +31,10 @@ template class NzVector3 T DotProduct(const NzVector3& vec) const; - NzVector3 GetNormal() const; - - T Length() const; - float Lengthf() const; + T GetLength() const; + float GetLengthf() const; + NzVector3 GetNormal(T* length = nullptr) const; + T GetSquaredLength() const; NzVector3& MakeForward(); NzVector3& MakeLeft(); @@ -57,7 +57,6 @@ template class NzVector3 template NzVector3& Set(const NzVector3& vec); T SquaredDistance(const NzVector3& vec) const; - T SquaredLength() const; NzString ToString() const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 10a532195..207f5d7ef 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -85,24 +85,30 @@ T NzVector3::DotProduct(const NzVector3& vec) const } template -NzVector3 NzVector3::GetNormal() const +T NzVector3::GetLength() const +{ + return std::sqrt(GetSquaredLength()); +} + +template +float NzVector3::GetLengthf() const +{ + return std::sqrt(static_cast(GetSquaredLength())); +} + +template +NzVector3 NzVector3::GetNormal(T* length) const { NzVector3 vec(*this); - vec.Normalize(); + vec.Normalize(length); return vec; } template -T NzVector3::Length() const +T NzVector3::GetSquaredLength() const { - return std::sqrt(SquaredLength()); -} - -template -float NzVector3::Lengthf() const -{ - return std::sqrt(static_cast(SquaredLength())); + return x*x + y*y + z*z; } template @@ -180,7 +186,7 @@ NzVector3& NzVector3::Minimize(const NzVector3& vec) template NzVector3& NzVector3::Normalize(T* length) { - T norm = Length(); + T norm = GetLength(); T invNorm = F(1.0) / norm; x *= invNorm; @@ -253,13 +259,7 @@ NzVector3& NzVector3::Set(const NzVector3& vec) template T NzVector3::SquaredDistance(const NzVector3& vec) const { - return operator-(vec).SquaredLength(); -} - -template -T NzVector3::SquaredLength() const -{ - return x*x + y*y + z*z; + return operator-(vec).GetSquaredLength(); } template diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index b5ce734b5..e8e40ce0d 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -26,6 +26,8 @@ template class NzVector4 T DotProduct(const NzVector4& vec) const; + NzVector4 GetNormal(T* length = nullptr) const; + NzVector4& MakeUnitX(); NzVector4& MakeUnitY(); NzVector4& MakeUnitZ(); diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 6d95accfc..9e3ab6954 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -67,6 +67,15 @@ T NzVector4::DotProduct(const NzVector4& vec) const return x*vec.x + y*vec.y + z*vec.z + w*vec.w; } +template +NzVector4 NzVector4::GetNormal(T* length) const +{ + NzVector4 vec(*this); + vec.Normalize(length); + + return vec; +} + template NzVector4& NzVector4::MakeUnitX() {