From e25fbe30e651ddfce833a9c3b2e4c1c6b197e144 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 22 Feb 2024 19:11:25 +0100 Subject: [PATCH] Math/Vector3: Add ProjectOnPlane --- include/Nazara/Math/Vector3.hpp | 1 + include/Nazara/Math/Vector3.inl | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 380c3b298..c81f1f0af 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -53,6 +53,7 @@ namespace Nz constexpr Vector3& Minimize(const Vector3& vec); constexpr Vector3 Project(const Vector3& normal) const; + constexpr Vector3 ProjectOnPlane(const Vector3& normal) const; Vector3& Normalize(T* length = nullptr); diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index dd7d9b42b..317cc94ef 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -290,6 +290,13 @@ namespace Nz return normal * dot; } + template + constexpr Vector3 Vector3::ProjectOnPlane(const Vector3& normal) const + { + float dot = DotProduct(normal); + return *this - normal * dot; + } + /*! * \brief Normalizes the current vector * \return A reference to this vector