From edf32a6fb0213bf35748890dfbc84b20d384298e Mon Sep 17 00:00:00 2001 From: Martin Poirier Date: Sun, 29 Nov 2009 18:20:26 +0000 Subject: Gimbal orientation defaults to Normal instead of Global when bone or object is not using euler orientation (Normal is bone axis for pose and Local axis for object, so this is more useful than defaulting to Global). --- .../editors/transform/transform_manipulator.c | 100 +++++++++++---------- 1 file changed, 54 insertions(+), 46 deletions(-) (limited to 'source/blender/editors/transform/transform_manipulator.c') diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index fe79e9b4285..7530e015496 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -182,60 +182,67 @@ static int test_rotmode_euler(short rotmode) return (ELEM(rotmode, ROT_MODE_AXISANGLE, ROT_MODE_QUAT)) ? 0:1; } -void gimbal_axis(Object *ob, float gmat[][3]) +int gimbal_axis(Object *ob, float gmat[][3]) { - if(ob->mode & OB_MODE_POSE) - { - bPoseChannel *pchan= get_active_posechannel(ob); + if (ob) { + if(ob->mode & OB_MODE_POSE) + { + bPoseChannel *pchan= get_active_posechannel(ob); - if(pchan && test_rotmode_euler(pchan->rotmode)) { - float mat[3][3], tmat[3][3], obmat[3][3]; + if(pchan && test_rotmode_euler(pchan->rotmode)) { + float mat[3][3], tmat[3][3], obmat[3][3]; - eulO_to_gimbal_axis(mat, pchan->eul, pchan->rotmode); + eulO_to_gimbal_axis(mat, pchan->eul, pchan->rotmode); - /* apply bone transformation */ - mul_m3_m3m3(tmat, pchan->bone->bone_mat, mat); - - if (pchan->parent) - { - float parent_mat[3][3]; + /* apply bone transformation */ + mul_m3_m3m3(tmat, pchan->bone->bone_mat, mat); - copy_m3_m4(parent_mat, pchan->parent->pose_mat); - mul_m3_m3m3(mat, parent_mat, tmat); + if (pchan->parent) + { + float parent_mat[3][3]; - /* needed if object transformation isn't identity */ - copy_m3_m4(obmat, ob->obmat); - mul_m3_m3m3(gmat, obmat, mat); - } - else - { - /* needed if object transformation isn't identity */ - copy_m3_m4(obmat, ob->obmat); - mul_m3_m3m3(gmat, obmat, tmat); - } + copy_m3_m4(parent_mat, pchan->parent->pose_mat); + mul_m3_m3m3(mat, parent_mat, tmat); - normalize_m3(gmat); + /* needed if object transformation isn't identity */ + copy_m3_m4(obmat, ob->obmat); + mul_m3_m3m3(gmat, obmat, mat); + } + else + { + /* needed if object transformation isn't identity */ + copy_m3_m4(obmat, ob->obmat); + mul_m3_m3m3(gmat, obmat, tmat); + } + + normalize_m3(gmat); + return 1; + } } - } - else { - if(test_rotmode_euler(ob->rotmode)) { - - - if (ob->parent) - { - float parent_mat[3][3], amat[3][3]; + else { + if(test_rotmode_euler(ob->rotmode)) { + - eulO_to_gimbal_axis(amat, ob->rot, ob->rotmode); - copy_m3_m4(parent_mat, ob->parent->obmat); - normalize_m3(parent_mat); - mul_m3_m3m3(gmat, parent_mat, amat); - } - else - { - eulO_to_gimbal_axis(gmat, ob->rot, ob->rotmode); + if (ob->parent) + { + float parent_mat[3][3], amat[3][3]; + + eulO_to_gimbal_axis(amat, ob->rot, ob->rotmode); + copy_m3_m4(parent_mat, ob->parent->obmat); + normalize_m3(parent_mat); + mul_m3_m3m3(gmat, parent_mat, amat); + return 1; + } + else + { + eulO_to_gimbal_axis(gmat, ob->rot, ob->rotmode); + return 1; + } } } } + + return 0; } @@ -481,10 +488,11 @@ int calc_manipulator_stats(const bContext *C) case V3D_MANIP_GIMBAL: { float mat[3][3]; - unit_m3(mat); - gimbal_axis(ob, mat); - copy_m4_m3(rv3d->twmat, mat); - break; + if (gimbal_axis(ob, mat)) { + copy_m4_m3(rv3d->twmat, mat); + break; + } + /* if not gimbal, fall through to normal */ } case V3D_MANIP_NORMAL: if(obedit || ob->mode & OB_MODE_POSE) { -- cgit v1.2.3