From 86d9ce7bce5254da5bc3a3f7f0e9925abbe704db Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Sat, 13 Aug 2016 15:34:05 +0100 Subject: [PATCH] Fix issues with kmVec3ProjectOnToVec3 --- kazmath/vec3.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kazmath/vec3.c b/kazmath/vec3.c index e238401..b7b2eb8 100755 --- a/kazmath/vec3.c +++ b/kazmath/vec3.c @@ -490,10 +490,14 @@ void kmVec3OrthoNormalize(kmVec3* normal, kmVec3* tangent) { kmVec3Normalize(tangent, tangent); } -kmVec3* kmVec3ProjectOnToVec3(const kmVec3* pIn, const kmVec3* other, kmVec3* projection) { - kmScalar scale = kmVec3Length(pIn) * kmVec3Dot(pIn, other); +kmVec3* kmVec3ProjectOnToVec3(const kmVec3* w, const kmVec3* v, kmVec3* projection) { + kmVec3 unitW, unitV; + kmVec3Normalize(&unitW, w); + kmVec3Normalize(&unitV, v); + + kmScalar cos0 = kmVec3Dot(&unitW, &unitV); + + kmVec3Scale(projection, &unitV, kmVec3Length(w) * cos0); - kmVec3Normalize(projection, other); - kmVec3Scale(projection, projection, scale); return projection; }