Cleanup: transform center
authorCampbell Barton <ideasman42@gmail.com>
Fri, 26 Jun 2015 06:19:39 +0000 (16:19 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 26 Jun 2015 06:21:04 +0000 (16:21 +1000)
store global center in transform struct,
some code was calculating all the time, this is useful to keep available.

source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_constraints.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_snap.c

index 1c8c21cadd189e47a4880b4a72476e1e7fd092ec..68d77dec619b7910c9b1dc069f1fafcdbf710644 100644 (file)
@@ -1548,7 +1548,7 @@ bool calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], floa
 
                if (cent3d) {
                        // Copy center from constraint center. Transform center can be local
-                       copy_v3_v3(cent3d, t->con.center);
+                       copy_v3_v3(cent3d, t->center_global);
                }
        }
 
@@ -2269,7 +2269,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
                return 0;
        }
 
-
        /* overwrite initial values if operator supplied a non-null vector */
        if ((prop = RNA_struct_find_property(op->ptr, "value")) && RNA_property_is_set(op->ptr, prop)) {
                float values[4] = {0}; /* in case value isn't length 4, avoid uninitialized memory  */
@@ -2825,6 +2824,7 @@ static void initBend(TransInfo *t)
 
        //copy_v3_v3(t->center, ED_view3d_cursor3d_get(t->scene, t->view));
        calculateCenterCursor(t, t->center);
+       calculateCenterGlobal(t);
 
        t->val = 0.0f;
 
index af82f416db82a67f68d298ff6f5713e4b22e6e46..8863d337cff2f2163338bfd8ad82443ff13795a2 100644 (file)
@@ -104,8 +104,6 @@ typedef struct TransCon {
        float mtx[3][3];     /* Matrix of the Constraint space                                            */
        float imtx[3][3];    /* Inverse Matrix of the Constraint space                                    */
        float pmtx[3][3];    /* Projection Constraint Matrix (same as imtx with some axis == 0)           */
-       float center[3];     /* transformation center to define where to draw the view widget
-                             * ALWAYS in global space. Unlike the transformation center                  */
        int   imval[2];      /* initial mouse value for visual calculation                                */
                             /* the one in TransInfo is not garanty to stay the same (Rotates change it)  */
        int   mode;          /* Mode flags of the Constraint                                              */
@@ -359,7 +357,8 @@ typedef struct TransInfo {
        char            proptext[20];   /* proportional falloff text                    */
        float       aspect[3];      /* spaces using non 1:1 aspect, (uv's, f-curve, movie-clip... etc)
                                     * use for conversion and snapping. */
-       float       center[3];      /* center of transformation             */
+       float       center[3];      /* center of transformation (in local-space) */
+       float       center_global[3];  /* center of transformation (in global-space) */
        float       center2d[2];    /* center in screen coordinates         */
        int         imval[2];       /* initial mouse position               */
        short           event_type;             /* event->type used to invoke transform */
@@ -694,6 +693,7 @@ void restoreTransObjects(TransInfo *t);
 void recalcData(TransInfo *t);
 
 void calculateCenter2D(TransInfo *t);
+void calculateCenterGlobal(TransInfo *t);
 
 void calculateCenter(TransInfo *t);
 
index 50c255bc9dbd07af404f06c4dfe813c6f01bbe7f..ae5d2c8773982d40cc3142758f75454ca5a714d7 100644 (file)
@@ -203,7 +203,7 @@ static void axisProjection(TransInfo *t, const float axis[3], const float in[3],
                return;
        }
 
-       copy_v3_v3(t_con_center, t->con.center);
+       copy_v3_v3(t_con_center, t->center_global);
 
        /* checks for center being too close to the view center */
        viewAxisCorrectCenter(t, t_con_center);
@@ -277,7 +277,7 @@ static void planeProjection(TransInfo *t, const float in[3], float out[3])
 {
        float vec[3], factor, norm[3];
 
-       add_v3_v3v3(vec, in, t->con.center);
+       add_v3_v3v3(vec, in, t->center_global);
        getViewVector(t, vec, norm);
 
        sub_v3_v3v3(vec, out, in);
@@ -688,11 +688,11 @@ void drawConstraint(TransInfo *t)
                        int depth_test_enabled;
 
                        convertViewVec(t, vec, (t->mval[0] - t->con.imval[0]), (t->mval[1] - t->con.imval[1]));
-                       add_v3_v3(vec, tc->center);
+                       add_v3_v3(vec, t->center_global);
 
-                       drawLine(t, tc->center, tc->mtx[0], 'X', 0);
-                       drawLine(t, tc->center, tc->mtx[1], 'Y', 0);
-                       drawLine(t, tc->center, tc->mtx[2], 'Z', 0);
+                       drawLine(t, t->center_global, tc->mtx[0], 'X', 0);
+                       drawLine(t, t->center_global, tc->mtx[1], 'Y', 0);
+                       drawLine(t, t->center_global, tc->mtx[2], 'Z', 0);
 
                        glColor3ubv((GLubyte *)col2);
 
@@ -702,7 +702,7 @@ void drawConstraint(TransInfo *t)
 
                        setlinestyle(1);
                        glBegin(GL_LINE_STRIP);
-                       glVertex3fv(tc->center);
+                       glVertex3fv(t->center_global);
                        glVertex3fv(vec);
                        glEnd();
                        setlinestyle(0);
@@ -712,13 +712,13 @@ void drawConstraint(TransInfo *t)
                }
 
                if (tc->mode & CON_AXIS0) {
-                       drawLine(t, tc->center, tc->mtx[0], 'X', DRAWLIGHT);
+                       drawLine(t, t->center_global, tc->mtx[0], 'X', DRAWLIGHT);
                }
                if (tc->mode & CON_AXIS1) {
-                       drawLine(t, tc->center, tc->mtx[1], 'Y', DRAWLIGHT);
+                       drawLine(t, t->center_global, tc->mtx[1], 'Y', DRAWLIGHT);
                }
                if (tc->mode & CON_AXIS2) {
-                       drawLine(t, tc->center, tc->mtx[2], 'Z', DRAWLIGHT);
+                       drawLine(t, t->center_global, tc->mtx[2], 'Z', DRAWLIGHT);
                }
        }
 }
@@ -729,7 +729,6 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
        if (t->flag & T_PROP_EDIT) {
                RegionView3D *rv3d = CTX_wm_region_view3d(C);
                float tmat[4][4], imat[4][4];
-               float center[3];
                int depth_test_enabled;
 
                UI_ThemeColor(TH_GRID);
@@ -745,10 +744,8 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
 
                glPushMatrix();
 
-               copy_v3_v3(center, t->center);
-
-               if ((t->spacetype == SPACE_VIEW3D) && t->obedit) {
-                       mul_m4_v3(t->obedit->obmat, center); /* because t->center is in local space */
+               if (t->spacetype == SPACE_VIEW3D) {
+                       /* pass */
                }
                else if (t->spacetype == SPACE_IMAGE) {
                        glScalef(1.0f / t->aspect[0], 1.0f / t->aspect[1], 1.0f);
@@ -769,7 +766,7 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
                        glDisable(GL_DEPTH_TEST);
 
                set_inverted_drawing(1);
-               drawcircball(GL_LINE_LOOP, center, t->prop_size, imat);
+               drawcircball(GL_LINE_LOOP, t->center_global, t->prop_size, imat);
                set_inverted_drawing(0);
 
                if (depth_test_enabled)
@@ -960,7 +957,7 @@ static void setNearestAxis3d(TransInfo *t)
 
                mul_v3_fl(axis, zfac);
                /* now we can project to get window coordinate */
-               add_v3_v3(axis, t->con.center);
+               add_v3_v3(axis, t->center_global);
                projectFloatView(t, axis, axis_2d);
 
                sub_v2_v2v2(axis, axis_2d, t->center2d);
index f958e520c0db890fdbbaf276dda8c94cbd1899a0..90c806a2d05ad00ad9a8651fce42c91c996e67eb 100644 (file)
@@ -1128,6 +1128,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 
        zero_v3(t->vec);
        zero_v3(t->center);
+       zero_v3(t->center_global);
 
        unit_m3(t->mat);
        
@@ -1568,6 +1569,19 @@ void calculateCenter2D(TransInfo *t)
        }
 }
 
+void calculateCenterGlobal(TransInfo *t)
+{
+       /* setting constraint center */
+       /* note, init functions may over-ride t->center */
+       if (t->flag & (T_EDIT | T_POSE)) {
+               Object *ob = t->obedit ? t->obedit : t->poseobj;
+               mul_v3_m4v3(t->center_global, ob->obmat, t->center);
+       }
+       else {
+               copy_v3_v3(t->center_global, t->center);
+       }
+}
+
 void calculateCenterCursor(TransInfo *t, float r_center[3])
 {
        const float *cursor;
@@ -1769,14 +1783,8 @@ void calculateCenter(TransInfo *t)
        }
 
        calculateCenter2D(t);
+       calculateCenterGlobal(t);
 
-       /* setting constraint center */
-       copy_v3_v3(t->con.center, t->center);
-       if (t->flag & (T_EDIT | T_POSE)) {
-               Object *ob = t->obedit ? t->obedit : t->poseobj;
-               mul_m4_v3(ob->obmat, t->con.center);
-       }
-       
        /* for panning from cameraview */
        if (t->flag & T_OBJECT) {
                if (t->spacetype == SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
@@ -1797,7 +1805,7 @@ void calculateCenter(TransInfo *t)
                                /* rotate only needs correct 2d center, grab needs ED_view3d_calc_zfac() value */
                                if (t->mode == TFM_TRANSLATION) {
                                        copy_v3_v3(t->center, axis);
-                                       copy_v3_v3(t->con.center, t->center);
+                                       copy_v3_v3(t->center_global, t->center);
                                }
                        }
                }
index db6620b0d46a0c9cb0120019c981e092b5017af0..8e100b9c92565f0657a7278d8ca58404d42ac5e7 100644 (file)
@@ -841,16 +841,10 @@ static float TranslationBetween(TransInfo *UNUSED(t), const float p1[3], const f
 
 static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3])
 {
-       float angle, start[3], end[3], center[3];
-       
-       copy_v3_v3(center, t->center);
-       if (t->flag & (T_EDIT | T_POSE)) {
-               Object *ob = t->obedit ? t->obedit : t->poseobj;
-               mul_m4_v3(ob->obmat, center);
-       }
+       float angle, start[3], end[3];
 
-       sub_v3_v3v3(start, p1, center);
-       sub_v3_v3v3(end, p2, center);
+       sub_v3_v3v3(start, p1, t->center_global);
+       sub_v3_v3v3(end,   p2, t->center_global);
                
        // Angle around a constraint axis (error prone, will need debug)
        if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) {
@@ -897,16 +891,10 @@ static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3])
 
 static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3])
 {
-       float d1[3], d2[3], center[3], len_d1;
-       
-       copy_v3_v3(center, t->center);
-       if (t->flag & (T_EDIT | T_POSE)) {
-               Object *ob = t->obedit ? t->obedit : t->poseobj;
-               mul_m4_v3(ob->obmat, center);
-       }
+       float d1[3], d2[3], len_d1;
 
-       sub_v3_v3v3(d1, p1, center);
-       sub_v3_v3v3(d2, p2, center);
+       sub_v3_v3v3(d1, p1, t->center_global);
+       sub_v3_v3v3(d2, p2, t->center_global);
        
        if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) {
                mul_m3_v3(t->con.pmtx, d1);
@@ -1112,13 +1100,7 @@ static void TargetSnapCenter(TransInfo *t)
 {
        /* Only need to calculate once */
        if ((t->tsnap.status & TARGET_INIT) == 0) {
-               copy_v3_v3(t->tsnap.snapTarget, t->center);
-               
-               if (t->flag & (T_EDIT | T_POSE)) {
-                       Object *ob = t->obedit ? t->obedit : t->poseobj;
-                       mul_m4_v3(ob->obmat, t->tsnap.snapTarget);
-               }
-               
+               copy_v3_v3(t->tsnap.snapTarget, t->center_global);
                TargetSnapOffset(t, NULL);
                
                t->tsnap.status |= TARGET_INIT;