FSO.Vitaboy.Skeleton.ComputeBonePositions C# (CSharp) Method

ComputeBonePositions() public method

Computes the absolute position for all the bones in this skeleton.
public ComputeBonePositions ( Bone bone, Matrix world ) : void
bone Bone The bone to start with, should always be the ROOT bone.
world Matrix A world matrix to use in the calculation.
return void
        public void ComputeBonePositions(Bone bone, Matrix world)
        {
            var translateMatrix = Matrix.CreateTranslation(bone.Translation);
            var rotationMatrix = Matrix.CreateFromQuaternion(bone.Rotation);

            var myWorld = (rotationMatrix * translateMatrix)*world;
            bone.AbsolutePosition = Vector3.Transform(Vector3.Zero, myWorld);
            bone.AbsoluteMatrix = myWorld;

            foreach (var child in bone.Children)
            {
                ComputeBonePositions(child, myWorld);
            }
        }

Usage Example

Ejemplo n.º 1
0
 /// <summary>
 /// When the skeleton changes (for example due to an animation) this
 /// method will recompute the meshes to adhere to the new skeleton positions.
 /// </summary>
 public void ReloadSkeleton()
 {
     Skeleton.ComputeBonePositions(Skeleton.RootBone, Matrix.Identity);
     SkelBones = new Matrix[Skeleton.Bones.Length];
     for (int i = 0; i < Skeleton.Bones.Length; i++)
     {
         SkelBones[i] = Skeleton.Bones[i].AbsoluteMatrix;
     }
 }
All Usage Examples Of FSO.Vitaboy.Skeleton::ComputeBonePositions