Bone Transformation

I'm using Blender to export my armatures in relative coordinates, and I'm trying to get to absolute coordinates in my engine. For the above example, the childBone's tip is an offset of [-1,0,0], which is relative to the forward direction of the rootBone, not the global X axis. I understand how matrix multiplication works, but I can't quite seem to get there. Could someone break down the exact steps needed to calculate the absolute coordinates? Here's my attempt:

Vector3f rootRoot = new Vector3f(1,1,0);
Vector3f rootTip = new Vector3f(2,1,0);
Vector3f rootTipOffset = Vector3f.sub(rootTip, rootRoot);
float rootLength = rootTipOffset.length();
Quaternion rootRotation = new Quaternion(new Matrix4f().initRotation(rootTipOffset, Vector3f.Y_AXIS));
Matrix4f rootBindPose = new Matrix4f().initTranslation(rootRoot).mult(rootRotation.toRotationMatrix());
//Matrix for the root of the root bone

Matrix4f childOffset = new Matrix4f().initTranslation(rootTipOffset).mult(rootBindPose);

Vector3f childRoot = new Vector3f(0,0,0); //2,1,0
Vector3f childTip = new Vector3f(-1,0,0); //2,2,0
Vector3f childTipOffset = Vector3f.sub(childTip, childRoot);
float childLength = childTipOffset.length();
Quaternion childRotation = new Quaternion(new Matrix4f().initRotation(childTipOffset, childOffset.getRotation().getUp()));
Matrix4f childBindPose = childOffset.mult(new Matrix4f().initTranslation(childRoot).mult(childRotation.toRotationMatrix()));
Matrix4f testMatrix = new Matrix4f().initTranslation(new Vector3f(0,0,childLength)).mult(childOffset);
System.out.println(testMatrix.getTranslation()); //Prints [2, 1, 1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.