Transform fixes
authorMartin Poirier <theeth@yahoo.com>
Thu, 31 Mar 2005 21:02:35 +0000 (21:02 +0000)
committerMartin Poirier <theeth@yahoo.com>
Thu, 31 Mar 2005 21:02:35 +0000 (21:02 +0000)
Connected PET for mesh had an infinite loop in some case. Fixed an made a bit faster.
Renamed the numinput flag.
Corrected a conflict in TransInfo flags. This was a crash waiting to happen.
NO_CONSTRAINT flag now correctly used to disable MMB and constraint hotkeys when needed.

Added check for the manipulator flag when drawing them before applying transformation matrix. Was really weird when doing MMB with rotation.

source/blender/src/transform.c
source/blender/src/transform.h
source/blender/src/transform_constraints.c
source/blender/src/transform_generics.c
source/blender/src/transform_manipulator.c
source/blender/src/transform_numinput.c

index 6bccb672fb6dcaae07d2d4358e029feb1fca6926..4ba9c8afe5870077dd3351ad888f9e909a931af1 100755 (executable)
@@ -788,7 +788,7 @@ static void editmesh_set_connectivity_distance(int total, float *vectors, EditVe
                        eve->vn = (EditVert *)(i);
 
                        if(eve->f & SELECT) {
-                               eve->f2= 1;
+                               eve->f2= 2;
                                E_NEAR(eve) = eve;
                                E_VEC(eve)[0] = 0.0f;
                                E_VEC(eve)[1] = 0.0f;
@@ -816,26 +816,34 @@ static void editmesh_set_connectivity_distance(int total, float *vectors, EditVe
                                float *vec2 = E_VEC(v2);
                                float *vec1 = E_VEC(v1);
 
+                               if (v1->f2 + v2->f2 == 4)
+                                       continue;
+
                                if (v1->f2) {
                                        if (v2->f2) {
                                                float nvec[3];
                                                float len1 = VecLength(vec1);
                                                float len2 = VecLength(vec2);
                                                float lenn;
-                                               /* for v2 */
-                                               VecSubf(nvec, v2->co, E_NEAR(v1)->co);
-                                               lenn = VecLength(nvec);
-                                               if (lenn - len1 > 0.00001f && len2 - lenn > 0.00001f) {
-                                                       VECCOPY(vec2, nvec);
-                                                       E_NEAR(v2) = E_NEAR(v1);
-                                                       done = 1;
+                                               /* for v2 if not selected */
+                                               if (v2->f2 != 2) {
+                                                       VecSubf(nvec, v2->co, E_NEAR(v1)->co);
+                                                       lenn = VecLength(nvec);
+                                                       if (lenn - len1 > 0.00001f && len2 - lenn > 0.00001f) {
+                                                               VECCOPY(vec2, nvec);
+                                                               E_NEAR(v2) = E_NEAR(v1);
+                                                               done = 1;
+                                                       }
                                                }
-                                               /* for v1 */
-                                               VecSubf(nvec, v1->co, E_NEAR(v2)->co);
-                                               if (lenn - len2 > 0.00001f && len1 - lenn > 0.00001f) {
-                                                       VECCOPY(vec1, nvec);
-                                                       E_NEAR(v1) = E_NEAR(v2);
-                                                       done = 1;
+                                               /* for v1 if not selected */
+                                               if (v1->f2 != 2) {
+                                                       VecSubf(nvec, v1->co, E_NEAR(v2)->co);
+                                                       lenn = VecLength(nvec);
+                                                       if (lenn - len2 > 0.00001f && len1 - lenn > 0.00001f) {
+                                                               VECCOPY(vec1, nvec);
+                                                               E_NEAR(v1) = E_NEAR(v2);
+                                                               done = 1;
+                                                       }
                                                }
                                        }
                                        else {
@@ -1503,11 +1511,11 @@ void Transform(int mode, int context)
        }
 
        Trans.context = context;
-       
-       initTransModeFlags(&Trans, mode);       // modal settings in struct Trans
 
        initTrans(&Trans);                                      // internal data, mouse, vectors
 
+       initTransModeFlags(&Trans, mode);       // modal settings in struct Trans
+
        createTransData(&Trans);                        // make TransData structs from selection
 
        if (Trans.total == 0)
@@ -1599,18 +1607,20 @@ void Transform(int mode, int context)
                                        break;
                                        
                                case MIDDLEMOUSE:
-                                       /* exception for switching to dolly, or trackball, in camera view */
-                                       if (Trans.flag & T_CAMERA) {
-                                               if (Trans.mode==TFM_TRANSLATION)
-                                                       setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
-                                               else if (Trans.mode==TFM_ROTATION) {
-                                                       restoreTransObjects(&Trans);
-                                                       initTransModeFlags(&Trans, TFM_TRACKBALL);
-                                                       initTrackball(&Trans);
+                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                                               /* exception for switching to dolly, or trackball, in camera view */
+                                               if (Trans.flag & T_CAMERA) {
+                                                       if (Trans.mode==TFM_TRANSLATION)
+                                                               setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
+                                                       else if (Trans.mode==TFM_ROTATION) {
+                                                               restoreTransObjects(&Trans);
+                                                               initTransModeFlags(&Trans, TFM_TRACKBALL);
+                                                               initTrackball(&Trans);
+                                                       }
                                                }
+                                               else 
+                                                       initSelectConstraint(&Trans);
                                        }
-                                       else 
-                                               initSelectConstraint(&Trans);
                                        Trans.redraw = 1;
                                        break;
                                case ESCKEY:
@@ -1649,73 +1659,79 @@ void Transform(int mode, int context)
                                        Trans.redraw = 1;
                                        break;
                                case XKEY:
-                                       if (cmode == 'X') {
-                                               stopConstraint(&Trans);
-                                               cmode = '\0';
-                                       }
-                                       else if(cmode == 'x') {
-                                               if (G.qual == 0)
-                                                       setLocalConstraint(&Trans, (CON_AXIS0), "along local X");
-                                               else if (G.qual == LR_SHIFTKEY)
-                                                       setLocalConstraint(&Trans, (CON_AXIS1|CON_AXIS2), "locking local X");
+                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                                               if (cmode == 'X') {
+                                                       stopConstraint(&Trans);
+                                                       cmode = '\0';
+                                               }
+                                               else if(cmode == 'x') {
+                                                       if (G.qual == 0)
+                                                               setLocalConstraint(&Trans, (CON_AXIS0), "along local X");
+                                                       else if (G.qual == LR_SHIFTKEY)
+                                                               setLocalConstraint(&Trans, (CON_AXIS1|CON_AXIS2), "locking local X");
 
-                                               cmode = 'X';
-                                       }
-                                       else {
-                                               if (G.qual == 0)
-                                                       setConstraint(&Trans, mati, (CON_AXIS0), "along global X");
-                                               else if (G.qual == LR_SHIFTKEY)
-                                                       setConstraint(&Trans, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
+                                                       cmode = 'X';
+                                               }
+                                               else {
+                                                       if (G.qual == 0)
+                                                               setConstraint(&Trans, mati, (CON_AXIS0), "along global X");
+                                                       else if (G.qual == LR_SHIFTKEY)
+                                                               setConstraint(&Trans, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
 
-                                               cmode = 'x';
+                                                       cmode = 'x';
+                                               }
+                                               Trans.redraw = 1;
                                        }
-                                       Trans.redraw = 1;
                                        break;
                                case YKEY:
-                                       if (cmode == 'Y') {
-                                               stopConstraint(&Trans);
-                                               cmode = '\0';
-                                       }
-                                       else if(cmode == 'y') {
-                                               if (G.qual == 0)
-                                                       setLocalConstraint(&Trans, (CON_AXIS1), "along global Y");
-                                               else if (G.qual == LR_SHIFTKEY)
-                                                       setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS2), "locking global Y");
+                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                                               if (cmode == 'Y') {
+                                                       stopConstraint(&Trans);
+                                                       cmode = '\0';
+                                               }
+                                               else if(cmode == 'y') {
+                                                       if (G.qual == 0)
+                                                               setLocalConstraint(&Trans, (CON_AXIS1), "along global Y");
+                                                       else if (G.qual == LR_SHIFTKEY)
+                                                               setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS2), "locking global Y");
 
-                                               cmode = 'Y';
-                                       }
-                                       else {
-                                               if (G.qual == 0)
-                                                       setConstraint(&Trans, mati, (CON_AXIS1), "along local Y");
-                                               else if (G.qual == LR_SHIFTKEY)
-                                                       setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS2), "locking local Y");
+                                                       cmode = 'Y';
+                                               }
+                                               else {
+                                                       if (G.qual == 0)
+                                                               setConstraint(&Trans, mati, (CON_AXIS1), "along local Y");
+                                                       else if (G.qual == LR_SHIFTKEY)
+                                                               setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS2), "locking local Y");
 
-                                               cmode = 'y';
+                                                       cmode = 'y';
+                                               }
+                                               Trans.redraw = 1;
                                        }
-                                       Trans.redraw = 1;
                                        break;
                                case ZKEY:
-                                       if (cmode == 'Z') {
-                                               stopConstraint(&Trans);
-                                               cmode = '\0';
-                                       }
-                                       else if(cmode == 'z') {
-                                               if (G.qual == 0)
-                                                       setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
-                                               else if (G.qual == LR_SHIFTKEY)
-                                                       setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS1), "locking local Z");
+                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                                               if (cmode == 'Z') {
+                                                       stopConstraint(&Trans);
+                                                       cmode = '\0';
+                                               }
+                                               else if(cmode == 'z') {
+                                                       if (G.qual == 0)
+                                                               setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
+                                                       else if (G.qual == LR_SHIFTKEY)
+                                                               setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS1), "locking local Z");
 
-                                               cmode = 'Z';
-                                       }
-                                       else {
-                                               if (G.qual == 0)
-                                                       setConstraint(&Trans, mati, (CON_AXIS2), "along global Z");
-                                               else if (G.qual == LR_SHIFTKEY)
-                                                       setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
+                                                       cmode = 'Z';
+                                               }
+                                               else {
+                                                       if (G.qual == 0)
+                                                               setConstraint(&Trans, mati, (CON_AXIS2), "along global Z");
+                                                       else if (G.qual == LR_SHIFTKEY)
+                                                               setConstraint(&Trans, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
 
-                                               cmode = 'z';
+                                                       cmode = 'z';
+                                               }
+                                               Trans.redraw = 1;
                                        }
-                                       Trans.redraw = 1;
                                        break;
                                case OKEY:
                                        if (G.qual==LR_SHIFTKEY) {
@@ -1750,8 +1766,10 @@ void Transform(int mode, int context)
                                /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still 
                                   after releasing modifer key */
                                case MIDDLEMOUSE:
-                                       postSelectConstraint(&Trans);
-                                       Trans.redraw = 1;
+                                       if ((Trans.flag & T_NO_CONSTRAINT)==0) {
+                                               postSelectConstraint(&Trans);
+                                               Trans.redraw = 1;
+                                       }
                                        break;
                                case LEFTMOUSE:
                                case RIGHTMOUSE:
@@ -1821,9 +1839,10 @@ void ManipulatorTransform(int mode)
 
        Trans.context = CTX_NONE;
 
+       initTrans(&Trans);                                      // internal data, mouse, vectors
+
        initTransModeFlags(&Trans, mode);       // modal settings in struct Trans
 
-       initTrans(&Trans);                                      // internal data, mouse, vectors
        G.moving |= G_TRANSFORM_MANIP;          // signal to draw manipuls while transform
        createTransData(&Trans);                        // make TransData structs from selection
 
@@ -3063,3 +3082,72 @@ int Tilt(TransInfo *t, short mval[2])
        return 1;
 }
 
+/* ************************** PUSH/PULL *************************** */
+
+void initPushPull(TransInfo *t) 
+{
+       t->idx_max = 0;
+       t->num.idx_max = 0;
+       t->snap[0] = 0.0f;
+       t->snap[1] = 1.0f;
+       t->snap[2] = t->snap[1] * 0.1f;
+       t->transform = ShrinkFatten;
+}
+
+
+
+int PushPull(TransInfo *t, short mval[2]) 
+{
+       float vec[3];
+       float distance;
+       int i;
+       char str[50];
+       TransData *td = t->data;
+
+       window_to_3d(t->vec, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1]));
+       Projf(vec, t->vec, G.vd->viewinv[1]);
+       distance = Inpf(t->viewinv[1], vec) * 2.0f;
+
+       snapGrid(t, &distance);
+
+       applyNumInput(&t->num, &distance);
+
+       /* header print for NumInput */
+       if (hasNumInput(&t->num)) {
+               char c[20];
+
+               outputNumInput(&(t->num), c);
+
+               sprintf(str, "Push/Pull: %s%s %s", c, t->con.text, t->proptext);
+       }
+       else {
+               /* default header print */
+               sprintf(str, "Push/Pull: %.4f%s %s", distance, t->con.text, t->proptext);
+       }
+       
+       
+       for(i = 0 ; i < t->total; i++, td++) {
+               if (td->flag & TD_NOACTION)
+                       break;
+
+               VecSubf(vec, t->center, td->center);
+               if (t->con.applyRot) {
+                       float axis[3];
+                       t->con.applyRot(t, td, axis);
+                       Projf(vec, vec, axis);
+               }
+               Normalise(vec);
+               VecMulf(vec, distance);
+               VecMulf(vec, td->factor);
+
+               VecAddf(td->loc, td->iloc, vec);
+       }
+
+       recalcData(t);
+
+       headerprint(str);
+
+       force_draw(0);
+
+       return 1;
+}
index 58d6658791d07c3b2f6fd1837035ef3625454d01..28e0e5a48a0ed36bfad57b0067ddbb63974c49fe 100755 (executable)
@@ -140,13 +140,12 @@ typedef struct TransInfo {
 
 /* ******************** Macros & Prototypes *********************** */
 
-/* MODE AND NUMINPUT FLAGS */
-#define NOCONSTRAINT   1
-#define NULLONE                        2
-#define NONEGATIVE             4
-#define        NOZERO                  8
-#define NOFRACTION             16
-#define        AFFECTALL               32
+/* NUMINPUT FLAGS */
+#define NUM_NULL_ONE           2
+#define NUM_NO_NEGATIVE                4
+#define        NUM_NO_ZERO                     8
+#define NUM_NO_FRACTION                16
+#define        NUM_AFFECT_ALL          32
 
 /* transinfo->flag */
 #define T_OBJECT               1
@@ -159,6 +158,12 @@ typedef struct TransInfo {
                // for manipulator exceptions, like scaling using center point, drawing help lines
 #define T_USES_MANIPULATOR     128
 
+/* restrictions flags */
+#define T_ALL_RESTRICTIONS     (256|512|1024)
+#define T_NO_CONSTRAINT        256
+#define T_NULL_ONE             512
+#define T_NO_ZERO              1024
+
 
 /* transinfo->con->mode */
 #define CON_APPLY              1
index 9c5d200891b49425f3f02b5e072398e6046410ac..34cec872b59318d43fa701b0ee89162f482597c5 100755 (executable)
@@ -116,7 +116,7 @@ void getConstraintMatrix(TransInfo *t);
 void constraintNumInput(TransInfo *t, float vec[3])
 {
        int mode = t->con.mode;
-       float nval = (t->num.flag & NULLONE)?1.0f:0.0f;
+       float nval = (t->flag & T_NULL_ONE)?1.0f:0.0f;
 
        if (getConstraintSpaceDimension(t) == 2) {
                if (mode & (CON_AXIS0|CON_AXIS1)) {
@@ -157,7 +157,7 @@ static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) {
 
        snapGrid(t, vec);
 
-       if (t->num.flag & NULLONE) {
+       if (t->num.flag & T_NULL_ONE) {
                if (!(t->con.mode & CON_AXIS0))
                        vec[0] = 1.0f;
 
index 25e87193f0d23631b57d311661c2e03557add739..fc0ff34f93d43a86ff6d74d2c5b1b1a2990400d0 100755 (executable)
@@ -314,25 +314,29 @@ void recalcData(TransInfo *t)
 
 void initTransModeFlags(TransInfo *t, int mode) 
 {
-       t->num.flag = 0;
        t->mode = mode;
+       t->num.flag = 0;
+
+       /* REMOVING RESTRICTIONS FLAGS */
+       t->flag &= ~T_ALL_RESTRICTIONS;
        
        switch (mode) {
        case TFM_RESIZE:
-               t->num.flag |= NULLONE;
-               t->num.flag |= AFFECTALL;
+               t->flag |= T_NULL_ONE;
+               t->num.flag |= NUM_NULL_ONE;
+               t->num.flag |= NUM_AFFECT_ALL;
                if (!G.obedit) {
-                       t->flag |= NOZERO;
-                       t->num.flag |= NOZERO;
+                       t->flag |= T_NO_ZERO;
+                       t->num.flag |= NUM_NO_ZERO;
                }
                break;
        case TFM_TOSPHERE:
-               t->num.flag |= NULLONE;
-               t->num.flag |= NONEGATIVE;
-               t->flag |= NOCONSTRAINT;
+               t->num.flag |= NUM_NULL_ONE;
+               t->num.flag |= NUM_NO_NEGATIVE;
+               t->flag |= T_NO_CONSTRAINT;
                break;
        case TFM_SHEAR:
-               t->flag |= NOCONSTRAINT;
+               t->flag |= T_NO_CONSTRAINT;
                break;
        }
 }
@@ -381,8 +385,9 @@ void initTrans (TransInfo *t)
        t->data = NULL;
        t->ext = NULL;
 
-       getmouseco_areawin(t->imval);
        t->flag = 0;
+
+       getmouseco_areawin(t->imval);
        t->con.imval[0] = t->imval[0];
        t->con.imval[1] = t->imval[1];
 
index c9060403aff0b98dc938c9bb5e24ceab471f9d87..21fcd40df4aae1441a09b9b3221eb2623b16e9b6 100644 (file)
@@ -1177,7 +1177,9 @@ static void draw_manipulator_rotate_cyl(float mat[][4], int moving, int drawflag
        if(moving) {
                float matt[4][4];
                Mat4CpyMat4(matt, mat); // to copy the parts outside of [3][3]
-               Mat4MulMat34(matt, Trans.mat, mat);
+               if (Trans.flag & T_USES_MANIPULATOR) {
+                       Mat4MulMat34(matt, Trans.mat, mat);
+               }
                mymultmatrix(matt);
        }
        else {
index e051f60e8f02faf805a63f1252d4c6b4b9b741d3..262ff79c64b178268a38e619005410337a4061ce 100755 (executable)
@@ -66,7 +66,7 @@ void outputNumInput(NumInput *n, char *str)
 
        for (j=0; j<=n->idx_max; j++) {
                /* if AFFECTALL and no number typed and cursor not on number, use first number */
-               if (n->flag & AFFECTALL && n->idx != j && n->ctrl[j] == 0)
+               if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
                        i = 0;
                else
                        i = j;
@@ -124,15 +124,15 @@ void applyNumInput(NumInput *n, float *vec)
        if (hasNumInput(n)) {
                for (j=0; j<=n->idx_max; j++) {
                        /* if AFFECTALL and no number typed and cursor not on number, use first number */
-                       if (n->flag & AFFECTALL && n->idx != j && n->ctrl[j] == 0)
+                       if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
                                i = 0;
                        else
                                i = j;
 
-                       if (n->ctrl[i] == 0 && n->flag & NULLONE) {
+                       if (n->ctrl[i] == 0 && n->flag & NUM_NULL_ONE) {
                                vec[j] = 1.0f;
                        }
-                       else if (n->val[i] == 0.0f && n->flag & NOZERO) {
+                       else if (n->val[i] == 0.0f && n->flag & NUM_NO_ZERO) {
                                vec[j] = 0.0001f;
                        }
                        else {
@@ -164,7 +164,7 @@ char handleNumInput(NumInput *n, unsigned short event)
                break;
        case PERIODKEY:
        case PADPERIOD:
-               if (n->flag & NOFRACTION)
+               if (n->flag & NUM_NO_FRACTION)
                        break;
 
                switch (n->ctrl[idx])
@@ -178,7 +178,7 @@ char handleNumInput(NumInput *n, unsigned short event)
                }
                break;
        case MINUSKEY:
-               if (n->flag & NONEGATIVE)
+               if (n->flag & NUM_NO_NEGATIVE)
                        break;
 
                if (n->ctrl[idx]) {