From 59b0311f4844a38ce15326c62aeae5c0e9c2834b Mon Sep 17 00:00:00 2001 From: Thompson Lee Date: Thu, 4 Aug 2016 07:05:25 -0400 Subject: [PATCH] Minor Fixes series - Added a missing @param[in]. - Added @mtheall 's Mtx_Multiply() enhancement. --- include/c3d/maths.h | 7 ++++--- source/maths/mtx_multiply.c | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/c3d/maths.h b/include/c3d/maths.h index b3aade8..a935587 100644 --- a/include/c3d/maths.h +++ b/include/c3d/maths.h @@ -346,9 +346,10 @@ static inline C3D_FVec Mtx_MultiplyFVecH(const C3D_Mtx* mtx, C3D_FVec v) /** * @brief 3D translation * @param[in,out] mtx Matrix to translate - * @param[in] x X component to translate - * @param[in] y Y component to translate - * @param[in] z Z component to translate + * @param[in] x X component to translate + * @param[in] y Y component to translate + * @param[in] z Z component to translate + * @param[in] bRightSide Whether to transform from the right side */ void Mtx_Translate(C3D_Mtx* mtx, float x, float y, float z, bool bRightSide); diff --git a/source/maths/mtx_multiply.c b/source/maths/mtx_multiply.c index c7e6377..f7d5b54 100644 --- a/source/maths/mtx_multiply.c +++ b/source/maths/mtx_multiply.c @@ -2,6 +2,15 @@ void Mtx_Multiply(C3D_Mtx* out, const C3D_Mtx* a, const C3D_Mtx* b) { + // if out is a or b, then we need to avoid overwriting them + if(out == a || out == b) + { + C3D_Mtx tmp; + Mtx_Multiply(&tmp, a, b); + Mtx_Copy(out, &tmp); + return; + } + // http://www.wolframalpha.com/input/?i={{a,b,c,d},{e,f,g,h},{i,j,k,l},{m,n,o,p}}{{α,β,γ,δ},{ε,θ,ι,κ},{λ,μ,ν,ξ},{ο,π,ρ,σ}} int i, j; for (j = 0; j < 4; ++j)