Last active
January 4, 2016 05:09
-
-
Save tsterker/8573260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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