# How to determine local x and z axis of bones

I'm interested in the local coordinate system of the bone in order to interpret animation data from blender correctly in my game.

For simplicity I'm assuming 0 roll.

Getting the y axis seems straight forward, it's always in the direction from the head of the bone to the tail of the bone.

But how do I determine the local X and Z axis?

When the bones are in the XY plane Z is always up, so I figured it's probably something like, cross product local_y global_z to get the x axis and then cross product local_x local_y to get the local z axis.

But this doesn't seem to hold up for bones in the zx plane.

It kind of looks like they are blending between orientations at the 6 axis directions.

But not sure how that blend would work.

What is being blended? Quaternion? 3x3Matrix?

How is it being blended? Lerp? Slerp?

Or is it something completely different?

If anyone can shine some light on this, or point me towards the relevant documentation I would really appreciate it <3

I figured it out, so in case someone has the same question and finds this, I'll answer my own question:

This is the blender source file in question: https://github.com/blender/blender/blob/master/source/blender/blenkernel/intern/armature.c

The relevant function is called vec_roll_to_mat3_normalized In a comment it mentions: "P.S. In the end, this basically is a heavily optimized version of Damped Track +Y."

Here is the documentation for Damped Track Constrains: https://docs.blender.org/manual/en/latest/animation/constraints/tracking/damped_track.html

It states that it's using a swing rotation: https://docs.blender.org/manual/en/latest/glossary/index.html#term-Swing

Here is an in depth blog post on Swing-Twist Interpolation: http://allenchou.net/2018/05/game-math-swing-twist-interpolation-sterp/

• nice finding!! + 1 Nov 4, 2022 at 13:21