# Is my skeletal animation algorith/representation correct?

I'm representing a rig (skeleton) as:

1. A root pivot point, with a position (Vector3) and a direction (Vector 3).

2. A tree of bones, where each bone is a struct with a rotation (Quaternion) and a length (Float).

I'm projecting the positions of the joints by:

1. Start with the root pivot point and the root bone, rotate it by bone.rotation and project it by bone.length across its new direction. The new pivot is a pair of position, direction.

2. Repeat for each child bone.

Is that correct?

• Remember that SE is not for discussion. It's unlikely that you're looking for a simple yes/no answer. It would probably be best if you included details about why you think it's not working. Present all of your evidence and entire problem up front, don't wait to be asked for details or engage in discussion. – MichaelHouse Jan 13 '15 at 0:37

This will work if all you're concerned about is the translation part of each bone, but it is more common to represent your bone structure as a transformation matrix tree, which is probably the most popular way to do Forward Kinematics.

Define a Node as follows:

class Node
{
Transform localTransform;
Node parent;
List<Node> children;

// Computes the global transform of the node with respect to the world.
Transform ComputeGlobalTransform()
{
if (parent == null) return localTransform;
else return parent.ComputeGlobalTransform() * localTransform;
}
}


A Link is a Node that has mesh geometry. A Joint is a node that connects two links, and rotates around its Z axis.

class Link : Node
{
Mesh geometry;
}

class Joint : Node
{
void SetJointAngle(float value)
{
// The local transform is a rotation around the Z axis by convention.
// Make sure to preserve the translation part of the transform.
localTransform.SetRotationPart(Matrix.CreateRotationZ(value));
}
}


You can make more complicated joints such as prismatic and ball-in-socket joints fairly easily this way. Representing your links and joints as transforms rather than just a direction and a length also disambiguates the rotation part of your skeletal animation system. It also allows you to offset links in an arbitrary way.