Merging r40265 through r40492 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / transform / transform_conversions.c
index 4a292d753523d3a7573521998fc677aacdb215fb..d02be58ba7eda620817506ccf7dba895dc8e24fc 100644 (file)
@@ -79,6 +79,7 @@
 #include "BKE_report.h"
 #include "BKE_tracking.h"
 #include "BKE_movieclip.h"
+#include "BKE_node.h"
 
 
 #include "ED_anim_api.h"
 #include "ED_object.h"
 #include "ED_markers.h"
 #include "ED_mesh.h"
+#include "ED_node.h"
 #include "ED_types.h"
 #include "ED_uvedit.h"
 #include "ED_clip.h"
-#include "ED_curve.h" /* for ED_curve_editnurbs */
 #include "ED_util.h"  /* for crazyspace correction */
 
+#include "WM_api.h"            /* for WM_event_add_notifier to deal with stabilization nodes */
+#include "WM_types.h"
+
 #include "UI_view2d.h"
 
 #include "BLI_math.h"
@@ -272,7 +276,7 @@ static void createTransTexspace(TransInfo *t)
        td->ext= t->ext= MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
 
        td->flag= TD_SELECTED;
-       VECCOPY(td->center, ob->obmat[3]);
+       copy_v3_v3(td->center, ob->obmat[3]);
        td->ob = ob;
 
        copy_m3_m4(td->mtx, ob->obmat);
@@ -285,9 +289,9 @@ static void createTransTexspace(TransInfo *t)
                *texflag &= ~AUTOSPACE;
        }
 
-       VECCOPY(td->iloc, td->loc);
-       VECCOPY(td->ext->irot, td->ext->rot);
-       VECCOPY(td->ext->isize, td->ext->size);
+       copy_v3_v3(td->iloc, td->loc);
+       copy_v3_v3(td->ext->irot, td->ext->rot);
+       copy_v3_v3(td->ext->isize, td->ext->size);
 }
 
 /* ********************* edge (for crease) ***** */
@@ -423,7 +427,7 @@ static short apply_targetless_ik(Object *ob)
                                        copy_m4_m3(offs_bone, bone->bone_mat);
 
                                        /* The bone's root offset (is in the parent's coordinate system) */
-                                       VECCOPY(offs_bone[3], bone->head);
+                                       copy_v3_v3(offs_bone[3], bone->head);
 
                                        /* Get the length translation of parent (length along y axis) */
                                        offs_bone[3][1]+= parbone->length;
@@ -434,7 +438,7 @@ static short apply_targetless_ik(Object *ob)
                                                copy_m4_m4(rmat, parbone->arm_mat);     /* rmat used as temp */
 
                                                /* the location of actual parent transform */
-                                               VECCOPY(rmat[3], offs_bone[3]);
+                                               copy_v3_v3(rmat[3], offs_bone[3]);
                                                offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f;
                                                mul_m4_v3(parchan->parent->pose_mat, rmat[3]);
 
@@ -452,7 +456,7 @@ static short apply_targetless_ik(Object *ob)
                                else {
                                        copy_m4_m3(tmat, bone->bone_mat);
 
-                                       VECCOPY(tmat[3], bone->head);
+                                       copy_v3_v3(tmat[3], bone->head);
                                        invert_m4_m4(imat, tmat);
                                }
                                /* result matrix */
@@ -494,7 +498,7 @@ static short apply_targetless_ik(Object *ob)
                                        
                                        /* causes problems with some constraints (e.g. childof), so disable this */
                                        /* as it is IK shouldn't affect location directly */
-                                       /* VECCOPY(parchan->loc, rmat[3]); */
+                                       /* copy_v3_v3(parchan->loc, rmat[3]); */
                                }
 
                        }
@@ -514,8 +518,8 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
        float cmat[3][3], tmat[3][3];
        float vec[3];
 
-       VECCOPY(vec, pchan->pose_mat[3]);
-       VECCOPY(td->center, vec);
+       copy_v3_v3(vec, pchan->pose_mat[3]);
+       copy_v3_v3(td->center, vec);
 
        td->ob = ob;
        td->flag = TD_SELECTED;
@@ -533,10 +537,10 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
        td->protectflag= pchan->protectflag;
 
        td->loc = pchan->loc;
-       VECCOPY(td->iloc, pchan->loc);
+       copy_v3_v3(td->iloc, pchan->loc);
 
        td->ext->size= pchan->size;
-       VECCOPY(td->ext->isize, pchan->size);
+       copy_v3_v3(td->ext->isize, pchan->size);
 
        if (pchan->rotmode > 0) {
                td->ext->rot= pchan->eul;
@@ -544,7 +548,7 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
                td->ext->rotAngle= NULL;
                td->ext->quat= NULL;
                
-               VECCOPY(td->ext->irot, pchan->eul);
+               copy_v3_v3(td->ext->irot, pchan->eul);
        }
        else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
                td->ext->rot= NULL;
@@ -553,7 +557,7 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
                td->ext->quat= NULL;
                
                td->ext->irotAngle= pchan->rotAngle;
-               VECCOPY(td->ext->irotAxis, pchan->rotAxis);
+               copy_v3_v3(td->ext->irotAxis, pchan->rotAxis);
        }
        else {
                td->ext->rot= NULL;
@@ -629,7 +633,7 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
                else {
                        // abusive storage of scale in the loc pointer :)
                        td->loc= &bone->xwidth;
-                       VECCOPY (td->iloc, td->loc);
+                       copy_v3_v3(td->iloc, td->loc);
                        td->val= NULL;
                }
        }
@@ -639,13 +643,13 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
                bKinematicConstraint *data= has_targetless_ik(pchan);
                if(data) {
                        if(data->flag & CONSTRAINT_IK_TIP) {
-                               VECCOPY(data->grabtarget, pchan->pose_tail);
+                               copy_v3_v3(data->grabtarget, pchan->pose_tail);
                        }
                        else {
-                               VECCOPY(data->grabtarget, pchan->pose_head);
+                               copy_v3_v3(data->grabtarget, pchan->pose_head);
                        }
                        td->loc = data->grabtarget;
-                       VECCOPY(td->iloc, td->loc);
+                       copy_v3_v3(td->iloc, td->loc);
                        data->flag |= CONSTRAINT_IK_AUTO;
 
                        /* only object matrix correction */
@@ -888,7 +892,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan)
        else
                data->flag= CONSTRAINT_IK_TIP;
        data->flag |= CONSTRAINT_IK_TEMP|CONSTRAINT_IK_AUTO;
-       VECCOPY(data->grabtarget, pchan->pose_tail);
+       copy_v3_v3(data->grabtarget, pchan->pose_tail);
        data->rootbone= 0; /* watch-it! has to be 0 here, since we're still on the same bone for the first time through the loop [#25885] */
        
        /* we only include bones that are part of a continual connected chain */
@@ -1004,7 +1008,7 @@ static void createTransPose(TransInfo *t, Object *ob)
        if (arm->flag & ARM_RESTPOS) {
                if (ELEM(t->mode, TFM_DUMMY, TFM_BONESIZE)==0) {
                        // XXX use transform operator reports
-                       // BKE_report(op->reports, RPT_ERROR, "Can't select linked when sync selection is enabled.");
+                       // BKE_report(op->reports, RPT_ERROR, "Can't select linked when sync selection is enabled");
                        return;
                }
        }
@@ -1042,7 +1046,7 @@ static void createTransPose(TransInfo *t, Object *ob)
 
        if(td != (t->data+t->total)) {
                // XXX use transform operator reports
-               // BKE_report(op->reports, RPT_DEBUG, "Bone selection count error.");
+               // BKE_report(op->reports, RPT_DEBUG, "Bone selection count error");
        }
 
        /* initialise initial auto=ik chainlen's? */
@@ -1112,7 +1116,7 @@ static void createTransArmatureVerts(TransInfo *t)
                                        td->val= &ebo->rad_head;
                                        td->ival= *td->val;
 
-                                       VECCOPY (td->center, ebo->head);
+                                       copy_v3_v3(td->center, ebo->head);
                                        td->flag= TD_SELECTED;
 
                                        copy_m3_m3(td->smtx, smtx);
@@ -1128,7 +1132,7 @@ static void createTransArmatureVerts(TransInfo *t)
                                {
                                        td->val= &ebo->rad_tail;
                                        td->ival= *td->val;
-                                       VECCOPY (td->center, ebo->tail);
+                                       copy_v3_v3(td->center, ebo->tail);
                                        td->flag= TD_SELECTED;
 
                                        copy_m3_m3(td->smtx, smtx);
@@ -1155,10 +1159,10 @@ static void createTransArmatureVerts(TransInfo *t)
                                        {
                                                // abusive storage of scale in the loc pointer :)
                                                td->loc= &ebo->xwidth;
-                                               VECCOPY (td->iloc, td->loc);
+                                               copy_v3_v3(td->iloc, td->loc);
                                                td->val= NULL;
                                        }
-                                       VECCOPY (td->center, ebo->head);
+                                       copy_v3_v3(td->center, ebo->head);
                                        td->flag= TD_SELECTED;
 
                                        /* use local bone matrix */
@@ -1184,7 +1188,7 @@ static void createTransArmatureVerts(TransInfo *t)
                                        td->val= &(ebo->roll);
                                        td->ival= ebo->roll;
 
-                                       VECCOPY (td->center, ebo->head);
+                                       copy_v3_v3(td->center, ebo->head);
                                        td->flag= TD_SELECTED;
 
                                        td->ext = NULL;
@@ -1197,8 +1201,8 @@ static void createTransArmatureVerts(TransInfo *t)
                        {
                                if (ebo->flag & BONE_TIPSEL)
                                {
-                                       VECCOPY (td->iloc, ebo->tail);
-                                       VECCOPY (td->center, td->iloc);
+                                       copy_v3_v3(td->iloc, ebo->tail);
+                                       copy_v3_v3(td->center, td->iloc);
                                        td->loc= ebo->tail;
                                        td->flag= TD_SELECTED;
                                        if (ebo->flag & BONE_EDITMODE_LOCKED)
@@ -1223,8 +1227,8 @@ static void createTransArmatureVerts(TransInfo *t)
                                }
                                if (ebo->flag & BONE_ROOTSEL)
                                {
-                                       VECCOPY (td->iloc, ebo->head);
-                                       VECCOPY (td->center, td->iloc);
+                                       copy_v3_v3(td->iloc, ebo->head);
+                                       copy_v3_v3(td->center, td->iloc);
                                        td->loc= ebo->head;
                                        td->flag= TD_SELECTED;
                                        if (ebo->flag & BONE_EDITMODE_LOCKED)
@@ -1282,8 +1286,8 @@ static void createTransMBallVerts(TransInfo *t)
        for(ml= mb->editelems->first; ml; ml= ml->next) {
                if(propmode || (ml->flag & SELECT)) {
                        td->loc= &ml->x;
-                       VECCOPY(td->iloc, td->loc);
-                       VECCOPY(td->center, td->loc);
+                       copy_v3_v3(td->iloc, td->loc);
+                       copy_v3_v3(td->center, td->loc);
 
                        if(ml->flag & SELECT) td->flag= TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE;
                        else td->flag= TD_USEQUAT;
@@ -1398,7 +1402,7 @@ static void createTransCurveVerts(bContext *C, TransInfo *t)
        if(cu->editnurb==NULL) return;
 
        /* count total of vertices, check identical as in 2nd loop for making transdata! */
-       nurbs= ED_curve_editnurbs(cu);
+       nurbs= curve_editnurbs(cu);
        for(nu= nurbs->first; nu; nu= nu->next) {
                if(nu->type == CU_BEZIER) {
                        for(a=0, bezt= nu->bezt; a<nu->pntsu; a++, bezt++) {
@@ -1447,9 +1451,9 @@ static void createTransCurveVerts(bContext *C, TransInfo *t)
                                                        ((bezt->f2 & SELECT) && hide_handles) ||
                                                        ((bezt->f1 & SELECT) && hide_handles == 0)
                                          ) {
-                                               VECCOPY(td->iloc, bezt->vec[0]);
+                                               copy_v3_v3(td->iloc, bezt->vec[0]);
                                                td->loc= bezt->vec[0];
-                                               VECCOPY(td->center, bezt->vec[(hide_handles || bezt->f2 & SELECT) ? 1:0]);
+                                               copy_v3_v3(td->center, bezt->vec[(hide_handles || bezt->f2 & SELECT) ? 1:0]);
                                                if (hide_handles) {
                                                        if(bezt->f2 & SELECT) td->flag= TD_SELECTED;
                                                        else td->flag= 0;
@@ -1472,9 +1476,9 @@ static void createTransCurveVerts(bContext *C, TransInfo *t)
 
                                        /* This is the Curve Point, the other two are handles */
                                        if(propmode || (bezt->f2 & SELECT)) {
-                                               VECCOPY(td->iloc, bezt->vec[1]);
+                                               copy_v3_v3(td->iloc, bezt->vec[1]);
                                                td->loc= bezt->vec[1];
-                                               VECCOPY(td->center, td->loc);
+                                               copy_v3_v3(td->center, td->loc);
                                                if(bezt->f2 & SELECT) td->flag= TD_SELECTED;
                                                else td->flag= 0;
                                                td->ext = NULL;
@@ -1506,9 +1510,9 @@ static void createTransCurveVerts(bContext *C, TransInfo *t)
                                                        ((bezt->f2 & SELECT) && hide_handles) ||
                                                        ((bezt->f3 & SELECT) && hide_handles == 0)
                                          ) {
-                                               VECCOPY(td->iloc, bezt->vec[2]);
+                                               copy_v3_v3(td->iloc, bezt->vec[2]);
                                                td->loc= bezt->vec[2];
-                                               VECCOPY(td->center, bezt->vec[(hide_handles || bezt->f2 & SELECT) ? 1:2]);
+                                               copy_v3_v3(td->center, bezt->vec[(hide_handles || bezt->f2 & SELECT) ? 1:2]);
                                                if (hide_handles) {
                                                        if(bezt->f2 & SELECT) td->flag= TD_SELECTED;
                                                        else td->flag= 0;
@@ -1550,9 +1554,9 @@ static void createTransCurveVerts(bContext *C, TransInfo *t)
                        for(a= nu->pntsu*nu->pntsv, bp= nu->bp; a>0; a--, bp++) {
                                if(bp->hide==0) {
                                        if(propmode || (bp->f1 & SELECT)) {
-                                               VECCOPY(td->iloc, bp->vec);
+                                               copy_v3_v3(td->iloc, bp->vec);
                                                td->loc= bp->vec;
-                                               VECCOPY(td->center, td->loc);
+                                               copy_v3_v3(td->center, td->loc);
                                                if(bp->f1 & SELECT) td->flag= TD_SELECTED;
                                                else td->flag= 0;
                                                td->ext = NULL;
@@ -1622,9 +1626,9 @@ static void createTransLatticeVerts(TransInfo *t)
        while(a--) {
                if(propmode || (bp->f1 & SELECT)) {
                        if(bp->hide==0) {
-                               VECCOPY(td->iloc, bp->vec);
+                               copy_v3_v3(td->iloc, bp->vec);
                                td->loc= bp->vec;
-                               VECCOPY(td->center, td->loc);
+                               copy_v3_v3(td->center, td->loc);
                                if(bp->f1 & SELECT) td->flag= TD_SELECTED;
                                else td->flag= 0;
                                copy_m3_m3(td->smtx, smtx);
@@ -1717,15 +1721,15 @@ static void createTransParticleVerts(bContext *C, TransInfo *t)
 
                for(k=0, key=point->keys; k<point->totkey; k++, key++) {
                        if(key->flag & PEK_USE_WCO) {
-                               VECCOPY(key->world_co, key->co);
+                               copy_v3_v3(key->world_co, key->co);
                                mul_m4_v3(mat, key->world_co);
                                td->loc = key->world_co;
                        }
                        else
                                td->loc = key->co;
 
-                       VECCOPY(td->iloc, td->loc);
-                       VECCOPY(td->center, td->loc);
+                       copy_v3_v3(td->iloc, td->loc);
+                       copy_v3_v3(td->center, td->loc);
 
                        if(key->flag & PEK_SELECT)
                                td->flag |= TD_SELECTED;
@@ -1790,13 +1794,13 @@ void flushTransParticles(TransInfo *t)
                        invert_m4_m4(imat,mat);
 
                        for(k=0, key=point->keys; k<point->totkey; k++, key++) {
-                               VECCOPY(co, key->world_co);
+                               copy_v3_v3(co, key->world_co);
                                mul_m4_v3(imat, co);
 
 
                                /* optimization for proportional edit */
                                if(!propmode || !compare_v3v3(key->co, co, 0.0001f)) {
-                                       VECCOPY(key->co, co);
+                                       copy_v3_v3(key->co, co);
                                        point->flag |= PEP_EDIT_RECALC;
                                }
                        }
@@ -1811,7 +1815,7 @@ void flushTransParticles(TransInfo *t)
 /* ********************* mesh ****************** */
 
 /* proportional distance based on connectivity  */
-#define THRESHOLD      0.0001f
+#define THRESHOLDFACTOR (1.0f-0.0001f)
 
 static int connectivity_edge(float mtx[][3], EditVert *v1, EditVert *v2)
 {
@@ -1832,10 +1836,10 @@ static int connectivity_edge(float mtx[][3], EditVert *v1, EditVert *v2)
 
        if (v1->f2) {
                if (v2->f2) {
-                       if (v2->tmp.fp + edge_len + THRESHOLD < v1->tmp.fp) {
+                       if (v2->tmp.fp + edge_len < THRESHOLDFACTOR * v1->tmp.fp) {
                                v1->tmp.fp = v2->tmp.fp + edge_len;
                                done = 1;
-                       } else if (v1->tmp.fp + edge_len + THRESHOLD < v2->tmp.fp) {
+                       } else if (v1->tmp.fp + edge_len < THRESHOLDFACTOR * v2->tmp.fp) {
                                v2->tmp.fp = v1->tmp.fp + edge_len;
                                done = 1;
                        }
@@ -1913,7 +1917,7 @@ static void get_face_center(float *cent, EditMesh *em, EditVert *eve)
                        if(efa->v1==eve || efa->v2==eve || efa->v3==eve || efa->v4==eve)
                                break;
        if(efa) {
-               VECCOPY(cent, efa->cent);
+               copy_v3_v3(cent, efa->cent);
        }
 }
 
@@ -1927,13 +1931,13 @@ static void VertsToTransData(TransInfo *t, TransData *td, EditMesh *em, EditVert
        //else
        td->loc = eve->co;
 
-       VECCOPY(td->center, td->loc);
+       copy_v3_v3(td->center, td->loc);
        if(t->around==V3D_LOCAL && (em->selectmode & SCE_SELECT_FACE))
                get_face_center(td->center, em, eve);
-       VECCOPY(td->iloc, td->loc);
+       copy_v3_v3(td->iloc, td->loc);
 
        // Setting normals
-       VECCOPY(td->axismtx[2], eve->no);
+       copy_v3_v3(td->axismtx[2], eve->no);
        td->axismtx[0][0]               =
                td->axismtx[0][1]       =
                td->axismtx[0][2]       =
@@ -1963,9 +1967,9 @@ static void createTransBMeshVerts(TransInfo *t, BME_Mesh *bm, BME_TransData_Head
                if ( (vtd = BME_get_transdata(td,v)) ) {
                        tob->loc = vtd->loc;
                        tob->val = &vtd->factor;
-                       VECCOPY(tob->iloc,vtd->co);
-                       VECCOPY(tob->center,vtd->org);
-                       VECCOPY(tob->axismtx[0],vtd->vec);
+                       copy_v3_v3(tob->iloc,vtd->co);
+                       copy_v3_v3(tob->center,vtd->org);
+                       copy_v3_v3(tob->axismtx[0],vtd->vec);
                        tob->axismtx[1][0] = vtd->max ? *vtd->max : 0;
                        tob++;
                        i++;
@@ -1987,7 +1991,7 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
        float *mappedcos = NULL, *quats= NULL;
        float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL;
        int count=0, countsel=0, a, totleft;
-       int propmode = t->flag & T_PROP_EDIT;
+       int propmode = (t->flag & T_PROP_EDIT) ? (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) : 0;
        int mirror = 0;
        short selectmode = ts->selectmode;
 
@@ -2057,7 +2061,9 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
        copy_m3_m4(mtx, t->obedit->obmat);
        invert_m3_m3(smtx, mtx);
 
-       if(propmode) editmesh_set_connectivity_distance(em, mtx);
+       if(propmode & T_PROP_CONNECTED) {
+               editmesh_set_connectivity_distance(em, mtx);
+       }
 
        /* detect CrazySpace [tm] */
        if(modifiers_getCageIndex(t->scene, t->obedit, NULL, 1)>=0) {
@@ -2186,6 +2192,12 @@ void flushTransNodes(TransInfo *t)
                td->loc2d[0]= td->loc[0];
                td->loc2d[1]= td->loc[1];
        }
+       
+       /* handle intersection with noodles */
+       if(t->total==1) {
+               ED_node_link_intersect_test(t->sa, 1);
+       }
+       
 }
 
 /* *** SEQUENCE EDITOR *** */
@@ -2302,8 +2314,8 @@ static void UVsToTransData(SpaceImage *sima, TransData *td, TransData2D *td2d, f
 
        td->flag = 0;
        td->loc = td2d->loc;
-       VECCOPY(td->center, td->loc);
-       VECCOPY(td->iloc, td->loc);
+       copy_v3_v3(td->center, td->loc);
+       copy_v3_v3(td->iloc, td->loc);
 
        memset(td->axismtx, 0, sizeof(td->axismtx));
        td->axismtx[2][2] = 1.0f;
@@ -2483,6 +2495,7 @@ static short FrameOnMouseSide(char side, float frame, float cframe)
 static void createTransNlaData(bContext *C, TransInfo *t)
 {
        Scene *scene= t->scene;
+       SpaceNla *snla = NULL;
        TransData *td = NULL;
        TransDataNla *tdn = NULL;
        
@@ -2496,9 +2509,10 @@ static void createTransNlaData(bContext *C, TransInfo *t)
        /* determine what type of data we are operating on */
        if (ANIM_animdata_get_context(C, &ac) == 0)
                return;
+       snla = (SpaceNla *)ac.sl;
        
        /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT);
+       filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
        
        /* which side of the current frame should be allowed */
@@ -2581,7 +2595,7 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                                                tdn->strip= strip;
                                                tdn->trackIndex= BLI_findindex(&adt->nla_tracks, nlt);
                                                
-                                               yval= (float)(tdn->trackIndex * NLACHANNEL_STEP);
+                                               yval= (float)(tdn->trackIndex * NLACHANNEL_STEP(snla));
                                                
                                                tdn->h1[0]= strip->start;
                                                tdn->h1[1]= yval;
@@ -2601,10 +2615,10 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                                                        /* now, link the transform data up to this data */
                                                        if (ELEM(t->mode, TFM_TRANSLATION, TFM_TIME_EXTEND)) {
                                                                td->loc= tdn->h1;
-                                                               VECCOPY(td->iloc, tdn->h1);
+                                                               copy_v3_v3(td->iloc, tdn->h1);
                                                                
                                                                /* store all the other gunk that is required by transform */
-                                                               VECCOPY(td->center, center);
+                                                               copy_v3_v3(td->center, center);
                                                                memset(td->axismtx, 0, sizeof(td->axismtx));
                                                                td->axismtx[2][2] = 1.0f;
                                                                
@@ -2633,10 +2647,10 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                                                        /* now, link the transform data up to this data */
                                                        if (ELEM(t->mode, TFM_TRANSLATION, TFM_TIME_EXTEND)) {
                                                                td->loc= tdn->h2;
-                                                               VECCOPY(td->iloc, tdn->h2);
+                                                               copy_v3_v3(td->iloc, tdn->h2);
                                                                
                                                                /* store all the other gunk that is required by transform */
-                                                               VECCOPY(td->center, center);
+                                                               copy_v3_v3(td->center, center);
                                                                memset(td->axismtx, 0, sizeof(td->axismtx));
                                                                td->axismtx[2][2] = 1.0f;
                                                                
@@ -2685,7 +2699,7 @@ static void createTransNlaData(bContext *C, TransInfo *t)
 static void posttrans_gpd_clean (bGPdata *gpd)
 {
        bGPDlayer *gpl;
-
+       
        for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
                ListBase sel_buffer = {NULL, NULL};
                bGPDframe *gpf, *gpfn;
@@ -2838,7 +2852,7 @@ static void posttrans_action_clean (bAnimContext *ac, bAction *act)
        int filter;
 
        /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+       filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/);
        ANIM_animdata_filter(ac, &anim_data, filter, act, ANIMCONT_ACTION);
 
        /* loop through relevant data, removing keyframes as appropriate
@@ -2846,7 +2860,7 @@ static void posttrans_action_clean (bAnimContext *ac, bAction *act)
         */
        for (ale= anim_data.first; ale; ale= ale->next) {
                AnimData *adt= ANIM_nla_mapping_get(ac, ale);
-
+               
                if (adt) {
                        ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
                        posttrans_fcurve_clean(ale->key_data);
@@ -3040,9 +3054,9 @@ static void createTransActionData(bContext *C, TransInfo *t)
        
        /* filter data */
        if (ac.datatype == ANIMCONT_GPENCIL)
-               filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT);
+               filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT);
        else
-               filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+               filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
        
        /* which side of the current frame should be allowed */
@@ -3135,12 +3149,18 @@ static void createTransActionData(bContext *C, TransInfo *t)
                float min=999999999.0f, max=-999999999.0f;
                int i;
                
-               td= (t->data + 1);
-               for (i=1; i < count; i+=3, td+=3) {
+               td= t->data;
+               for (i=0; i < count; i++, td++) {
                        if (min > *(td->val)) min= *(td->val);
                        if (max < *(td->val)) max= *(td->val);
                }
                
+               if (min == max) {
+                       /* just use the current frame ranges */
+                       min = (float)PSFRA;
+                       max = (float)PEFRA;
+               }
+               
                /* minx/maxx values used by TimeSlide are stored as a
                 * calloced 2-float array in t->customData. This gets freed
                 * in postTrans (T_FREE_CUSTOMDATA).
@@ -3183,7 +3203,7 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, AnimData *adt,
                td->center[1] = cent[1];
                td->center[2] = 0.0f;
                
-               VECCOPY(td->iloc, td->loc);
+               copy_v3_v3(td->iloc, td->loc);
        }
        else {
                td2d->loc[0] = loc[0];
@@ -3192,8 +3212,8 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, AnimData *adt,
                td2d->loc2d = loc;
                
                td->loc = td2d->loc;
-               VECCOPY(td->center, cent);
-               VECCOPY(td->iloc, td->loc);
+               copy_v3_v3(td->center, cent);
+               copy_v3_v3(td->iloc, td->loc);
        }
 
        if (td->flag & TD_MOVEHANDLE1) {
@@ -3261,7 +3281,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                return;
        
        /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY | ANIMFILTER_CURVEVISIBLE);
+       filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
        
        /* which side of the current frame should be allowed */
@@ -3396,7 +3416,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                                const char sel3= use_handle ? bezt->f3 & SELECT : 0;
 
                                TransDataCurveHandleFlags *hdata = NULL;
-                               short h1=1, h2=1;
+                               /* short h1=1, h2=1; */ /* UNUSED */
                                
                                /* only include handles if selected, irrespective of the interpolation modes.
                                 * also, only treat handles specially if the center point isn't selected. 
@@ -3406,16 +3426,18 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                                                hdata = initTransDataCurveHandles(td, bezt);
                                                bezt_to_transdata(td++, td2d++, adt, bezt, 0, 1, 1, intvals, mtx, smtx);
                                        } 
-                                       else
-                                               h1= 0;
+                                       else {
+                                               /* h1= 0; */ /* UNUSED */
+                                       }
                                        
                                        if (sel3) {
                                                if (hdata==NULL)
                                                        hdata = initTransDataCurveHandles(td, bezt);
                                                bezt_to_transdata(td++, td2d++, adt, bezt, 2, 1, 1, intvals, mtx, smtx);
                                        } 
-                                       else
-                                               h2= 0;
+                                       else {
+                                               /* h2= 0; */ /* UNUSED */
+                                       }
                                }
                                
                                /* only include main vert if selected */
@@ -3441,7 +3463,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                                 *        then check if we're using auto-handles.
                                 *      - If so, change them auto-handles to aligned handles so that handles get affected too
                                 */
-                               if ((bezt->h1 == HD_AUTO) && (bezt->h2 == HD_AUTO) && ELEM(t->mode, TFM_ROTATION, TFM_RESIZE)) {
+                               if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) && ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM) && ELEM(t->mode, TFM_ROTATION, TFM_RESIZE)) {
                                        if (hdata && (sel1) && (sel3)) {
                                                bezt->h1= HD_ALIGN;
                                                bezt->h2= HD_ALIGN;
@@ -3892,8 +3914,8 @@ static TransData *SeqToTransData(TransData *td, TransData2D *td2d, TransDataSeq
 
        td->flag = 0;
        td->loc = td2d->loc;
-       VECCOPY(td->center, td->loc);
-       VECCOPY(td->iloc, td->loc);
+       copy_v3_v3(td->center, td->loc);
+       copy_v3_v3(td->iloc, td->loc);
 
        memset(td->axismtx, 0, sizeof(td->axismtx));
        td->axismtx[2][2] = 1.0f;
@@ -4244,7 +4266,7 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
        td->ob = ob;
 
        td->loc = ob->loc;
-       VECCOPY(td->iloc, td->loc);
+       copy_v3_v3(td->iloc, td->loc);
        
        if (ob->rotmode > 0) {
                td->ext->rot= ob->rot;
@@ -4252,8 +4274,8 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
                td->ext->rotAngle= NULL;
                td->ext->quat= NULL;
                
-               VECCOPY(td->ext->irot, ob->rot);
-               VECCOPY(td->ext->drot, ob->drot);
+               copy_v3_v3(td->ext->irot, ob->rot);
+               copy_v3_v3(td->ext->drot, ob->drot);
        }
        else if (ob->rotmode == ROT_MODE_AXISANGLE) {
                td->ext->rot= NULL;
@@ -4262,9 +4284,9 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
                td->ext->quat= NULL;
                
                td->ext->irotAngle= ob->rotAngle;
-               VECCOPY(td->ext->irotAxis, ob->rotAxis);
+               copy_v3_v3(td->ext->irotAxis, ob->rotAxis);
                // td->ext->drotAngle= ob->drotAngle;                   // XXX, not implimented
-               // VECCOPY(td->ext->drotAxis, ob->drotAxis);    // XXX, not implimented
+               // copy_v3_v3(td->ext->drotAxis, ob->drotAxis); // XXX, not implimented
        }
        else {
                td->ext->rot= NULL;
@@ -4278,10 +4300,10 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
        td->ext->rotOrder=ob->rotmode;
 
        td->ext->size = ob->size;
-       VECCOPY(td->ext->isize, ob->size);
-       VECCOPY(td->ext->dsize, ob->dsize);
+       copy_v3_v3(td->ext->isize, ob->size);
+       copy_v3_v3(td->ext->dsize, ob->dsize);
 
-       VECCOPY(td->center, ob->obmat[3]);
+       copy_v3_v3(td->center, ob->obmat[3]);
 
        copy_m4_m4(td->ext->obmat, ob->obmat);
 
@@ -4760,10 +4782,25 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
 
        }
        else if (t->spacetype == SPACE_NODE) {
-               /* pass */
+               SpaceNode *snode= (SpaceNode *)t->sa->spacedata.first;
+               ED_node_update_hierarchy(C, snode->edittree);
+               
+               if(cancelled == 0)
+                       ED_node_link_insert(t->sa);
+               
+               /* clear link line */
+               ED_node_link_intersect_test(t->sa, 0);
        }
        else if (t->spacetype == SPACE_CLIP) {
-               /* pass */
+               SpaceClip *sc= t->sa->spacedata.first;
+               MovieClip *clip= ED_space_clip(sc);
+
+               if(t->scene->nodetree) {
+                       /* tracks can be used for stabilization nodes,
+                          flush update for such nodes */
+                       NodeTagIDChanged(t->scene->nodetree, &clip->id);
+                       WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
+               }
        }
        else if (t->spacetype == SPACE_ACTION) {
                SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
@@ -4778,7 +4815,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                if (ELEM(ac.datatype, ANIMCONT_DOPESHEET, ANIMCONT_SHAPEKEY)) {
                        ListBase anim_data = {NULL, NULL};
                        bAnimListElem *ale;
-                       short filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+                       short filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/);
                        
                        /* get channels to work on */
                        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
@@ -4845,7 +4882,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                                // XXX: BAD! this get gpencil datablocks directly from main db...
                                // but that's how this currently works :/
                                for (gpd = G.main->gpencil.first; gpd; gpd = gpd->id.next) {
-                                       if (ID_REAL_USERS(gpd) > 1)
+                                       if (ID_REAL_USERS(gpd))
                                                posttrans_gpd_clean(gpd);
                                }
                        }
@@ -4873,7 +4910,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                }
                
                /* make sure all F-Curves are set correctly */
-               ANIM_editkeyframes_refresh(&ac);
+               if (ac.datatype != ANIMCONT_GPENCIL)
+                       ANIM_editkeyframes_refresh(&ac);
                
                /* clear flag that was set for time-slide drawing */
                saction->flag &= ~SACTION_MOVING;
@@ -4890,7 +4928,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                {
                        ListBase anim_data = {NULL, NULL};
                        bAnimListElem *ale;
-                       short filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY | ANIMFILTER_CURVEVISIBLE);
+                       short filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE);
                        
                        /* get channels to work on */
                        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
@@ -4940,7 +4978,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                {
                        ListBase anim_data = {NULL, NULL};
                        bAnimListElem *ale;
-                       short filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NLATRACKS);
+                       short filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT);
                        
                        /* get channels to work on */
                        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
@@ -5180,9 +5218,14 @@ static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node)
        td2d->loc2d = &node->locx; /* current location */
 
        td->flag = 0;
+       /* exclude nodes whose parent is also transformed */
+       if (node->parent && (node->parent->flag & NODE_TRANSFORM)) {
+               td->flag |= TD_SKIP;
+       }
+
        td->loc = td2d->loc;
-       VECCOPY(td->center, td->loc);
-       VECCOPY(td->iloc, td->loc);
+       copy_v3_v3(td->center, td->loc);
+       copy_v3_v3(td->iloc, td->loc);
 
        memset(td->axismtx, 0, sizeof(td->axismtx));
        td->axismtx[2][2] = 1.0f;
@@ -5200,6 +5243,16 @@ static void createTransNodeData(bContext *C, TransInfo *t)
 {
        TransData *td;
        TransData2D *td2d;
+       SpaceNode *snode= t->sa->spacedata.first;
+       bNode *node;
+
+       /* set transform flags on nodes */
+       for (node=snode->edittree->nodes.first; node; node=node->next) {
+               if ((node->flag & NODE_SELECT) || (node->parent && (node->parent->flag & NODE_TRANSFORM)))
+                       node->flag |= NODE_TRANSFORM;
+               else
+                       node->flag &= ~NODE_TRANSFORM;
+       }
 
        t->total= CTX_DATA_COUNT(C, selected_nodes);
 
@@ -5213,20 +5266,53 @@ static void createTransNodeData(bContext *C, TransInfo *t)
 
 /* *** CLIP EDITOR *** */
 
-static void markerToTransDataInit(TransData *td, TransData2D *td2d, float *loc, float *rel)
+typedef struct TransDataTracking {
+       int area;
+       float *relative, *loc;
+       float soffset[2], srelative[2];
+       float offset[2];
+
+       float (*smarkers)[2];
+       int markersnr;
+       MovieTrackingMarker *markers;
+} TransDataTracking;
+
+static void markerToTransDataInit(TransData *td, TransData2D *td2d,
+                       TransDataTracking *tdt, MovieTrackingTrack *track, int area, float *loc, float *rel, float *off)
 {
-       td2d->loc[0] = loc[0]; /* hold original location */
-       td2d->loc[1] = loc[1];
+       int anchor = area==TRACK_AREA_POINT && off;
+
+       if(anchor) {
+               td2d->loc[0] = rel[0]; /* hold original location */
+               td2d->loc[1] = rel[1];
+
+               tdt->loc= loc;
+               td2d->loc2d = loc; /* current location */
+       } else {
+               td2d->loc[0] = loc[0]; /* hold original location */
+               td2d->loc[1] = loc[1];
+
+               td2d->loc2d = loc; /* current location */
+       }
        td2d->loc[2] = 0.0f;
 
-       if(rel) {       /* XXX: could it be nicer? */
-               td2d->loc[0]+= rel[0];
-               td2d->loc[1]+= rel[1];
+       tdt->relative= rel;
+       tdt->area= area;
 
-               td->extra= rel;
+       tdt->markersnr= track->markersnr;
+       tdt->markers= track->markers;
+
+       if(rel) {
+               if(!anchor) {
+                       td2d->loc[0]+= rel[0];
+                       td2d->loc[1]+= rel[1];
+               }
+
+               copy_v2_v2(tdt->srelative, rel);
        }
 
-       td2d->loc2d = loc; /* current location */
+       if(off)
+               copy_v2_v2(tdt->soffset, off);
 
        td->flag = 0;
        td->loc = td2d->loc;
@@ -5245,7 +5331,8 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d, float *loc,
        unit_m3(td->smtx);
 }
 
-static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d, MovieTrackingTrack *track)
+static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
+                       TransDataTracking *tdt, MovieTrackingTrack *track)
 {
        MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
 
@@ -5253,17 +5340,29 @@ static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d, Mo
 
        marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
 
+       markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, track->offset, marker->pos, track->offset);
+
        if(track->flag&SELECT)
-               markerToTransDataInit(td++, td2d++, marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, marker->pos, NULL, NULL);
 
        if(track->pat_flag&SELECT) {
-               markerToTransDataInit(td++, td2d++, track->pat_min, marker->pos);
-               markerToTransDataInit(td++, td2d++, track->pat_max, marker->pos);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, track->pat_min, marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, track->pat_max, marker->pos, NULL);
        }
 
        if(track->search_flag&SELECT) {
-               markerToTransDataInit(td++, td2d++, track->search_min, marker->pos);
-               markerToTransDataInit(td++, td2d++, track->search_max, marker->pos);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_SEARCH, track->search_min, marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_SEARCH, track->search_max, marker->pos, NULL);
+       }
+}
+
+static void transDataTrackingFree(TransInfo *t)
+{
+       TransDataTracking *tdt= t->customData;
+
+       if(tdt) {
+               if(tdt->smarkers) MEM_freeN(tdt->smarkers);
+               MEM_freeN(tdt);
        }
 }
 
@@ -5275,6 +5374,7 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
        MovieClip *clip = ED_space_clip(sc);
        MovieTrackingTrack *track;
        MovieTrackingMarker *marker;
+       TransDataTracking *tdt;
        int framenr = sc->user.framenr;
 
        if(clip && !BKE_movieclip_has_frame(clip, &sc->user)) {
@@ -5287,52 +5387,57 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
 
        track = clip->tracking.tracks.first;
        while(track) {
-               if(TRACK_SELECTED(track)) {
+               if(TRACK_VIEW_SELECTED(sc, track) && (track->flag&TRACK_LOCKED)==0) {
                        marker= BKE_tracking_get_marker(track, framenr);
 
                        if(marker) {
-                               if((marker->flag&MARKER_DISABLED)==0) {
-                                       if(track->flag&SELECT) t->total++;
-                                       if(track->pat_flag&SELECT) t->total+= 2;
-                               }
-
-                               if(track->search_flag&SELECT) {
-                                       t->total+= 2;
+                               t->total++;     /* offset */
 
-                                       if(marker->flag&MARKER_DISABLED)
-                                               t->total+= 3;
-                               }
+                               if(track->flag&SELECT) t->total++;
+                               if(track->pat_flag&SELECT) t->total+= 2;
+                               if(track->search_flag&SELECT) t->total+= 2;
                        }
                }
 
                track = track->next;
        }
 
+       if(t->total==0)
+               return;
+
        td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransTracking TransData");
        td2d = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransTracking TransData2D");
+       tdt = t->customData = MEM_callocN(t->total*sizeof(TransDataTracking), "TransTracking TransDataTracking");
+
+       t->customFree= transDataTrackingFree;
 
        /* create actual data */
        track = clip->tracking.tracks.first;
        while(track) {
-               if(TRACK_SELECTED(track)) {
+               if(TRACK_VIEW_SELECTED(sc, track) && (track->flag&TRACK_LOCKED)==0) {
                        marker= BKE_tracking_get_marker(track, framenr);
 
-                       if(marker) {
-                               trackToTransData(sc, td, td2d, track);
+                       trackToTransData(sc, td, td2d, tdt, track);
 
-                               if((marker->flag&MARKER_DISABLED)==0) {
-                                       if(track->flag&SELECT) {td++; td2d++;}
-                                       if(track->pat_flag&SELECT) {td+= 2; td2d+= 2;}
-                               }
+                       /* offset */
+                       td++;
+                       td2d++;
+                       tdt++;
 
-                               if(track->search_flag&SELECT) {
-                                       td+= 2;
-                                       td2d+= 2;
+                       if((marker->flag&MARKER_DISABLED)==0) {
+                               if(track->flag&SELECT) {td++; td2d++; tdt++;}
+                               if(track->pat_flag&SELECT) {td+= 2; td2d+= 2;tdt+=2;}
+                       }
 
-                                       if(marker->flag&MARKER_DISABLED) {
-                                               td+= 3;
-                                               td2d+= 3;
-                                       }
+                       if(track->search_flag&SELECT) {
+                               td+= 2;
+                               td2d+= 2;
+                               tdt+= 2;
+
+                               if(marker->flag&MARKER_DISABLED) {
+                                       td+= 3;
+                                       td2d+= 3;
+                                       tdt+= 3;
                                };
                        }
                }
@@ -5345,15 +5450,40 @@ void flushTransTracking(TransInfo *t)
 {
        TransData *td;
        TransData2D *td2d;
+       TransDataTracking *tdt;
        int a;
 
        /* flush to 2d vector from internally used 3d vector */
-       for(a=0, td= t->data, td2d= t->data2d; a<t->total; a++, td2d++, td++) {
-               td2d->loc2d[0] = td2d->loc[0];
-               td2d->loc2d[1] = td2d->loc[1];
+       for(a=0, td= t->data, td2d= t->data2d, tdt= t->customData; a<t->total; a++, td2d++, td++, tdt++) {
+               if(t->flag&T_ALT_TRANSFORM) {
+                       if(tdt->area==TRACK_AREA_POINT && tdt->relative) {
+                               float d[2], d2[2];
+
+                               if(!tdt->smarkers) {
+                                       tdt->smarkers= MEM_callocN(sizeof(*tdt->smarkers)*tdt->markersnr, "flushTransTracking markers");
+                                       for(a= 0; a<tdt->markersnr; a++)
+                                               copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos);
+                               }
+
+                               sub_v2_v2v2(d, td2d->loc, tdt->soffset);
+                               sub_v2_v2(d, tdt->srelative);
+
+                               sub_v2_v2v2(d2, td2d->loc, tdt->srelative);
 
-               if(td->extra)
-                       sub_v2_v2(td2d->loc2d, td->extra);
+                               for(a= 0; a<tdt->markersnr; a++)
+                                       add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
+
+                               negate_v2_v2(td2d->loc2d, d);
+                       }
+               }
+
+               if(tdt->area!=TRACK_AREA_POINT || tdt->relative==0) {
+                       td2d->loc2d[0] = td2d->loc[0];
+                       td2d->loc2d[1] = td2d->loc[1];
+
+                       if(tdt->relative)
+                               sub_v2_v2(td2d->loc2d, tdt->relative);
+               }
        }
 }