From 5180f249886778108cddd00c1aba31d673816a0b Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 22 Feb 2024 17:06:58 +0100 Subject: [PATCH] Math/Vector3: Add Project method --- include/Nazara/Math/Vector3.hpp | 2 ++ include/Nazara/Math/Vector3.inl | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 327ac12d0..380c3b298 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -52,6 +52,8 @@ namespace Nz constexpr Vector3& Maximize(const Vector3& vec); constexpr Vector3& Minimize(const Vector3& vec); + constexpr Vector3 Project(const Vector3& normal) const; + Vector3& Normalize(T* length = nullptr); constexpr T SquaredDistance(const Vector3& vec) const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 1dacbf295..dd7d9b42b 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -8,6 +8,7 @@ #include #include #include +#include "Vector3.hpp" namespace Nz { @@ -282,6 +283,13 @@ namespace Nz return *this; } + template + constexpr Vector3 Vector3::Project(const Vector3& normal) const + { + float dot = DotProduct(normal); + return normal * dot; + } + /*! * \brief Normalizes the current vector * \return A reference to this vector