by JoeJ » Sat Jun 30, 2012 1:21 pm
I'm not sure if Julios suggestion affects physics - i mean the true center of mass of a forearm should stay at the center of it, not at the ellbow position.
Another way worth mentioning anyways is:
// You get the matrix from the body:
matrix mb;
NewtonBodyGetMAtrix (mb, body);
// bodies point 3 units in z, so we need to translate 1.5 units backwards to get to the bone-tip:
mb[3] -= mb[2] * 1.5; // we subtract the local z axis from the translation to achieve that.
Now you can use that matrix for graphics.
You could do the same with matrix math:
matrix pompb = { // "precomputed offset matrix per bone"
1,0,0,0
0,1,0,0
0,0,1,0
0,0,-1.5,1};
gfxBoneMatrix = bodyMatrix * pompb;
// or:
gfxBoneMatrix = pompb * bodyMatrix;
// depending on your math libs conventions (i don't know DirectX)
... this looks complex and first method is faster, but if you also need to fix rotation it will make sense, because you only need to modify pompb-matrix.
You can also put the Scaling-correction you need in that pompb-matrix.
Something that could fix most of your mismatch is:
matrix pompb = {
1,0,0,0
0,1,0,0
0,0,0.333,0 // make z axis less long to fix the scale
0.5, 0, -1.5, 1}; // try the 0.5 value both positive and negative, and also at y instead of x, as i can't see the axis in your screenshot i can only guess.
Again - visualize all Transforms to know what you're doing.