Cleanup: comments, redundant normalize

This commit is contained in:
2019-11-29 14:57:07 +11:00
parent 77c7440540
commit ac15f5e9b0

View File

@@ -281,6 +281,11 @@ static void armature_transform_recurse(ListBase *bonebase,
{
for (Bone *bone = bonebase->first; bone; bone = bone->next) {
/* Store the initial bone roll in a matrix, this is needed even for child bones
* so any change in head/tail doesn't cause the roll to change.
*
* Logic here is different to edit-mode because
* this is calculated in relative to the parent. */
float roll_mat3_pre[3][3];
{
float delta[3];
@@ -290,6 +295,7 @@ static void armature_transform_recurse(ListBase *bonebase,
mul_m3_m3m3(roll_mat3_pre, mat3, roll_mat3_pre);
}
}
/* Optional, use this for predictable results since the roll is re-calculated below anyway. */
bone->roll = 0.0f;
mul_m4_v3(mat, bone->arm_head);
@@ -308,17 +314,14 @@ static void armature_transform_recurse(ListBase *bonebase,
copy_v3_v3(bone->tail, bone->arm_tail);
}
/* Now the head/tail have been updated, set the roll back, matching 'roll_mat3_pre'. */
{
float roll_mat3_post[3][3];
float delta_mat3[3][3];
float roll_mat3_post[3][3], delta_mat3[3][3];
float delta[3];
sub_v3_v3v3(delta, bone->tail, bone->head);
vec_roll_to_mat3(delta, bone->roll, roll_mat3_post);
normalize_v3(delta);
vec_roll_to_mat3(delta, 0.0f, roll_mat3_post);
invert_m3(roll_mat3_post);
mul_m3_m3m3(delta_mat3, roll_mat3_post, roll_mat3_pre);
bone->roll = atan2f(delta_mat3[2][0], delta_mat3[2][2]);
}