merge with/from trunk at r35190
[blender.git] / source / blender / editors / transform / transform_constraints.c
index 7f47bfd25afa6ab8d6d835945b8ac5584a7ee078..4427e4724129e02872f8534e573e2415a83c5eff 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
 #include <string.h>
 #include <math.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifndef WIN32
 #include <unistd.h>
 #else
 #include <io.h>
 #endif
 
-#include "MEM_guardedalloc.h"
-
-#include "DNA_action_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_effect_types.h"
-#include "DNA_image_types.h"
-#include "DNA_ipo_types.h"
-#include "DNA_key_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_lattice_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_meta_types.h"
+
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "BIF_glutil.h"
 
 #include "BKE_context.h"
-#include "BKE_global.h"
-#include "BKE_utildefines.h"
+
 
 #include "ED_image.h"
 #include "ED_view3d.h"
 
-#include "BLI_arithb.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
 
 //#include "blendef.h"
 //
 //#include "mydevice.h"
 
-#include "WM_types.h"
 #include "UI_resources.h"
 
 
@@ -88,7 +69,7 @@
 static void drawObjectConstraint(TransInfo *t);
 
 /* ************************** CONSTRAINTS ************************* */
-void constraintAutoValues(TransInfo *t, float vec[3])
+static void constraintAutoValues(TransInfo *t, float vec[3])
 {
        int mode = t->con.mode;
        if (mode & CON_APPLY)
@@ -157,7 +138,7 @@ void constraintNumInput(TransInfo *t, float vec[3])
 static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) {
        int i = 0;
 
-       Mat3MulVecfl(t->con.imtx, vec);
+       mul_m3_v3(t->con.imtx, vec);
 
        snapGrid(t, vec);
 
@@ -174,16 +155,18 @@ static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) {
 
        if (hasNumInput(&t->num)) {
                applyNumInput(&t->num, vec);
+               removeAspectRatio(t, vec);
                constraintNumInput(t, vec);
        }
 
        /* autovalues is operator param, use that directly but not if snapping is forced */
        if (t->flag & T_AUTOVALUES && (t->tsnap.status & SNAP_FORCED) == 0)
        {
-               VECCOPY(vec, t->auto_values);
+               mul_v3_m3v3(vec, t->con.imtx, t->auto_values);
                constraintAutoValues(t, vec);
+               /* inverse transformation at the end */
        }
-       
+
        if (t->con.mode & CON_AXIS0) {
                pvec[i++] = vec[0];
        }
@@ -194,75 +177,95 @@ static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) {
                pvec[i++] = vec[2];
        }
 
-       Mat3MulVecfl(t->con.mtx, vec);
+       mul_m3_v3(t->con.mtx, vec);
 }
 
 static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3]) {
-       float norm[3], vec[3], factor;
-       
+       float norm[3], vec[3], factor, angle;
+
        if(in[0]==0.0f && in[1]==0.0f && in[2]==0.0f)
                return;
-       
+
+       angle = fabs(angle_v3v3(axis, t->viewinv[2]));
+       if (angle > M_PI / 2) {
+               angle = M_PI - angle;
+       }
+       angle = 180.0f * angle / M_PI;
+
        /* For when view is parallel to constraint... will cause NaNs otherwise
           So we take vertical motion in 3D space and apply it to the
           constraint axis. Nice for camera grab + MMB */
-       if(1.0f - fabs(Inpf(axis, t->viewinv[2])) < 0.000001f) {
-               Projf(vec, in, t->viewinv[1]);
-               factor = Inpf(t->viewinv[1], vec) * 2.0f;
+       if(angle < 5.0f) {
+               project_v3_v3v3(vec, in, t->viewinv[1]);
+               factor = dot_v3v3(t->viewinv[1], vec) * 2.0f;
                /* since camera distance is quite relative, use quadratic relationship. holding shift can compensate */
                if(factor<0.0f) factor*= -factor;
                else factor*= factor;
-               
+
                VECCOPY(out, axis);
-               Normalize(out);
-               VecMulf(out, -factor);  /* -factor makes move down going backwards */
+               normalize_v3(out);
+               mul_v3_fl(out, -factor);        /* -factor makes move down going backwards */
        }
        else {
-               float cb[3], ab[3];
-               
-               VECCOPY(out, axis);
-               
-               /* Get view vector on axis to define a plane */
-               VecAddf(vec, t->con.center, in);
-               getViewVector(t, vec, norm);
-               
-               Crossf(vec, norm, axis);
-               
-               /* Project input vector on the plane passing on axis */
-               Projf(vec, in, vec);
-               VecSubf(vec, in, vec);
-               
-               /* intersect the two lines: axis and norm */
-               Crossf(cb, vec, norm);
-               Crossf(ab, axis, norm);
+               float v[3], i1[3], i2[3];
+               float v2[3], v4[3];
+               float norm_center[3];
+               float plane[3];
+
+               getViewVector(t, t->con.center, norm_center);
+               cross_v3_v3v3(plane, norm_center, axis);
+
+               project_v3_v3v3(vec, in, plane);
+               sub_v3_v3v3(vec, in, vec);
                
-               VecMulf(out, Inpf(cb, ab) / Inpf(ab, ab));
+               add_v3_v3v3(v, vec, t->con.center);
+               getViewVector(t, v, norm);
+
+               /* give arbitrary large value if projection is impossible */
+               factor = dot_v3v3(axis, norm);
+               if (1 - fabs(factor) < 0.0002f) {
+                       VECCOPY(out, axis);
+                       if (factor > 0) {
+                               mul_v3_fl(out, 1000000000);
+                       } else {
+                               mul_v3_fl(out, -1000000000);
+       }
+               } else {
+                       add_v3_v3v3(v2, t->con.center, axis);
+                       add_v3_v3v3(v4, v, norm);
+                       
+                       isect_line_line_v3(t->con.center, v2, v, v4, i1, i2);
+                       
+                       sub_v3_v3v3(v, i2, v);
+       
+                       sub_v3_v3v3(out, i1, t->con.center);
+               }
        }
 }
 
 static void planeProjection(TransInfo *t, float in[3], float out[3]) {
        float vec[3], factor, norm[3];
 
-       VecAddf(vec, in, t->con.center);
+       add_v3_v3v3(vec, in, t->con.center);
        getViewVector(t, vec, norm);
 
-       VecSubf(vec, out, in);
+       sub_v3_v3v3(vec, out, in);
 
-       factor = Inpf(vec, norm);
+       factor = dot_v3v3(vec, norm);
        if (fabs(factor) <= 0.001) {
                return; /* prevent divide by zero */
        }
-       factor = Inpf(vec, vec) / factor;
+       factor = dot_v3v3(vec, vec) / factor;
 
        VECCOPY(vec, norm);
-       VecMulf(vec, factor);
+       mul_v3_fl(vec, factor);
 
-       VecAddf(out, in, vec);
+       add_v3_v3v3(out, in, vec);
 }
 
 /*
  * Generic callback for constant spacial constraints applied to linear motion
- * 
+ *
  * The IN vector in projected into the constrained space and then further
  * projected along the view vector.
  * (in perspective mode, the view vector is relative to the position on screen)
@@ -273,10 +276,10 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], flo
 {
        VECCOPY(out, in);
        if (!td && t->con.mode & CON_APPLY) {
-               Mat3MulVecfl(t->con.pmtx, out);
-               
+               mul_m3_v3(t->con.pmtx, out);
+
                // With snap, a projection is alright, no need to correct for view alignment
-               if ((t->tsnap.status & SNAP_ON) == 0) {
+               if (!(t->tsnap.mode != SCE_SNAP_MODE_INCREMENT && activeSnap(t))) {
                        if (getConstraintSpaceDimension(t) == 2) {
                                if (out[0] != 0.0f || out[1] != 0.0f || out[2] != 0.0f) {
                                        planeProjection(t, in, out);
@@ -284,7 +287,7 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], flo
                        }
                        else if (getConstraintSpaceDimension(t) == 1) {
                                float c[3];
-       
+
                                if (t->con.mode & CON_AXIS0) {
                                        VECCOPY(c, t->con.mtx[0]);
                                }
@@ -302,8 +305,8 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], flo
 }
 
 /*
- * Generic callback for object based spacial constraints applied to linear motion
- * 
+ * Generic callback for object based spatial constraints applied to linear motion
+ *
  * At first, the following is applied to the first data in the array
  * The IN vector in projected into the constrained space and then further
  * projected along the view vector.
@@ -317,7 +320,7 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, float in[3], f
        VECCOPY(out, in);
        if (t->con.mode & CON_APPLY) {
                if (!td) {
-                       Mat3MulVecfl(t->con.pmtx, out);
+                       mul_m3_v3(t->con.pmtx, out);
                        if (getConstraintSpaceDimension(t) == 2) {
                                if (out[0] != 0.0f || out[1] != 0.0f || out[2] != 0.0f) {
                                        planeProjection(t, in, out);
@@ -353,14 +356,14 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, float in[3], f
                        if (t->con.mode & CON_AXIS2) {
                                out[2] = in[i++];
                        }
-                       Mat3MulVecfl(td->axismtx, out);
+                       mul_m3_v3(td->axismtx, out);
                }
        }
 }
 
 /*
  * Generic callback for constant spacial constraints applied to resize motion
- * 
+ *
  *
  */
 
@@ -379,14 +382,14 @@ static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3
                        smat[2][2] = 1.0f;
                }
 
-               Mat3MulMat3(tmat, smat, t->con.imtx);
-               Mat3MulMat3(smat, t->con.mtx, tmat);
+               mul_m3_m3m3(tmat, smat, t->con.imtx);
+               mul_m3_m3m3(smat, t->con.mtx, tmat);
        }
 }
 
 /*
  * Callback for object based spacial constraints applied to resize motion
- * 
+ *
  *
  */
 
@@ -396,7 +399,7 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3]
                float tmat[3][3];
                float imat[3][3];
 
-               Mat3Inv(imat, td->axismtx);
+               invert_m3_m3(imat, td->axismtx);
 
                if (!(t->con.mode & CON_AXIS0)) {
                        smat[0][0] = 1.0f;
@@ -408,14 +411,14 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3]
                        smat[2][2] = 1.0f;
                }
 
-               Mat3MulMat3(tmat, smat, imat);
-               Mat3MulMat3(smat, td->axismtx, tmat);
+               mul_m3_m3m3(tmat, smat, imat);
+               mul_m3_m3m3(smat, td->axismtx, tmat);
        }
 }
 
 /*
  * Generic callback for constant spacial constraints applied to rotations
- * 
+ *
  * The rotation axis is copied into VEC.
  *
  * In the case of single axis constraints, the rotation axis is directly the one constrained to.
@@ -448,7 +451,7 @@ static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], fl
                }
                /* don't flip axis if asked to or if num input */
                if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) {
-                       if (Inpf(vec, t->viewinv[2]) > 0.0f) {
+                       if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) {
                                *angle = -(*angle);
                        }
                }
@@ -457,7 +460,7 @@ static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], fl
 
 /*
  * Callback for object based spacial constraints applied to rotations
- * 
+ *
  * The rotation axis is copied into VEC.
  *
  * In the case of single axis constraints, the rotation axis is directly the one constrained to.
@@ -473,7 +476,7 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3],
 {
        if (t->con.mode & CON_APPLY) {
                int mode = t->con.mode & (CON_AXIS0|CON_AXIS1|CON_AXIS2);
-               
+
                /* on setup call, use first object */
                if (td == NULL) {
                        td= t->data;
@@ -494,7 +497,7 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3],
                        break;
                }
                if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) {
-                       if (Inpf(vec, t->viewinv[2]) > 0.0f) {
+                       if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) {
                                *angle = -(*angle);
                        }
                }
@@ -505,7 +508,7 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3],
 
 void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) {
        strncpy(t->con.text + 1, text, 48);
-       Mat3CpyMat3(t->con.mtx, space);
+       copy_m3_m3(t->con.mtx, space);
        t->con.mode = mode;
        getConstraintMatrix(t);
 
@@ -521,7 +524,8 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
 void setLocalConstraint(TransInfo *t, int mode, const char text[]) {
        if (t->flag & T_EDIT) {
                float obmat[3][3];
-               Mat3CpyMat4(obmat, t->scene->obedit->obmat);
+               copy_m3_m4(obmat, t->scene->obedit->obmat);
+               normalize_m3(obmat);
                setConstraint(t, obmat, mode, text);
        }
        else {
@@ -530,7 +534,7 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) {
                }
                else {
                        strncpy(t->con.text + 1, text, 48);
-                       Mat3CpyMat3(t->con.mtx, t->data->axismtx);
+                       copy_m3_m3(t->con.mtx, t->data->axismtx);
                        t->con.mode = mode;
                        getConstraintMatrix(t);
 
@@ -551,16 +555,14 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) {
        ftext is a format string passed to sprintf. It will add the name of
        the orientation where %s is (logically).
 */
-void setUserConstraint(TransInfo *t, int mode, const char ftext[]) {
+void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[]) {
        char text[40];
-       //short twmode= (t->spacetype==SPACE_VIEW3D)? ((View3D*)t->view)->twmode: V3D_MANIP_GLOBAL;
 
-       switch(t->current_orientation) {
+       switch(orientation) {
        case V3D_MANIP_GLOBAL:
                {
-                       float mtx[3][3];
+                       float mtx[3][3]= MAT3_UNITY;
                        sprintf(text, ftext, "global");
-                       Mat3One(mtx);
                        setConstraint(t, mtx, mode, text);
                }
                break;
@@ -576,140 +578,24 @@ void setUserConstraint(TransInfo *t, int mode, const char ftext[]) {
                sprintf(text, ftext, "view");
                setConstraint(t, t->spacemtx, mode, text);
                break;
+       case V3D_MANIP_GIMBAL:
+               sprintf(text, ftext, "gimbal");
+               setConstraint(t, t->spacemtx, mode, text);
+               break;
        default: /* V3D_MANIP_CUSTOM */
                sprintf(text, ftext, t->spacename);
                setConstraint(t, t->spacemtx, mode, text);
                break;
        }
 
-       t->con.mode |= CON_USER;
-}
-
-/*--------------------- EXTERNAL SETUP CALLS ------------------*/
-
-void BIF_setLocalLockConstraint(char axis, char *text) {
-       TransInfo *t = BIF_GetTransInfo();
-
-       if (t->total == 0) {
-               return;
-       }
-       
-       switch (axis) {
-       case 'x':
-               setLocalConstraint(t, (CON_AXIS1|CON_AXIS2), text);
-               break;
-       case 'y':
-               setLocalConstraint(t, (CON_AXIS0|CON_AXIS2), text);
-               break;
-       case 'z':
-               setLocalConstraint(t, (CON_AXIS0|CON_AXIS1), text);
-               break;
-       }
-}
-
-void BIF_setLocalAxisConstraint(char axis, char *text) {
-       TransInfo *t = BIF_GetTransInfo();
-
-       if (t->total == 0) {
-               return;
-       }
-       
-       switch (axis) {
-       case 'X':
-               setLocalConstraint(t, CON_AXIS0, text);
-               break;
-       case 'Y':
-               setLocalConstraint(t, CON_AXIS1, text);
-               break;
-       case 'Z':
-               setLocalConstraint(t, CON_AXIS2, text);
-               break;
-       }
-}
-
-/* text is optional, for header print */
-void BIF_setSingleAxisConstraint(float vec[3], char *text) {
-       TransInfo *t = BIF_GetTransInfo();
-       float space[3][3], v[3];
-       
-       if (t->total == 0) {
-               return;
-       }
-       
-       VECCOPY(space[0], vec);
-
-       v[0] = vec[2];
-       v[1] = vec[0];
-       v[2] = vec[1];
+       t->con.orientation = orientation;
 
-       Crossf(space[1], vec, v);
-       Crossf(space[2], vec, space[1]);
-       Mat3Ortho(space);
-
-       Mat3CpyMat3(t->con.mtx, space);
-       t->con.mode = CON_AXIS0;
-       
-       getConstraintMatrix(t);
-
-       startConstraint(t);
-       
-       /* start copying with an offset of 1, to reserve a spot for the SPACE char */
-       if(text)
-       {
-               strncpy(t->con.text+1, text, 48);       /* 50 in struct */
-       }
-       else
-       {
-               t->con.text[1] = '\0'; /* No text */
-       }
-       
-       t->con.drawExtra = NULL;
-       t->con.applyVec = applyAxisConstraintVec;
-       t->con.applySize = applyAxisConstraintSize;
-       t->con.applyRot = applyAxisConstraintRot;
-       t->redraw = 1;
-}
-
-void BIF_setDualAxisConstraint(float vec1[3], float vec2[3], char *text) {
-       TransInfo *t = BIF_GetTransInfo();
-       float space[3][3];
-       
-       if (t->total == 0) {
-               return;
-       }
-
-       VECCOPY(space[0], vec1);
-       VECCOPY(space[1], vec2);
-       Crossf(space[2], space[0], space[1]);
-       Mat3Ortho(space);
-       
-       Mat3CpyMat3(t->con.mtx, space);
-       t->con.mode = CON_AXIS0|CON_AXIS1;
-
-       getConstraintMatrix(t);
-
-       startConstraint(t);
-       
-       /* start copying with an offset of 1, to reserve a spot for the SPACE char */
-       if(text)
-       {
-               strncpy(t->con.text+1, text, 48);       /* 50 in struct */
-       }
-       else
-       {
-               t->con.text[1] = '\0'; /* No text */
-       }
-
-       t->con.drawExtra = NULL;
-       t->con.applyVec = applyAxisConstraintVec;
-       t->con.applySize = applyAxisConstraintSize;
-       t->con.applyRot = applyAxisConstraintRot;
-       t->redraw = 1;
+       t->con.mode |= CON_USER;
 }
 
 /*----------------- DRAWING CONSTRAINTS -------------------*/
 
-void drawConstraint(const struct bContext *C, TransInfo *t)
+void drawConstraint(TransInfo *t)
 {
        TransCon *tc = &(t->con);
 
@@ -721,10 +607,10 @@ void drawConstraint(const struct bContext *C, TransInfo *t)
                return;
        if (t->flag & T_NO_CONSTRAINT)
                return;
-       
+
        /* nasty exception for Z constraint in camera view */
        // TRANSFORM_FIX_ME
-//     if((t->flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp==V3D_CAMOB) 
+//     if((t->flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp==V3D_CAMOB)
 //             return;
 
        if (tc->drawExtra) {
@@ -734,35 +620,40 @@ void drawConstraint(const struct bContext *C, TransInfo *t)
                if (tc->mode & CON_SELECT) {
                        float vec[3];
                        char col2[3] = {255,255,255};
+                       int depth_test_enabled;
+
                        convertViewVec(t, vec, (short)(t->mval[0] - t->con.imval[0]), (short)(t->mval[1] - t->con.imval[1]));
-                       VecAddf(vec, vec, tc->center);
+                       add_v3_v3(vec, tc->center);
 
-                       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, 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);
 
                        glColor3ubv((GLubyte *)col2);
-                       
-                       glDisable(GL_DEPTH_TEST);
+
+                       depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
+                       if(depth_test_enabled)
+                               glDisable(GL_DEPTH_TEST);
+
                        setlinestyle(1);
-                       glBegin(GL_LINE_STRIP); 
-                               glVertex3fv(tc->center); 
-                               glVertex3fv(vec); 
+                       glBegin(GL_LINE_STRIP);
+                               glVertex3fv(tc->center);
+                               glVertex3fv(vec);
                        glEnd();
                        setlinestyle(0);
-                       // TRANSFORM_FIX_ME
-                       //if(G.vd->zbuf)
-                               glEnable(GL_DEPTH_TEST);        
+
+                       if(depth_test_enabled)
+                               glEnable(GL_DEPTH_TEST);
                }
 
                if (tc->mode & CON_AXIS0) {
-                       drawLine(t, tc->center, tc->mtx[0], 'x', DRAWLIGHT);
+                       drawLine(t, tc->center, tc->mtx[0], 'X', DRAWLIGHT);
                }
                if (tc->mode & CON_AXIS1) {
-                       drawLine(t, tc->center, tc->mtx[1], 'y', DRAWLIGHT);
+                       drawLine(t, tc->center, tc->mtx[1], 'Y', DRAWLIGHT);
                }
                if (tc->mode & CON_AXIS2) {
-                       drawLine(t, tc->center, tc->mtx[2], 'z', DRAWLIGHT);
+                       drawLine(t, tc->center, tc->mtx[2], 'Z', DRAWLIGHT);
                }
        }
 }
@@ -773,25 +664,28 @@ 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];
 
                UI_ThemeColor(TH_GRID);
-               
+
                if(t->spacetype == SPACE_VIEW3D && rv3d != NULL)
                {
-                       Mat4CpyMat4(tmat, rv3d->viewmat);
-                       Mat4Invert(imat, tmat);
+                       copy_m4_m4(tmat, rv3d->viewmat);
+                       invert_m4_m4(imat, tmat);
                }
                else
                {
-                       Mat4One(tmat);
-                       Mat4One(imat);
+                       unit_m4(tmat);
+                       unit_m4(imat);
                }
 
                glPushMatrix();
 
+               VECCOPY(center, t->center);
+
                if((t->spacetype == SPACE_VIEW3D) && t->obedit)
                {
-                       glMultMatrixf(t->obedit->obmat); /* because t->center is in local space */
+                       mul_m4_v3(t->obedit->obmat, center); /* because t->center is in local space */
                }
                else if(t->spacetype == SPACE_IMAGE)
                {
@@ -802,22 +696,11 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
                }
 
                set_inverted_drawing(1);
-               drawcircball(GL_LINE_LOOP, t->center, t->prop_size, imat);
+               drawcircball(GL_LINE_LOOP, center, t->prop_size, imat);
                set_inverted_drawing(0);
-               
-               glPopMatrix();
-       }
-}
-
-void BIF_getPropCenter(float *center)
-{
-       TransInfo *t = BIF_GetTransInfo();
 
-       if (t && t->flag & T_PROP_EDIT) {
-               VECCOPY(center, t->center);
+               glPopMatrix();
        }
-       else
-               center[0] = center[1] = center[2] = 0.0f;
 }
 
 static void drawObjectConstraint(TransInfo *t) {
@@ -831,26 +714,26 @@ static void drawObjectConstraint(TransInfo *t) {
           Without drawing the first light, users have little clue what they are doing.
         */
        if (t->con.mode & CON_AXIS0) {
-               drawLine(t, td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT);
+               drawLine(t, td->ob->obmat[3], td->axismtx[0], 'X', DRAWLIGHT);
        }
        if (t->con.mode & CON_AXIS1) {
-               drawLine(t, td->ob->obmat[3], td->axismtx[1], 'y', DRAWLIGHT);
+               drawLine(t, td->ob->obmat[3], td->axismtx[1], 'Y', DRAWLIGHT);
        }
        if (t->con.mode & CON_AXIS2) {
-               drawLine(t, td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT);
+               drawLine(t, td->ob->obmat[3], td->axismtx[2], 'Z', DRAWLIGHT);
        }
-       
+
        td++;
 
        for(i=1;i<t->total;i++,td++) {
                if (t->con.mode & CON_AXIS0) {
-                       drawLine(t, td->ob->obmat[3], td->axismtx[0], 'x', 0);
+                       drawLine(t, td->ob->obmat[3], td->axismtx[0], 'X', 0);
                }
                if (t->con.mode & CON_AXIS1) {
-                       drawLine(t, td->ob->obmat[3], td->axismtx[1], 'y', 0);
+                       drawLine(t, td->ob->obmat[3], td->axismtx[1], 'Y', 0);
                }
                if (t->con.mode & CON_AXIS2) {
-                       drawLine(t, td->ob->obmat[3], td->axismtx[2], 'z', 0);
+                       drawLine(t, td->ob->obmat[3], td->axismtx[2], 'Z', 0);
                }
        }
 }
@@ -872,8 +755,8 @@ void stopConstraint(TransInfo *t) {
 void getConstraintMatrix(TransInfo *t)
 {
        float mat[3][3];
-       Mat3Inv(t->con.imtx, t->con.mtx);
-       Mat3One(t->con.pmtx);
+       invert_m3_m3(t->con.imtx, t->con.mtx);
+       unit_m3(t->con.pmtx);
 
        if (!(t->con.mode & CON_AXIS0)) {
                t->con.pmtx[0][0]               =
@@ -893,15 +776,15 @@ void getConstraintMatrix(TransInfo *t)
                        t->con.pmtx[2][2]       = 0.0f;
        }
 
-       Mat3MulMat3(mat, t->con.pmtx, t->con.imtx);
-       Mat3MulMat3(t->con.pmtx, t->con.mtx, mat);
+       mul_m3_m3m3(mat, t->con.pmtx, t->con.imtx);
+       mul_m3_m3m3(t->con.pmtx, t->con.mtx, mat);
 }
 
 /*------------------------- MMB Select -------------------------------*/
 
 void initSelectConstraint(TransInfo *t, float mtx[3][3])
 {
-       Mat3CpyMat3(t->con.mtx, mtx);
+       copy_m3_m3(t->con.mtx, mtx);
        t->con.mode |= CON_APPLY;
        t->con.mode |= CON_SELECT;
 
@@ -954,12 +837,12 @@ static void setNearestAxis3d(TransInfo *t)
        float mvec[3], axis[3], proj[3];
        float len[3];
        int i, icoord[2];
-       
+
        /* calculate mouse movement */
        mvec[0] = (float)(t->mval[0] - t->con.imval[0]);
        mvec[1] = (float)(t->mval[1] - t->con.imval[1]);
        mvec[2] = 0.0f;
-       
+
        /* we need to correct axis length for the current zoomlevel of view,
           this to prevent projected values to be clipped behind the camera
           and to overflow the short integers.
@@ -968,24 +851,24 @@ static void setNearestAxis3d(TransInfo *t)
           projecting them with window_to_3d_delta and then get the length of that vector.
        */
        zfac= t->persmat[0][3]*t->center[0]+ t->persmat[1][3]*t->center[1]+ t->persmat[2][3]*t->center[2]+ t->persmat[3][3];
-       zfac = VecLength(t->persinv[0]) * 2.0f/t->ar->winx * zfac * 30.0f;
+       zfac = len_v3(t->persinv[0]) * 2.0f/t->ar->winx * zfac * 30.0f;
 
        for (i = 0; i<3; i++) {
                VECCOPY(axis, t->con.mtx[i]);
-               
-               VecMulf(axis, zfac);
+
+               mul_v3_fl(axis, zfac);
                /* now we can project to get window coordinate */
-               VecAddf(axis, axis, t->con.center);
+               add_v3_v3(axis, t->con.center);
                projectIntView(t, axis, icoord);
-               
+
                axis[0] = (float)(icoord[0] - t->center2d[0]);
                axis[1] = (float)(icoord[1] - t->center2d[1]);
                axis[2] = 0.0f;
 
-               if (Normalize(axis) != 0.0f) {
-                       Projf(proj, mvec, axis);
-                       VecSubf(axis, mvec, proj);
-                       len[i] = Normalize(axis);
+                if (normalize_v3(axis) != 0.0f) {
+                       project_v3_v3v3(proj, mvec, axis);
+                       sub_v3_v3v3(axis, mvec, proj);
+                       len[i] = normalize_v3(axis);
                }
                else {
                        len[i] = 10000000000.0f;
@@ -1034,13 +917,13 @@ void setNearestAxis(TransInfo *t)
        /* constraint setting - depends on spacetype */
        if (t->spacetype == SPACE_VIEW3D) {
                /* 3d-view */
-               setNearestAxis3d(t);    
+               setNearestAxis3d(t);
        }
        else {
                /* assume that this means a 2D-Editor */
                setNearestAxis2d(t);
        }
-       
+
        getConstraintMatrix(t);
 }
 
@@ -1083,7 +966,7 @@ int isLockConstraint(TransInfo *t) {
 
 /*
  * Returns the dimension of the constraint space.
- * 
+ *
  * For that reason, the flags always needs to be set to properly evaluate here,
  * even if they aren't actually used in the callback function. (Which could happen
  * for weird constraints not yet designed. Along a path for example.)
@@ -1107,7 +990,7 @@ int getConstraintSpaceDimension(TransInfo *t)
   Someone willing to do it criptically could do the following instead:
 
   return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2);
-       
+
   Based on the assumptions that the axis flags are one after the other and start at 1
 */
 }