# [Bf-committers] Armatures for beyond Release 2.4

Gilbert, Joseph T. jgilbert at tigr.ORG
Fri Dec 23 19:25:18 CET 2005

```Thx Brecht :) This is useful info and I think we can apply it.
It would be nice to have a mat3_to_vec_roll in there somewhere that way
I wouldn't have to figure it out :)

-----Original Message-----
From: bf-committers-bounces at projects.blender.org
[mailto:bf-committers-bounces at projects.blender.org] On Behalf Of Brecht
Van Lommel
Sent: Friday, December 23, 2005 12:00 PM
To: thomas.hendrick at vistagy.com; bf-blender developers
Subject: Re: [Bf-committers] Armatures for beyond Release 2.4

Hi Thomas,

Thomas H. Hendrick wrote:
> Gilbert, Joseph T. wrote:
>> I think that what the python api could create some 'fudges' to
convert a
>> transformation matrix and/or a quat/loc into the vector_head,
>> vector_tail, roll This way you could add methods like setMatrix(),
>> setQuat(), setLoc(), setLength() to the armature bone.
>
> I think I understand the Blender Source well enough to write and
submit
> a patch for something like this, but I don't think I fully understand
> the Mathematics behind it.  If someone could give me a general
run-down
> of the equations that would be needed, I could probably make the code
> happen.

This sort of conversion happens in a few places in the blender source,
although never exactly the same as needed here it seems.

in blenkernel/intern/armature.c :

vec_roll_to_mat3  does the opposite of what you need
in b_bone_spline_setup around line 476-481 the roll is computed

So assuming you have a quaternion, a bone length and a bone head,
you can do this:

- convert quaternion to 3x3 matrix
- the 'direction' vector of this rotation is the second column of the
matrix.
(in blender's code this is simply mat[1])
- the bone tail then is bone head +  direction * bone length.
- the roll you can compute exactly the same as in in
b_bone_spline_setup:
- make a rotation matrix with vec_roll_to_mat3 using only the
direction
- compute the difference of this new matrix with the original
matrix
- roll = atan2(diff[2][0], diff[2][2]);

Cheers,
Brecht.
_______________________________________________
Bf-committers mailing list
Bf-committers at projects.blender.org
http://projects.blender.org/mailman/listinfo/bf-committers
```