diff --git a/include/Nazara/Math/Plane.hpp b/include/Nazara/Math/Plane.hpp index 2b95141ee..965b840af 100644 --- a/include/Nazara/Math/Plane.hpp +++ b/include/Nazara/Math/Plane.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014 Jérôme Leclercq +// Copyright (C) 2014 Jérôme Leclercq // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -27,6 +27,9 @@ class NzPlane T Distance(const NzVector3& point) const; T Distance(T x, T y, T z) const; + NzVector3 GetNormal() const; + T GetDistance() const; + NzPlane& Set(T normalX, T normalY, T normalZ, T Distance); NzPlane& Set(const T plane[4]); NzPlane& Set(const NzPlane& plane); @@ -38,6 +41,9 @@ class NzPlane NzString ToString() const; static NzPlane Lerp(const NzPlane& from, const NzPlane& to, T interpolation); + static NzPlane XY(); + static NzPlane XZ(); + static NzPlane YZ(); NzVector3 normal; T distance; diff --git a/include/Nazara/Math/Plane.inl b/include/Nazara/Math/Plane.inl index 640e9ea2f..186953134 100644 --- a/include/Nazara/Math/Plane.inl +++ b/include/Nazara/Math/Plane.inl @@ -58,6 +58,18 @@ T NzPlane::Distance(T x, T y, T z) const return Distance(NzVector3(x, y, z)); } +template +NzVector3 NzPlane::GetNormal() const +{ + return normal; +} + +template +T NzPlane::GetDistance() const +{ + return distance; +} + template NzPlane& NzPlane::Set(T normalX, T normalY, T normalZ, T D) { @@ -152,6 +164,24 @@ NzPlane NzPlane::Lerp(const NzPlane& from, const NzPlane& to, T interpolat return plane; } +template +NzPlane NzPlane::XY() +{ + return NzPlane(F(0.0), F(0.0), F(1.0), F(0.0)); +} + +template +NzPlane NzPlane::XZ() +{ + return NzPlane(F(0.0), F(1.0), F(0.0), F(0.0)); +} + +template +NzPlane NzPlane::YZ() +{ + return NzPlane(F(1.0), F(0.0), F(0.0), F(0.0)); +} + template std::ostream& operator<<(std::ostream& out, const NzPlane& plane) { diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index 64378a949..989bb6962 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -39,6 +39,7 @@ class NzSphere NzVector3 GetNegativeVertex(const NzVector3& normal) const; NzVector3 GetPosition() const; NzVector3 GetPositiveVertex(const NzVector3& normal) const; + T GetRadius() const; bool Intersect(const NzBox& box) const; bool Intersect(const NzSphere& sphere) const; diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 9c56fac16..1f469f6d7 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -117,6 +117,13 @@ NzVector3 NzSphere::GetPositiveVertex(const NzVector3& normal) const return pos; } + +template +T NzSphere::GetRadius() const +{ + return radius; +} + template bool NzSphere::Intersect(const NzBox& box) const { diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index e0c060e21..186860066 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -23,6 +23,8 @@ class NzVector2 T AbsDotProduct(const NzVector2& vec) const; + T AngleBetween(const NzVector2& vec, bool toDegree = true) 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 5da704243..a5e5f4712 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -54,6 +54,15 @@ inline unsigned int NzVector2::AbsDotProduct(const NzVector2 +T NzVector2::AngleBetween(const NzVector2& vec, bool toDegree) 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); +} + template T NzVector2::Distance(const NzVector2& vec) const { diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index fe2e33881..b8a980ae5 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -24,6 +24,8 @@ template class NzVector3 T AbsDotProduct(const NzVector3& vec) const; + T AngleBetween(const NzVector3& vec, bool toDegree = true) const; + NzVector3 CrossProduct(const NzVector3& vec) const; T Distance(const NzVector3& vec) const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index a90410a0d..f2940e279 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -60,6 +60,30 @@ inline unsigned int NzVector3::AbsDotProduct(const NzVector3 +T NzVector3::AngleBetween(const NzVector3& vec, bool toDegree) const +{ + T alpha = DotProduct(vec); + T divisor = (GetLength() * vec.GetLength()); + + #if NAZARA_MATH_SAFE + if (NzNumberEquals(divisor, F(0.0))) + { + NzString error("Division by zero"); + + NazaraError(error); + throw std::domain_error(error); + } + #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))); +} + template NzVector3 NzVector3::CrossProduct(const NzVector3& vec) const {