diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 45f2caa5c..357babaa5 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -23,7 +23,7 @@ class NzVector2 T AbsDotProduct(const NzVector2& vec) const; - T AngleBetween(const NzVector2& vec, bool toDegree = true) const; + T AngleBetween(const NzVector2& vec) const; T Distance(const NzVector2& vec) const; float Distancef(const NzVector2& vec) const; diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index b480bffd3..b457f0ad0 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -55,12 +55,9 @@ inline unsigned int NzVector2::AbsDotProduct(const NzVector2 -T NzVector2::AngleBetween(const NzVector2& vec, bool toDegree) const +T NzVector2::AngleBetween(const NzVector2& vec) const { - if (toDegree) - return NzRadianToDegree(std::atan2(vec.y, vec.x) - std::atan2(y, x)); - else - return std::atan2(vec.y, vec.x) - std::atan2(y, x); + return NzRadians(std::atan2(vec.y, vec.x) - std::atan2(y, x)); } template diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 8be7f40b5..875662270 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -24,7 +24,7 @@ template class NzVector3 T AbsDotProduct(const NzVector3& vec) const; - T AngleBetween(const NzVector3& vec, bool toDegree = true) const; + T AngleBetween(const NzVector3& vec) const; NzVector3 CrossProduct(const NzVector3& vec) const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index aa1661bae..2ca0c5051 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -61,10 +61,10 @@ inline unsigned int NzVector3::AbsDotProduct(const NzVector3 -T NzVector3::AngleBetween(const NzVector3& vec, bool toDegree) const +T NzVector3::AngleBetween(const NzVector3& vec) const { - T alpha = DotProduct(vec); - T divisor = (GetLength() * vec.GetLength()); + // sqrt(a) * sqrt(b) = sqrt(a*b) + T divisor = std::sqrt(GetSquaredLength() * vec.GetSquaredLength()); #if NAZARA_MATH_SAFE if (NzNumberEquals(divisor, F(0.0))) @@ -76,12 +76,8 @@ T NzVector3::AngleBetween(const NzVector3& vec, bool toDegree) const } #endif - alpha /= divisor; - - if (toDegree) - return NzRadianToDegree(std::acos(NzClamp(alpha, F(-1.0), F(1.0)))); - else - return std::acos(NzClamp(alpha, F(-1.0), F(1.0))); + T alpha = DotProduct(vec)/divisor; + return NzRadians(std::acos(NzClamp(alpha, F(-1.0), F(1.0)))); } template @@ -478,8 +474,8 @@ template bool NzVector3::operator==(const NzVector3& vec) const { return NzNumberEquals(x, vec.x) && - NzNumberEquals(y, vec.y) && - NzNumberEquals(z, vec.z); + NzNumberEquals(y, vec.y) && + NzNumberEquals(z, vec.z); } template