private static MatrixF GetDefaultBoneTransform(Bone b) { var m = MatrixF.Identity; while (b != null) { m *= QuaternionF.EulerAngles(b.DefaultAngles).GetMatrix().Translate(b.DefaultPosition); b = b.Parent; } return(m); }
public Bone(int boneIndex, int parentIndex, Bone parent, string name, CoordinateF defaultPosition, CoordinateF defaultAngles, CoordinateF defaultPositionScale, CoordinateF defaultAnglesScale) { BoneIndex = boneIndex; ParentIndex = parentIndex; Parent = parent; Name = name; DefaultPosition = defaultPosition; DefaultAngles = defaultAngles; DefaultPositionScale = defaultPositionScale; DefaultAnglesScale = defaultAnglesScale; Transform = QuaternionF.EulerAngles(DefaultAngles).GetMatrix().Translate(defaultPosition); if (parent != null) { Transform *= parent.Transform; } }
public MatrixF GetAnimationTransform(Bone b, bool transformBones, bool applyDefaults) { var m = transformBones ? MatrixF.Identity : GetDefaultBoneTransform(b).Inverse(); while (b != null) { var ang = Bones[b.BoneIndex].Angles; var pos = Bones[b.BoneIndex].Position; if (applyDefaults) { ang *= QuaternionF.EulerAngles(b.DefaultAngles); pos += b.DefaultPosition; } m *= ang.GetMatrix().Translate(pos); //var test = Bones[b.BoneIndex].Angles * QuaternionF.EulerAngles(b.DefaultAngles); //m *= test.GetMatrix().Translate(Bones[b.BoneIndex].Position + b.DefaultPosition); //m *= Bones[b.BoneIndex].Angles.GetMatrix().Translate(Bones[b.BoneIndex].Position); b = b.Parent; } return(m); }