Math/Vector3: Add Project method

This commit is contained in:
SirLynix 2024-02-22 17:06:58 +01:00
parent 61764dfc3d
commit 5180f24988
2 changed files with 10 additions and 0 deletions

View File

@ -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;

View File

@ -8,6 +8,7 @@
#include <cstring>
#include <limits>
#include <stdexcept>
#include "Vector3.hpp"
namespace Nz
{
@ -282,6 +283,13 @@ namespace Nz
return *this;
}
template<typename T>
constexpr Vector3<T> Vector3<T>::Project(const Vector3& normal) const
{
float dot = DotProduct(normal);
return normal * dot;
}
/*!
* \brief Normalizes the current vector
* \return A reference to this vector