Problem with bones


12-07-2012 15:13:58

Hi all,
in my project I have to draw a skeleton, and then I have to put some balls in the same position of the right ankle of skeleton.
I don't draw a skeleton (i have used skeletonentity.Visible = False).
The sequence of what I do is:
- i rotate manually the bones
- i do a procedure in order to make the skeleton attached to the ground
- i search the global position of the wrist ankle bone
- i draw the ball in the same coordinate

I make the skeleton to keep attached to the ground in this way:

Dim yMin As Single = 9999
Dim yTemp As Single
Dim v As Mogre.Vector3
For Each osso As Mogre.Bone In s.GetBoneIterator
If IsNothing(osso.Parent) Then
yTemp = osso.Position.y
v = o.fcn_getPosizioneBone(skeletonentity, osso)
yTemp = v.y
End If
If yTemp < yMin Then yMin = yTemp
s.GetBone("Root").Position = New Mogre.Vector3(s.GetBone("Root").InitialPosition.x, _
s.GetBone("Root").Position.y - yMin, s.GetBone("Root").InitialPosition.z)

I search the bone global position in this way:

Public Function fcn_getPosizioneBone(ent As Mogre.Entity, bone As Mogre.Bone) As Mogre.Vector3
Dim world_position As Mogre.Vector3 = bone._getDerivedPosition()
Dim pParentNode As Mogre.Node = ent.ParentNode
Dim pSceneNode As Mogre.SceneNode = ent.ParentSceneNode

While Not IsNothing(pParentNode)
If Not (pParentNode.Equals(pSceneNode)) Then
world_position = DirectCast(pParentNode, Mogre.TagPoint)._getFullLocalTransform() * world_position
pParentNode = DirectCast(pParentNode, Mogre.TagPoint).ParentEntity.ParentNode
world_position = pParentNode._getFullTransform() * world_position
Exit While
End If
End While
Return world_position
End Function

And i update the skeleton position and orientation with a skeleton._updateTransforms()...
The problem is that everything works only if my root bone doesn't move... if I move it, the first ball is positioned in wrong position, and the second one in right position.
You can see in the video the example with still root bone (the 3D model you see is another instance, visible, of the skeleton):

In this one you can instead see that if I move the root something goes wrong. The root bone is the pelvis.

Please help me!! What am I wrong???