From 6a77eb1dcfdfa9ba7a66b64e4ead590c503e536c Mon Sep 17 00:00:00 2001 From: Thompson Lee Date: Fri, 5 Aug 2016 01:02:54 -0400 Subject: [PATCH] Added @mtheall 's Mtx_Multiply() enhancement. --- source/maths/mtx_multiply.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/maths/mtx_multiply.c b/source/maths/mtx_multiply.c index 5182efa..f7d5b54 100644 --- a/source/maths/mtx_multiply.c +++ b/source/maths/mtx_multiply.c @@ -1,7 +1,16 @@ #include -void Mtx_Multiply(C3D_Mtx* __restrict out, const C3D_Mtx* a, const C3D_Mtx* b) +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)