Transform: snapping: normal-align: Cleanup!
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 30 Oct 2014 11:54:05 +0000 (12:54 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 30 Oct 2014 11:56:43 +0000 (12:56 +0100)
Use BLI's `rotation_between_vecs_to_mat3` helper instead of own custom code,
both simplifies the code and fixes wrong handling when snapped normal was exactly
opposed to org one (i.e. 180° rot case).

source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_snap.c

index d704f62654baaaab0591de3328ef63213863be63..9547f0bc77fe6fcef37f3d6b2c86d0ff82eea727 100644 (file)
@@ -4187,29 +4187,21 @@ static void applyTranslationValue(TransInfo *t, float vec[3])
                
                if (td->flag & TD_SKIP)
                        continue;
-               
+
                /* handle snapping rotation before doing the translation */
                if (usingSnappingNormal(t)) {
                        if (validSnappingNormal(t)) {
                                const float *original_normal;
-                               float axis[3];
-                               float quat[4];
                                float mat[3][3];
-                               float angle;
                                
                                /* In pose mode, we want to align normals with Y axis of bones... */
                                if (t->flag & T_POSE)
                                        original_normal = td->axismtx[1];
                                else
                                        original_normal = td->axismtx[2];
-                               
-                               cross_v3_v3v3(axis, original_normal, t->tsnap.snapNormal);
-                               angle = saacos(dot_v3v3(original_normal, t->tsnap.snapNormal));
-                               
-                               axis_angle_to_quat(quat, axis, angle);
-                               
-                               quat_to_mat3(mat, quat);
-                               
+
+                               rotation_between_vecs_to_mat3(mat, original_normal, t->tsnap.snapNormal);
+
                                ElementRotation(t, td, mat, V3D_LOCAL);
                        }
                        else {
index 47b208442945b5e5a31373b944347e631fcc917f..dcc7024705add3e3280f96f4ad94cae891e23902 100644 (file)
@@ -341,22 +341,15 @@ void applyProject(TransInfo *t)
                                        if (t->tsnap.align && (t->flag & T_OBJECT)) {
                                                /* handle alignment as well */
                                                const float *original_normal;
-                                               float axis[3];
                                                float mat[3][3];
-                                               float angle;
                                                float totmat[3][3], smat[3][3];
-                                               float eul[3], fmat[3][3], quat[4];
+                                               float eul[3], fmat[3][3];
                                                float obmat[3][3];
 
                                                /* In pose mode, we want to align normals with Y axis of bones... */
                                                original_normal = td->axismtx[2];
 
-                                               cross_v3_v3v3(axis, original_normal, no);
-                                               angle = saacos(dot_v3v3(original_normal, no));
-
-                                               axis_angle_to_quat(quat, axis, angle);
-
-                                               quat_to_mat3(mat, quat);
+                                               rotation_between_vecs_to_mat3(mat, original_normal, no);
 
                                                mul_m3_m3m3(totmat, mat, td->mtx);
                                                mul_m3_m3m3(smat, td->smtx, totmat);