diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-10-26 16:48:07 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-10-26 16:48:07 +0400 |
commit | f8ec6b8654962cd2fc77b9941f35c8127d37fc90 (patch) | |
tree | be28affb99be07434be6301d7b91f458b688ae4d /source/blender/blenkernel | |
parent | 30b4fa2aa839e7dba72d6d913fd0bff5cc816e43 (diff) |
move matrix decomposition out of object.c into BLI_math_matrix function: mat4_to_loc_rot_size(), use this now for pchan_apply_mat4() to support negative scale, visual keying now uses compatible eulers.
also added access to this in python's mathutils.Matrix()
loc, quat, scale = matrix.decompose()
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_armature.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 40 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 51 |
3 files changed, 32 insertions, 62 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 466b5d9a845..06e24431df4 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -105,7 +105,8 @@ void armature_mat_pose_to_bone(struct bPoseChannel *pchan, float inmat[][4], flo void armature_loc_pose_to_bone(struct bPoseChannel *pchan, float *inloc, float *outloc); void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]); -void pchan_apply_mat4(struct bPoseChannel *pchan, float mat[][4]); +void pchan_mat3_to_rot(struct bPoseChannel *pchan, float mat[][3], short use_compat); +void pchan_apply_mat4(struct bPoseChannel *pchan, float mat[][4], short use_comat); void pchan_to_mat4(struct bPoseChannel *pchan, float chan_mat[4][4]); /* Rotation Mode Conversions - Used for PoseChannels + Objects... */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 029b3c2e141..b44bf751a8a 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1177,32 +1177,30 @@ void armature_loc_pose_to_bone(bPoseChannel *pchan, float *inloc, float *outloc) VECCOPY(outloc, nLocMat[3]); } +/* same as object_mat3_to_rot() */ +void pchan_mat3_to_rot(bPoseChannel *pchan, float mat[][3], short use_compat) +{ + switch(pchan->rotmode) { + case ROT_MODE_QUAT: + mat3_to_quat(pchan->quat, mat); + break; + case ROT_MODE_AXISANGLE: + mat3_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, mat); + break; + default: /* euler */ + if(use_compat) mat3_to_compatible_eulO(pchan->eul, pchan->eul, pchan->rotmode, mat); + else mat3_to_eulO(pchan->eul, pchan->rotmode, mat); + } +} /* Apply a 4x4 matrix to the pose bone, * similar to object_apply_mat4() */ -void pchan_apply_mat4(bPoseChannel *pchan, float mat[][4]) +void pchan_apply_mat4(bPoseChannel *pchan, float mat[][4], short use_compat) { - /* location */ - copy_v3_v3(pchan->loc, mat[3]); - - /* scale */ - mat4_to_size(pchan->size, mat); - - /* rotation */ - if (pchan->rotmode == ROT_MODE_AXISANGLE) { - float tmp_quat[4]; - - /* need to convert to quat first (in temp var)... */ - mat4_to_quat(tmp_quat, mat); - quat_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, tmp_quat); - } - else if (pchan->rotmode == ROT_MODE_QUAT) { - mat4_to_quat(pchan->quat, mat); - } - else { - mat4_to_eulO(pchan->eul, pchan->rotmode, mat); - } + float rot[3][3]; + mat4_to_loc_rot_size(pchan->loc, rot, pchan->size, mat); + pchan_mat3_to_rot(pchan, rot, use_compat); } /* Remove rest-position effects from pose-transform for obtaining diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 9d93fac8ad0..5ade08478a2 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1680,54 +1680,25 @@ void object_rot_to_mat3(Object *ob, float mat[][3]) void object_mat3_to_rot(Object *ob, float mat[][3], short use_compat) { - if (ob->rotmode == ROT_MODE_QUAT) + switch(ob->rotmode) { + case ROT_MODE_QUAT: mat3_to_quat(ob->quat, mat); - else if (ob->rotmode == ROT_MODE_AXISANGLE) + break; + case ROT_MODE_AXISANGLE: mat3_to_axis_angle(ob->rotAxis, &ob->rotAngle, mat); - else { - if(use_compat) { - float eul[3]; - VECCOPY(eul, ob->rot); - mat3_to_compatible_eulO(ob->rot, eul, ob->rotmode, mat); - } - else - mat3_to_eulO(ob->rot, ob->rotmode, mat); + break; + default: /* euler */ + if(use_compat) mat3_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, mat); + else mat3_to_eulO(ob->rot, ob->rotmode, mat); } } /* see pchan_apply_mat4() for the equivalent 'pchan' function */ void object_apply_mat4(Object *ob, float mat[][4], short use_compat) { - float mat3[3][3]; /* obmat -> 3x3 */ - float mat3_n[3][3]; /* obmat -> normalized, 3x3 */ - float imat3_n[3][3]; /* obmat -> normalized & inverted, 3x3 */ - - /* location */ - copy_v3_v3(ob->loc, mat[3]); - - /* rotation & scale are linked, we need to create the mat's - * for these together since they are related. */ - copy_m3_m4(mat3, mat); - /* so scale doesnt interfear with rotation [#24291] */ - /* note: this is a workaround for negative matrix not working for rotation conversion, FIXME */ - normalize_m3_m3(mat3_n, (const float(*)[3])mat3); - if(is_negative_m3(mat3_n)) { - negate_v3(mat3_n[0]); - negate_v3(mat3_n[1]); - negate_v3(mat3_n[2]); - } - - /* rotation */ - object_mat3_to_rot(ob, mat3_n, use_compat); - - /* scale */ - /* note: mat4_to_size(ob->size, mat) fails for negative scale */ - invert_m3_m3(imat3_n, mat3_n); - mul_m3_m3m3(mat3, imat3_n, mat3); - - ob->size[0]= mat3[0][0]; - ob->size[1]= mat3[1][1]; - ob->size[2]= mat3[2][2]; + float rot[3][3]; + mat4_to_loc_rot_size(ob->loc, rot, ob->size, mat); + object_mat3_to_rot(ob, rot, use_compat); } void object_to_mat3(Object *ob, float mat[][3]) /* no parent */ |