Skip to content

Commit

Permalink
Fix issues with kmVec3ProjectOnToVec3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazade committed Aug 13, 2016
1 parent 3bddc3d commit 86d9ce7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions kazmath/vec3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 86d9ce7

Please sign in to comment.