effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateFromYawPitchRoll( tmpMH.Rotation.Y, tmpMH.Rotation.X, tmpMH.Rotation.Z) * Matrix.CreateScale(tmpMH.Scale) * Matrix.CreateTranslation(tmpMH.Position);
I am not a profiler, but I feel that this line is a pain. Creating and multiplying a matrix is ββquite expensive! I understand that this code is necessary, so if you cannot pre-calculate these matrices, I would try:
Matrix pitch, scale, translation, temp1, temp2; Matrix.CreateFromYawPitchRoll( tmpMH.Rotation.Y, tmpMH.Rotation.X, tmpMH.Rotation.Z, out pitch); Matrix.CreateScale(ref tmpMH.Scale, out scale); Matrix.CreateTranslation(ref tmpMH.Position, out translation); Matrix.Multiply(ref transforms[mesh.ParentBone.Index], ref pitch, out temp1); Matrix.Multiply(ref temp1, ref scale, out temp2); Matrix.Multiply(ref temp2, ref translation, out effect.World);
This can be faster, since there is no need to copy each matrix onto the stack to transfer parameters ( 20 times less files to copy !)
source share