Skip to content

Instantly share code, notes, and snippets.

@tsterker
Last active January 4, 2016 05:09
Show Gist options
  • Save tsterker/8573260 to your computer and use it in GitHub Desktop.
Save tsterker/8573260 to your computer and use it in GitHub Desktop.
// using first frame for testing
Skeleton* frame0 = rest_animation->GetFrame(0);
// for each joint in skeleton...
for (int i = 0; i < frame0->NumJoints(); i++) {
// current joint
Joint jnt = frame0->GetJoint(i);
// "global" transformation that should be applied to current joint
Matrix_4x4 totalTransform = Matrix_4x4::Id();
// start at parent, transformation for current joint will be applied after loop
int currentId = jnt.parent_id;
while(currentId >= 0){
// current parent joint
Joint parentJnt = frame0->GetJoint(currentId);
// function returns TransformationMatrix of current parent joint: rotation * position
Matrix_4x4 trans = parentJnt.GetTransform();
// accumulate transformations
totalTransform = trans * totalTransform;
// get next parent
currentId = parentJnt.parent_id;
}
// finally apply totalTransform to current joint
Vector3 newPos = totalTransform * jnt.rotation * jnt.position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment