Game Development Community

[BUG] Wrong matrix multiplication order in TSShapeInstance::addPath() [w/ fix] - RESOLVED

by Manoel Neto · in Torque 3D Professional · 05/12/2010 (10:42 am) · 3 replies

In the project I'm working on, we're rolling our own player classes with custom animation code (but still using TSShapeInstance and TSThread). For some more precise movements, we have the animation ground transform actually translate and rotate the player (instead of being used to change animation speed). When using only translation everything works fine, but when the animations have rotations the translations were messed up.

After lots of hair pulling, I found that the bug was in the unlikeliest of the places: TSShapeInstance::addPath(), the core function responsible for ground transform calculation. This is the culprit:

addM.mul(endM,startInvM);
endM.mul(addM,*mat);

This matrix multiplication is actually in the wrong order, but when startInvM is the inverse identity (which it is in all instances where stock T3D uses addPath() for something relevant) it doesn't cause any problems (same if the ground transform only contains translations).

The fix is simple:
addM.mul(startInvM,endM);
endM.mul(*mat,addM);

This is quite the old bug. But that's what happens when you implement a feature that isn't used anywhere ;)

#1
05/17/2010 (6:17 pm)
Wow... yea... totally untested code that probably no one has used on purpose.

Thanks for the fix... its checked into the repo.
#2
06/01/2010 (5:43 am)
logged Key: TQA-181
#3
08/02/2010 (5:25 pm)
Fixed in 1.1 Beta 2