replace VECCOPY and QUATCOPY with inline funcs.
[blender.git] / source / blender / editors / transform / transform.c
index 1796bd4..9c1d5ad 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -1091,7 +1089,7 @@ int calculateTransformCenter(bContext *C, int centerMode, float *vec)
                calculateCenter(t);
 
                // Copy center from constraint center. Transform center can be local
-               VECCOPY(vec, t->con.center);
+               copy_v3_v3(vec, t->con.center);
        }
 
 
@@ -1210,7 +1208,7 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
                mval[0]= x;
                mval[1]= y;
 
-               VECCOPY(vecrot, t->center);
+               copy_v3_v3(vecrot, t->center);
                if(t->flag & T_EDIT) {
                        Object *ob= t->obedit;
                        if(ob) mul_m4_v3(ob->obmat, vecrot);
@@ -1358,6 +1356,11 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        int proportional = 0;
        PropertyRNA *prop;
 
+       // Save back mode in case we're in the generic operator
+       if ((prop= RNA_struct_find_property(op->ptr, "mode"))) {
+               RNA_property_enum_set(op->ptr, prop, t->mode);
+       }
+
        if ((prop= RNA_struct_find_property(op->ptr, "value"))) {
                float *values= (t->flag & T_AUTOVALUES) ? t->auto_values : t->values;
                if (RNA_property_array_check(prop)) {
@@ -1538,10 +1541,11 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                {
                        if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS)
                        {
-                               if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) && event->ctrl) ||
-                                       (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
-                                       (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) && event->alt) ||
-                                       (kmi->type == OSKEY && event->oskey)) {
+                               if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) &&   event->ctrl)  ||
+                                   (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
+                                   (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) &&     event->alt)   ||
+                                   ((kmi->type == OSKEY) &&                         event->oskey) )
+                               {
                                        t->modifiers |= MOD_SNAP_INVERT;
                                }
                                break;
@@ -1686,8 +1690,8 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                        values[0]= RNA_float_get(op->ptr, "value");
                }
 
-               QUATCOPY(t->values, values);
-               QUATCOPY(t->auto_values, values);
+               copy_v4_v4(t->values, values);
+               copy_v4_v4(t->auto_values, values);
                t->flag |= T_AUTOVALUES;
        }
 
@@ -1917,7 +1921,7 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu
                        quat[3]= oldquat[3];
        }
        else {
-               /* quaternions get limited with euler... (compatability mode) */
+               /* quaternions get limited with euler... (compatibility mode) */
                float eul[3], oldeul[3], nquat[4], noldquat[4];
                float qlen;
 
@@ -1963,7 +1967,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
                 *      - current space should be local
                 */
                unit_m4(cob.matrix);
-               VECCOPY(cob.matrix[3], td->loc);
+               copy_v3_v3(cob.matrix[3], td->loc);
                
                /* Evaluate valid constraints */
                for (con= td->con; con; con= con->next) {
@@ -2022,7 +2026,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
                }
                
                /* copy results from cob->matrix */
-               VECCOPY(td->loc, cob.matrix[3]);
+               copy_v3_v3(td->loc, cob.matrix[3]);
        }
 }
 
@@ -2292,8 +2296,8 @@ int Warp(TransInfo *t, const int UNUSED(mval[2]))
         * It needs to be in view space, but we need to take object's offset
         * into account if in Edit mode.
         */
-       VECCOPY(cursor, curs);
-       VECCOPY(gcursor, cursor);
+       copy_v3_v3(cursor, curs);
+       copy_v3_v3(gcursor, cursor);
        if (t->flag & T_EDIT) {
                sub_v3_v3(cursor, t->obedit->obmat[3]);
                sub_v3_v3(gcursor, t->obedit->obmat[3]);
@@ -2336,7 +2340,7 @@ int Warp(TransInfo *t, const int UNUSED(mval[2]))
                        continue;
                
                /* translate point to center, rotate in such a way that outline==distance */
-               VECCOPY(vec, td->iloc);
+               copy_v3_v3(vec, td->iloc);
                mul_m3_v3(td->mtx, vec);
                mul_m4_v3(t->viewmat, vec);
                sub_v3_v3(vec, t->viewmat[3]);
@@ -2601,27 +2605,18 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
        }
        
        /* local constraint shouldn't alter center */
-       if (t->around == V3D_LOCAL) {
-               if (t->flag & T_OBJECT) {
-                       VECCOPY(center, td->center);
-               }
-               else if (t->flag & T_EDIT) {
-                       
-                       if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
-                               VECCOPY(center, td->center);
-                       }
-                       else {
-                               VECCOPY(center, t->center);
-                       }
-               }
-               else {
-                       VECCOPY(center, t->center);
-               }
+       if ((t->around == V3D_LOCAL) &&
+               (   (t->flag & (T_OBJECT|T_POSE)) ||
+                   ((t->flag & T_EDIT) && (t->settings->selectmode & SCE_SELECT_FACE)) ||
+                   (t->obedit && t->obedit->type == OB_ARMATURE))
+               )
+       {
+               copy_v3_v3(center, td->center);
        }
        else {
-               VECCOPY(center, t->center);
+               copy_v3_v3(center, t->center);
        }
-       
+
        if (td->ext) {
                float fsize[3];
                
@@ -2719,10 +2714,10 @@ int Resize(TransInfo *t, const int mval[2])
        
        if (t->flag & T_AUTOVALUES)
        {
-               VECCOPY(size, t->auto_values);
+               copy_v3_v3(size, t->auto_values);
        }
        
-       VECCOPY(t->values, size);
+       copy_v3_v3(t->values, size);
        
        size_to_mat3( mat,size);
        
@@ -2894,19 +2889,17 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
        float vec[3], totmat[3][3], smat[3][3];
        float eul[3], fmat[3][3], quat[4];
        float *center = t->center;
-       
+
        /* local constraint shouldn't alter center */
        if (around == V3D_LOCAL) {
-               if (t->flag & (T_OBJECT|T_POSE)) {
+               if (    (t->flag & (T_OBJECT|T_POSE)) ||
+                       (t->settings->selectmode & SCE_SELECT_FACE) ||
+                       (t->obedit && t->obedit->type == OB_ARMATURE))
+               {
                        center = td->center;
                }
-               else {
-                       if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
-                               center = td->center;
-                       }
-               }
        }
-       
+
        if (t->flag & T_POINTS) {
                mul_m3_m3m3(totmat, mat, td->mtx);
                mul_m3_m3m3(smat, td->smtx, totmat);
@@ -3020,7 +3013,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                mul_m3_m3m3(smat, td->smtx, totmat);
                                
                                /* calculate the total rotatation in eulers */
-                               VECCOPY(eul, td->ext->irot);
+                               copy_v3_v3(eul, td->ext->irot);
                                eulO_to_mat3( eulmat,eul, td->ext->rotOrder);
                                
                                /* mat = transform, obmat = bone rotation */
@@ -3030,7 +3023,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                
                                /* and apply (to end result only) */
                                protectedRotateBits(td->protectflag, eul, td->ext->irot);
-                               VECCOPY(td->ext->rot, eul);
+                               copy_v3_v3(td->ext->rot, eul);
                        }
                        
                        constraintRotLim(t, td);
@@ -3100,7 +3093,7 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                                
                                /* and apply */
                                protectedRotateBits(td->protectflag, eul, td->ext->irot);
-                               VECCOPY(td->ext->rot, eul);
+                               copy_v3_v3(td->ext->rot, eul);
                        }
                        
                        constraintRotLim(t, td);
@@ -3244,8 +3237,8 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2]))
        float mat[3][3], totmat[3][3], smat[3][3];
        float phi[2];
 
-       VECCOPY(axis1, t->persinv[0]);
-       VECCOPY(axis2, t->persinv[1]);
+       copy_v3_v3(axis1, t->persinv[0]);
+       copy_v3_v3(axis2, t->persinv[1]);
        normalize_v3(axis1);
        normalize_v3(axis2);
 
@@ -3296,6 +3289,11 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2]))
 
 void initTranslation(TransInfo *t)
 {
+       if (t->spacetype == SPACE_ACTION) {
+               /* this space uses time translate */
+               t->state = TRANS_CANCEL;
+       }
+
        t->mode = TFM_TRANSLATION;
        t->transform = Translation;
 
@@ -3341,7 +3339,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
        else {
                float dvec[3];
 
-               VECCOPY(dvec, vec);
+               copy_v3_v3(dvec, vec);
                applyAspectRatio(t, dvec);
 
                dist = len_v3(vec);
@@ -3371,10 +3369,10 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
                if(chainlen)
                        sprintf(autoik, "AutoIK-Len: %d", chainlen);
                else
-                       strcpy(autoik, "");
+                       autoik[0]= '\0';
        }
        else
-               strcpy(autoik, "");
+               autoik[0]= '\0';
 
        if (t->con.mode & CON_APPLY) {
                switch(t->num.idx_max) {
@@ -3448,7 +3446,7 @@ static void applyTranslation(TransInfo *t, float vec[3]) {
                        t->con.applyVec(t, td, vec, tvec, pvec);
                }
                else {
-                       VECCOPY(tvec, vec);
+                       copy_v3_v3(tvec, vec);
                }
                
                mul_m3_v3(td->smtx, tvec);
@@ -3475,7 +3473,7 @@ int Translation(TransInfo *t, const int UNUSED(mval[2]))
                }
                applySnapping(t, t->values);
                t->con.applyVec(t, NULL, t->values, tvec, pvec);
-               VECCOPY(t->values, tvec);
+               copy_v3_v3(t->values, tvec);
                headerTranslation(t, pvec, str);
        }
        else {
@@ -3564,7 +3562,7 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
                if (td->flag & TD_SKIP)
                        continue;
 
-               VECCOPY(vec, td->axismtx[2]);
+               copy_v3_v3(vec, td->axismtx[2]);
                mul_v3_fl(vec, distance);
                mul_v3_fl(vec, td->factor);
 
@@ -4260,7 +4258,6 @@ static int createSlideVerts(TransInfo *t)
        LinkNode *edgelist = NULL, *vertlist=NULL, *look;
        GHash *vertgh;
        TransDataSlideVert *tempsv;
-       float vertdist; // XXX, projectMat[4][4];
        int i, j, numsel, numadded=0, timesthrough = 0, vertsel=0;
        /* UV correction vars */
        GHash **uvarray= NULL;
@@ -4525,7 +4522,6 @@ static int createSlideVerts(TransInfo *t)
 
        look = vertlist;
        nearest = NULL;
-       vertdist = -1;
        while(look) {
                tempsv  = BLI_ghash_lookup(vertgh,(EditVert*)look->link);
 
@@ -4608,7 +4604,7 @@ static int createSlideVerts(TransInfo *t)
 
        add_v3_v3(start, end);
        mul_v3_fl(start, 0.5f*(1.0f/totvec));
-       VECCOPY(vec, start);
+       copy_v3_v3(vec, start);
        start[0] = t->mval[0];
        start[1] = t->mval[1];
        add_v3_v3v3(end, start, vec);
@@ -5215,7 +5211,7 @@ int Align(TransInfo *t, const int UNUSED(mval[2]))
        int i;
 
        /* saving original center */
-       VECCOPY(center, t->center);
+       copy_v3_v3(center, t->center);
 
        for(i = 0 ; i < t->total; i++, td++)
        {
@@ -5229,11 +5225,11 @@ int Align(TransInfo *t, const int UNUSED(mval[2]))
 
                /* around local centers */
                if (t->flag & (T_OBJECT|T_POSE)) {
-                       VECCOPY(t->center, td->center);
+                       copy_v3_v3(t->center, td->center);
                }
                else {
                        if(t->settings->selectmode & SCE_SELECT_FACE) {
-                               VECCOPY(t->center, td->center);
+                               copy_v3_v3(t->center, td->center);
                        }
                }
 
@@ -5245,7 +5241,7 @@ int Align(TransInfo *t, const int UNUSED(mval[2]))
        }
 
        /* restoring original center */
-       VECCOPY(t->center, center);
+       copy_v3_v3(t->center, center);
 
        recalcData(t);
 
@@ -5317,7 +5313,7 @@ int SeqSlide(TransInfo *t, const int UNUSED(mval[2]))
                float pvec[3] = {0.0f, 0.0f, 0.0f};
                float tvec[3];
                t->con.applyVec(t, NULL, t->values, tvec, pvec);
-               VECCOPY(t->values, tvec);
+               copy_v3_v3(t->values, tvec);
        }
        else {
                snapGrid(t, t->values);
@@ -5423,9 +5419,13 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d,
 {
        /* snap key to nearest frame? */
        if (autosnap == SACTSNAP_FRAME) {
+
+#if 0   /* 'doTime' disabled for now */
+
                const Scene *scene= t->scene;
                const short doTime= 0; //getAnimEdit_DrawTime(t); // NOTE: this works, but may be confusing behaviour given the option's label, hence disabled
                const double secf= FPS;
+#endif
                double val;
                
                /* convert frame to nla-action time (if needed) */
@@ -5434,11 +5434,17 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d,
                else
                        val= *(td->val);
                
+#if 0  /* 'doTime' disabled for now */
+
                /* do the snapping to nearest frame/second */
-               if (doTime)
+               if (doTime) {
                        val= (float)( floor((val/secf) + 0.5f) * secf );
+               }
                else
+#endif
+               {
                        val= (float)( floor(val+0.5f) );
+               }
                
                /* convert frame out of nla-action time */
                if (adt)
@@ -5553,7 +5559,7 @@ static void applyTimeTranslate(TransInfo *t, float UNUSED(sval))
 
        const short autosnap= getAnimEdit_SnapMode(t);
 
-       float deltax, val, valprev;
+       float deltax, val /* , valprev */;
 
        /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */
        for (i = 0 ; i < t->total; i++, td++, td2d++) {
@@ -5563,7 +5569,7 @@ static void applyTimeTranslate(TransInfo *t, float UNUSED(sval))
                 */
                AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL;
 
-               valprev = *td->val;
+               /* valprev = *td->val; */ /* UNUSED */
 
                /* check if any need to apply nla-mapping */
                if (adt && t->spacetype != SPACE_SEQ) {