Hi I'm using C#
and MonoGame
, and have the world matrices of 2 objects. I need to get the difference between them, so I can effectively parent the second object onto the first. The aim is to get to a point where any changes to the parent transform can be applied to the child object too, by doing child.Transform = parent.Transform * offset
.
I'm using the following code:
// ...
Matrix m1 = info.BoneTargets[i].Transform;
Matrix m2 = rigidbodyDefaultWorlds[transform.RigidBodyIndex];
Matrix transformFromTargetToRigidBody = Matrix.Invert(m1) * m2;
Debug.Assert((m1 * transformFromTargetToRigidBody).Equals(m2)); // FAIL
// ...
The Assert fails though, so I assume my math is wrong. I did try all other variations of the invert(a) * b formula though and none of them worked either.
For completion here are the matrix values:
M1 {M11:1 M12: 2.384186E-07 M13:-6.211763E-22 M14:0} {M21:0 M22:0 M23:1 M24:0} {M31:2.384186E-07 M32:-1 M33:0 M34:0} {M41:0.0005292654 M42:-0.03780181 M43:0.752234 M44:1}
M2 {M11:1 M12:-2.384186E-07 M13:0 M14:0} {M21:-3.884332E-14 M22:-1.629207E-07 M23:1 M24:0} {M31:-2.384186E-07 M32:-1 M33:-1.629207E-07 M34:0} {M41:0.01058531 M42:0.7560362 M43:-17.54894 M44:1}
TR {M11:1 M12:-4.768372E-07 M13:-3.884332E-14 M14:0} {M21:4.768372E-07 M22:1 M23:1.629207E-07 M24:0} {M31:-3.884332E-14 M32:-1.629207E-07 M33:1 M34:0} {M41:0.01005606 M42:0.7938381 M43:-18.30118 M44:1}
OUT {M11:1 M12:-2.384186E-07 M13:-6.211763E-22 M14:0} {M21:-3.884332E-14 M22:-1.629207E-07 M23:1 M24:0} {M31:-2.384186E-07 M32:-1 M33:-1.629207E-07 M34:0} {M41:0.01058531 M42:0.7560362 M43:-17.54894 M44:1}
EDIT: Actually, now I'm thinking the formula is this...
child.World = childTransformWithOffsetTranslation * parentWorld