[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:
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:
This is quite the old bug. But that's what happens when you implement a feature that isn't used anywhere ;)
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 ;)
About the author
Associate Tom Spilman
Sickhead Games
Thanks for the fix... its checked into the repo.