In my opinion you have several issues with your code, try something like this :
private static void BoneDraw(Model model)
{
const float width = 1f;
var bones = model.Bones;
// define new array
var bonesHasBeenDrawn =... // !!!
// first pass: draw parent->child bones !
foreach(var bone in bones)
{
var parent = bone.Parent;
if(parent != null && boneHasBeenDrawn[parent.Number]!=true ) // !!!
{
var boneMatrix = model.FinalBoneMatrices[bone.Number];
var parentMatrix = model.FinalBoneMatrices[parent.Number];
//handle the parent bone, not the bone ! therfor swap parent and bone here
var length = Vector3.Distance(parentMatrix.TranslationVector, boneMatrix.TranslationVector);
var dir = Vector3.Normalize(boneMatrix.TranslationVector-parentMatrix.TranslationVector); // !!!
var center = parentMatrix.TranslationVector + dir * length / 2; // !!!
var box = new Box(center, length, width, width);
// use the parent here !
var temp = Matrix3X3.CreateFromMatrix(parentMatrix); //!!!
box.OrientationMatrix = temp;
DeferredRenderer.ModelDrawer.Add(box);
boneBoxDictionary[bone.Number] = box;
// done
boneHasBeenDrawn[parent.Number] = true;
}
}
// second pass: draw bones without child and therefor without known length
foreach(var bone in bones)
{
if(boneHasBeenDrawn[bone.Number]!=true )
{
var boneMatrix = model.FinalBoneMatrices[bone.Number];
//virtual length
var length = 1.0; // default length for unknown bones
// point along z-axis, or whatever your lookat axis is
var center = boneMatrix.TranslationVector + boneMatrix.LookAtVector * length *0.5 ;
var box = new Box(center, length, width, width);
// use the parent her !
var temp = Matrix3X3.CreateFromMatrix(boneMatrix);
box.OrientationMatrix = temp;
DeferredRenderer.ModelDrawer.Add(box);
boneBoxDictionary[bone.Number] = box;
// done
boneHasBeenDrawn[bone.Number] = true;
}
}
}
First of, if you take the parent bone as direction, then you are actually drawing the parent bone and you need to orient it relative to it and not to the current bone. The second issue is, that you dont handle leaf-bone with it, therefor you need to draw the leaf-bones with an virtual length (the length is unknown).