From 4f72c9aee824cd576a666c73e8cb764407c824a5 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:44:27 +0200 Subject: [PATCH] Recast: implement new math functions Implement functions for deriving vector magnitude and scalar projections. --- .../recast/Shared/Include/SharedCommon.h | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/thirdparty/recast/Shared/Include/SharedCommon.h b/src/thirdparty/recast/Shared/Include/SharedCommon.h index f483d335..548754c5 100644 --- a/src/thirdparty/recast/Shared/Include/SharedCommon.h +++ b/src/thirdparty/recast/Shared/Include/SharedCommon.h @@ -319,6 +319,40 @@ inline void rdVnormalize2D(float* v) v[1] *= d; } +/// Derives the magnitude of the vector. +/// @param[in] v A vector. [(x, y, z)] +/// @return The magnitude of the vector. +inline float rdVmag(const float* v) +{ + return rdMathSqrtf(rdVdot(v, v)); +} + +/// Derives the magnitude of the vector on the xy-plane. +/// @param[in] v A vector. [(x, y, z)] +/// @return The magnitude of the vector on the xy-plane. +inline float rdVmag2D(const float* v) +{ + return rdMathSqrtf(rdVdot2D(v, v)); +} + +/// Derives the scalar projection of the specified point into the vector. +/// @param[in] p A point. [(x, y, z)] +/// @param[in] v A vector. [(x, y, z)] +/// @return The scalar projection of the specified point into the vector. +inline float rdVproj(const float* p, const float* v) +{ + return rdVdot(p, v) / rdVmag(v); +} + +/// Derives the scalar projection of the specified point into the vector on the xy-plane. +/// @param[in] p A point. [(x, y, z)] +/// @param[in] v A vector. [(x, y, z)] +/// @return The scalar projection of the specified point into the vector on the xy-plane. +inline float rdVproj2D(const float* p, const float* v) +{ + return rdVdot2D(p, v) / rdVmag2D(v); +} + /// Performs a 'sloppy' collocation check of the specified points. /// @param[in] p0 A point. [(x, y, z)] /// @param[in] p1 A point. [(x, y, z)]