Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 18 Aug 2011 17:47:13 +0000 (17:47 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 18 Aug 2011 17:47:13 +0000 (17:47 +0000)
===========================

Change behavior of alternate transformation/marker sliding:

- Update all markers from track position when sliding marker by
  it's left-top corner of pattern.
  This prevents confusing when adding offset to already tracker marker.
- The same change was done to translation tool.
- To switch to "offset" mode of translation tool now you should use
  G-key (hit it during translation). Alt key wasn't so good idea
  because it's quite common hotkey in linux to move windows.

source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_conversions.c

index 64b7a8ffeffc4225f43bef113ee59524d25a6181..de2ddab4811fdb6c092a413a8926f1e81f10fdd4 100644 (file)
@@ -297,6 +297,7 @@ typedef struct {
        int width, height;
        float *min, *max, *pos, *offset;
        float smin[2], smax[2], spos[2], soff[2];
+       float (*smarkers)[2];
 
        int lock, accurate;
 } SlideMarkerData;
@@ -323,10 +324,16 @@ static SlideMarkerData *create_slide_marker_data(SpaceClip *sc, MovieTrackingTra
                        data->min= track->pat_min;
                        data->max= track->pat_max;
                } else {
+                       int a;
+
                        data->pos= marker->pos;
                        data->offset= track->offset;
-                       copy_v2_v2(data->spos, marker->pos);
+
                        copy_v2_v2(data->soff, track->offset);
+
+                       data->smarkers= MEM_callocN(sizeof(*data->smarkers)*track->markersnr, "slide marekrs");
+                       for(a= 0; a<track->markersnr; a++)
+                               copy_v2_v2(data->smarkers[a], track->markers[a].pos);
                }
        } else if(area==TRACK_AREA_SEARCH) {
                data->min= track->search_min;
@@ -500,10 +507,23 @@ static void cancel_mouse_slide(SlideMarkerData *data)
                if(data->action==SLIDE_ACTION_SIZE) {
                        copy_v2_v2(data->min, data->smin);
                        copy_v2_v2(data->max, data->smax);
+               } else {
+                       int a;
+
+                       for(a= 0; a<data->track->markersnr; a++)
+                               copy_v2_v2(data->track->markers[a].pos, data->smarkers[a]);
+
+                       copy_v2_v2(data->offset, data->soff);
                }
        }
 }
 
+static void free_slide_data(SlideMarkerData *data)
+{
+       if(data->smarkers) MEM_freeN(data->smarkers);
+       MEM_freeN(data);
+}
+
 static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
        SpaceClip *sc= CTX_wm_space_clip(C);
@@ -568,8 +588,10 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
                                                add_v2_v2v2(data->min, data->smin, d);
                                                add_v2_v2v2(data->max, data->smax, d);
                                        } else {
-                                               add_v2_v2v2(data->pos, data->spos, d);
-                                               add_v2_v2v2(data->pos, data->spos, d);
+                                               int a;
+
+                                               for(a= 0; a<data->track->markersnr; a++)
+                                                       add_v2_v2v2(data->track->markers[a].pos, data->smarkers[a], d);
 
                                                sub_v2_v2v2(data->offset, data->soff, d);
                                        }
@@ -585,7 +607,7 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
 
                case LEFTMOUSE:
                        if(event->val==KM_RELEASE) {
-                               MEM_freeN(op->customdata);
+                               free_slide_data(op->customdata);
 
                                show_cursor(C);
 
@@ -597,7 +619,7 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
                case ESCKEY:
                        cancel_mouse_slide(op->customdata);
 
-                       MEM_freeN(op->customdata);
+                       free_slide_data(op->customdata);
 
                        show_cursor(C);
 
index 190d93b176beb7cbfa6d2799e42515678b601b49..916eeec822add4bac6887e72674ab138e3d5f7dc 100644 (file)
@@ -625,6 +625,14 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        t->redraw |= TREDRAW_HARD;
                                }
+                               else if(t->mode == TFM_TRANSLATION) {
+                                       if(t->options&CTX_MOVIECLIP) {
+                                               restoreTransObjects(t);
+
+                                               t->flag^= T_ALT_TRANSFORM;
+                                               t->redraw |= TREDRAW_HARD;
+                                       }
+                               }
                                break;
                        case TFM_MODAL_ROTATE:
                                /* only switch when... */
@@ -806,15 +814,6 @@ int transformEvent(TransInfo *t, wmEvent *event)
                        t->redraw |= TREDRAW_HARD;
                        break;
 
-               case LEFTALTKEY:
-                       if(t->options&CTX_MOVIECLIP) {
-                               restoreTransObjects(t);
-
-                               t->flag|= T_RELATIVE_POSITION;
-                               t->redraw |= TREDRAW_HARD;
-                       }
-                       break;
-
                case SPACEKEY:
                        if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
 #if 0 // TRANSFORM_FIX_ME
@@ -1067,14 +1066,6 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                t->redraw |= TREDRAW_HARD;
                        }
                        break;
-               case LEFTALTKEY:
-                       if(t->options&CTX_MOVIECLIP) {
-                               restoreTransObjects(t);
-
-                               t->flag&= ~T_RELATIVE_POSITION;
-                               t->redraw |= TREDRAW_HARD;
-                       }
-                       break;
 //             case LEFTMOUSE:
 //             case RIGHTMOUSE:
 //                     if(WM_modal_tweak_exit(event, t->event_type))
index d95bb0e73aab296194e6c533c33a16402ac8dbe6..c55137fc6ffea8f33001dea67d3f584310690d21 100644 (file)
@@ -384,8 +384,8 @@ typedef struct TransInfo {
 
 #define T_RELEASE_CONFIRM      (1 << 23)
 
-       /* relative position changes. used to add offset to tracking markers */
-#define T_RELATIVE_POSITION    (1 << 24)
+       /* alternative transformation. used to add offset to tracking markers */
+#define T_ALT_TRANSFORM                (1 << 24)
 
 /* TransInfo->modifiers */
 #define        MOD_CONSTRAINT_SELECT   0x01
index eb05b3d960c5b21def87ea529e82459de429bb20..5a66f0bcfd19da9e0e05df510fc932ba683cde6a 100644 (file)
@@ -5230,10 +5230,14 @@ typedef struct TransDataTracking {
        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, int area, float *loc, float *rel, float *off)
+                       TransDataTracking *tdt, MovieTrackingTrack *track, int area, float *loc, float *rel, float *off)
 {
        int anchor = area==TRACK_AREA_POINT && off;
 
@@ -5242,8 +5246,7 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d,
                td2d->loc[1] = rel[1];
 
                tdt->loc= loc;
-               copy_v2_v2(tdt->offset, rel);
-               td2d->loc2d = tdt->offset; /* current location */
+               td2d->loc2d = loc; /* current location */
        } else {
                td2d->loc[0] = loc[0]; /* hold original location */
                td2d->loc[1] = loc[1];
@@ -5255,6 +5258,9 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d,
        tdt->relative= rel;
        tdt->area= area;
 
+       tdt->markersnr= track->markersnr;
+       tdt->markers= track->markers;
+
        if(rel) {
                if(!anchor) {
                        td2d->loc[0]+= rel[0];
@@ -5293,19 +5299,29 @@ static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
 
        marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
 
-       markerToTransDataInit(td++, td2d++, tdt++, TRACK_AREA_POINT, track->offset, marker->pos, track->offset);
+       markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, track->offset, marker->pos, track->offset);
 
        if(track->flag&SELECT)
-               markerToTransDataInit(td++, td2d++, tdt++, TRACK_AREA_POINT, marker->pos, NULL, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, marker->pos, NULL, NULL);
 
        if(track->pat_flag&SELECT) {
-               markerToTransDataInit(td++, td2d++, tdt++, TRACK_AREA_PAT, track->pat_min, marker->pos, NULL);
-               markerToTransDataInit(td++, td2d++, tdt++, TRACK_AREA_PAT, track->pat_max, marker->pos, NULL);
+               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++, tdt++, TRACK_AREA_SEARCH, track->search_min, marker->pos, NULL);
-               markerToTransDataInit(td++, td2d++, tdt++, TRACK_AREA_SEARCH, track->search_max, marker->pos, NULL);
+               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);
        }
 }
 
@@ -5352,6 +5368,8 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
        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) {
@@ -5360,6 +5378,7 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
 
                        trackToTransData(sc, td, td2d, tdt, track);
 
+                       /* offset */
                        td++;
                        td2d++;
                        tdt++;
@@ -5395,14 +5414,25 @@ void flushTransTracking(TransInfo *t)
 
        /* flush to 2d vector from internally used 3d vector */
        for(a=0, td= t->data, td2d= t->data2d, tdt= t->customData; a<t->total; a++, td2d++, td++, tdt++) {
-               if(t->flag&T_RELATIVE_POSITION) {
+               if(t->flag&T_ALT_TRANSFORM) {
                        if(tdt->area==TRACK_AREA_POINT && tdt->relative) {
-                               float d[2];
+                               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(td2d->loc2d, tdt->soffset, d);
-                               negate_v2_v2(tdt->loc, d);
+
+                               sub_v2_v2v2(d2, td2d->loc, tdt->srelative);
+
+                               for(a= 0; a<tdt->markersnr; a++)
+                                       add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
+
+                               negate_v2_v2(td2d->loc2d, d);
                        }
                }