Fix T42444: Neg scale rotated object flips 2x axis
[blender.git] / source / blender / editors / transform / transform.c
index a85801a621bfacc917d8edd0f37656f3ee46a5c6..d704f62654baaaab0591de3328ef63213863be63 100644 (file)
@@ -58,6 +58,7 @@
 #include "BKE_particle.h"
 #include "BKE_unit.h"
 #include "BKE_mask.h"
+#include "BKE_report.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -270,7 +271,8 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
                        r_vec[0] = dx;
                        r_vec[1] = dy;
                }
-               else {  const float mval_f[2] = {(float)dx, (float)dy};
+               else {
+                       const float mval_f[2] = {(float)dx, (float)dy};
                        ED_view3d_win_to_delta(t->ar, mval_f, r_vec, t->zfac);
                }
        }
@@ -1123,47 +1125,22 @@ int transformEvent(TransInfo *t, const wmEvent *event)
                                handled = true;
                                break;
                        case TFM_MODAL_AXIS_X:
-                               if ((t->flag & T_NO_CONSTRAINT) == 0) {
-                                       if (cmode == 'X') {
-                                               stopConstraint(t);
-                                       }
-                                       else {
-                                               if (t->flag & T_2D_EDIT) {
-                                                       setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), IFACE_("along X"));
-                                               }
-                                               else {
-                                                       setUserConstraint(t, t->current_orientation, (CON_AXIS0), IFACE_("along %s X"));
-                                               }
-                                       }
+                               if (!(t->flag & T_NO_CONSTRAINT)) {
+                                       transform_event_xyz_constraint(t, XKEY, cmode);
                                        t->redraw |= TREDRAW_HARD;
                                        handled = true;
                                }
                                break;
                        case TFM_MODAL_AXIS_Y:
                                if ((t->flag & T_NO_CONSTRAINT) == 0) {
-                                       if (cmode == 'Y') {
-                                               stopConstraint(t);
-                                       }
-                                       else {
-                                               if (t->flag & T_2D_EDIT) {
-                                                       setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), IFACE_("along Y"));
-                                               }
-                                               else {
-                                                       setUserConstraint(t, t->current_orientation, (CON_AXIS1), IFACE_("along %s Y"));
-                                               }
-                                       }
+                                       transform_event_xyz_constraint(t, YKEY, cmode);
                                        t->redraw |= TREDRAW_HARD;
                                        handled = true;
                                }
                                break;
                        case TFM_MODAL_AXIS_Z:
-                               if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) {
-                                       if (cmode == 'Z') {
-                                               stopConstraint(t);
-                                       }
-                                       else {
-                                               setUserConstraint(t, t->current_orientation, (CON_AXIS2), IFACE_("along %s Z"));
-                                       }
+                               if ((t->flag & (T_NO_CONSTRAINT)) == 0) {
+                                       transform_event_xyz_constraint(t, ZKEY, cmode);
                                        t->redraw |= TREDRAW_HARD;
                                        handled = true;
                                }
@@ -1838,24 +1815,26 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
        
        BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
        
-       xco = rect.xmax - (int)printable_size[0] - 10;
-       yco = rect.ymax - (int)printable_size[1] - 10;
+       xco = (rect.xmax - U.widget_unit) - (int)printable_size[0];
+       yco = (rect.ymax - U.widget_unit);
        
        /* warning text (to clarify meaning of overlays)
         * - original color was red to match the icon, but that clashes badly with a less nasty border
         */
        UI_ThemeColorShade(TH_TEXT_HI, -50);
 #ifdef WITH_INTERNATIONAL
-       BLF_draw_default(xco, ar->winy - 17, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
+       BLF_draw_default(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
 #else
-       BLF_draw_default_ascii(xco, ar->winy - 17, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
+       BLF_draw_default_ascii(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
 #endif
        
        /* autokey recording icon... */
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        
-       xco -= (ICON_DEFAULT_WIDTH + 2);
+       xco -= U.widget_unit;
+       yco -= (int)printable_size[1] / 2;
+
        UI_icon_draw(xco, yco, ICON_REC);
        
        glDisable(GL_BLEND);
@@ -2051,7 +2030,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
        initTransInfo(C, t, op, event);
 
        if (t->spacetype == SPACE_VIEW3D) {
-               //calc_manipulator_stats(curarea);
                initTransformOrientation(C, t);
 
                t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
@@ -3181,38 +3159,23 @@ static void headerResize(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
        }
 }
 
-/* FLT_EPSILON is too small [#29633], 0.0000001f starts to flip */
-#define TX_FLIP_EPS 0.00001f
-BLI_INLINE int tx_sign(const float a)
-{
-       return (a < -TX_FLIP_EPS ? 1 : a > TX_FLIP_EPS ? 2 : 3);
-}
-BLI_INLINE int tx_vec_sign_flip(const float a[3], const float b[3])
-{
-       return ((tx_sign(a[0]) & tx_sign(b[0])) == 0 ||
-               (tx_sign(a[1]) & tx_sign(b[1])) == 0 ||
-               (tx_sign(a[2]) & tx_sign(b[2])) == 0);
-}
-
-/* smat is reference matrix, only scaled */
+/**
+ * \a smat is reference matrix only.
+ *
+ * \note this is a tricky area, before making changes see: T29633, T42444
+ */
 static void TransMat3ToSize(float mat[3][3], float smat[3][3], float size[3])
 {
-       float vec[3];
-       
-       copy_v3_v3(vec, mat[0]);
-       size[0] = normalize_v3(vec);
-       copy_v3_v3(vec, mat[1]);
-       size[1] = normalize_v3(vec);
-       copy_v3_v3(vec, mat[2]);
-       size[2] = normalize_v3(vec);
-       
+       float rmat[3][3];
+
+       mat3_to_rot_size(rmat, size, mat);
+
        /* first tried with dotproduct... but the sign flip is crucial */
-       if (tx_vec_sign_flip(mat[0], smat[0]) ) size[0] = -size[0];
-       if (tx_vec_sign_flip(mat[1], smat[1]) ) size[1] = -size[1];
-       if (tx_vec_sign_flip(mat[2], smat[2]) ) size[2] = -size[2];
+       if (dot_v3v3(rmat[0], smat[0]) < 0.0f) size[0] = -size[0];
+       if (dot_v3v3(rmat[1], smat[1]) < 0.0f) size[1] = -size[1];
+       if (dot_v3v3(rmat[2], smat[2]) < 0.0f) size[2] = -size[2];
 }
 
-
 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
 {
        float tmat[3][3], smat[3][3], center[3];
@@ -4064,6 +4027,9 @@ static void initTranslation(TransInfo *t)
 {
        if (t->spacetype == SPACE_ACTION) {
                /* this space uses time translate */
+               BKE_report(t->reports, RPT_ERROR, 
+                          "Use 'Time_Translate' transform mode instead of 'Translation' mode "
+                          "for translating keyframes in Dope Sheet Editor");
                t->state = TRANS_CANCEL;
        }