Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 22 Jul 2011 14:06:31 +0000 (14:06 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 22 Jul 2011 14:06:31 +0000 (14:06 +0000)
===========================

- Damn hidden searches. Again fix in select_all operator.
  This time for inverted selection.
- Do not select "hidden" parts of marker on creation.
- Added modifier key for marker transformation:
  if alt is pressed down -- pattern/search will be moving
  relative to marker center.
- Changed behavior of mouse sliding:
  * To change marker position markers should be slided by it's center.
  * Left-top corners now used to offset pattern/search relative to
   marker center.
  * Hide mouse cursor during sliding.

source/blender/editors/space_clip/clip_draw.c
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 7a1d9dda4d70ad28d463dfb392328a0da086032c..e7f5153567ba2a5b9bad59d72b446dc4ac50e0b6 100644 (file)
@@ -490,6 +490,7 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
        }
 
        if(sc->flag&SC_SHOW_MARKER_PATTERN) {
+               float tdx2= 0, tdy2= 0;
                /* use smaller slider for pattern area */
                dx= 10.0f/width/sc->zoom;
                dy= 10.0f/height/sc->zoom;
@@ -499,15 +500,33 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
                        else glColor3fv(col);
                }
 
+               tdx=MIN2(dx, (track->pat_max[0]-track->pat_min[0])/5);
+               tdy=MIN2(dy, (track->pat_max[1]-track->pat_min[1])/5);
+
+               if(outline) {
+                       tdx+= 1.0f/sc->zoom/width;
+                       tdy+= 1.0f/sc->zoom/height;
+
+                       tdx2+= 1.0f/sc->zoom/width;
+                       tdy2+= 1.0f/sc->zoom/height;
+               }
+
+               x= track->pat_min[0];
+               y= track->pat_max[1];
+
+               glBegin(GL_QUADS);
+                       glVertex3f(x+tdx2, y-tdy2, 0);
+                       glVertex3f(x-tdx, y-tdy2, 0);
+                       glVertex3f(x-tdx, y+tdy, 0);
+                       glVertex3f(x+tdx2, y+tdy, 0);
+               glEnd();
+
                x= track->pat_max[0];
                y= track->pat_min[1];
 
-               tdx=MIN2(dx, track->pat_max[0]-track->pat_min[0]);
-               tdy=MIN2(dy, track->pat_max[1]-track->pat_min[1]);
-
                if(outline) {
-                       tdx+= 2.0f/sc->zoom/width;
-                       tdy+= 2.0f/sc->zoom/height;
+                       tdx+= 1.0f/sc->zoom/width;
+                       tdy+= 1.0f/sc->zoom/height;
                }
 
                glBegin(GL_TRIANGLES);
index edec7bd3582979ef8df01ffeb37d552fdadb477c..98a00a192ef56c716dbc5b03fc05b4d9b755bb02 100644 (file)
@@ -127,13 +127,17 @@ static void add_marker(SpaceClip *sc, float x, float y)
 {
        MovieClip *clip= ED_space_clip(sc);
        MovieTrackingTrack *track;
-       int width, height;
+       int width, height, select= 0;
 
        ED_space_clip_size(sc, &width, &height);
 
        track= BKE_tracking_add_track(&clip->tracking, x, y, sc->user.framenr, width, height);
 
-       BKE_movieclip_select_track(clip, track, TRACK_AREA_ALL, 0);
+       select= TRACK_AREA_POINT;
+       if(sc->flag&SC_SHOW_MARKER_PATTERN) select|= TRACK_AREA_PAT;
+       if(sc->flag&SC_SHOW_MARKER_SEARCH) select|= TRACK_AREA_SEARCH;
+
+       BKE_movieclip_select_track(clip, track, select, 0);
        BKE_movieclip_set_selection(clip, MCLIP_SEL_TRACK, track);
 }
 
@@ -702,10 +706,8 @@ static int select_all_exec(bContext *C, wmOperator *op)
                                                break;
                                        case SEL_INVERT:
                                                track->flag^= SELECT;
-                                               if(sc->flag&SC_SHOW_MARKER_PATTERN && (track->pat_flag&SELECT))
-                                                       track->pat_flag^= SELECT;
-                                               if(sc->flag&SC_SHOW_MARKER_SEARCH && (track->search_flag&SELECT))
-                                                       track->search_flag^= SELECT;
+                                               if(sc->flag&SC_SHOW_MARKER_PATTERN) track->pat_flag^= SELECT;
+                                               if(sc->flag&SC_SHOW_MARKER_SEARCH) track->search_flag^= SELECT;
                                                break;
                                }
                        }
@@ -1630,8 +1632,11 @@ void CLIP_OT_set_center_principal(wmOperatorType *ot)
 }
 /********************** slide marker opertaotr *********************/
 
+#define SLIDE_ACTION_POS       0
+#define SLIDE_ACTION_SIZE      1
+
 typedef struct {
-       int area;
+       int area, action;
        MovieTrackingTrack *track;
        MovieTrackingMarker *marker;
 
@@ -1644,13 +1649,14 @@ typedef struct {
 } SlideMarkerData;
 
 static SlideMarkerData *create_slide_marker_data(SpaceClip *sc, MovieTrackingTrack *track,
-                       MovieTrackingMarker *marker, wmEvent *event, int area, int width, int height)
+                       MovieTrackingMarker *marker, wmEvent *event, int area, int act, int width, int height)
 {
        SlideMarkerData *data= MEM_callocN(sizeof(SlideMarkerData), "slide marker data");
 
        marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
 
        data->area= area;
+       data->action= act;
        data->track= track;
        data->marker= marker;
 
@@ -1682,7 +1688,8 @@ static SlideMarkerData *create_slide_marker_data(SpaceClip *sc, MovieTrackingTra
 }
 
 /* corner = 0: right-bottom corner,
-   corner = 1: left-top corner */
+   corner = 1: left-top inside corner
+   corner = 2: left top outside corder*/
 static int mouse_on_corner(SpaceClip *sc, MovieTrackingTrack *track, float size, float co[2], int corner,
                        float *pos, float *min, float *max, int width, int height)
 {
@@ -1703,16 +1710,52 @@ static int mouse_on_corner(SpaceClip *sc, MovieTrackingTrack *track, float size,
                crn[1]= pos[1]+min[1];
 
                inside= nco[0]>=crn[0]-dx && nco[0]<=crn[0] && nco[1]>=crn[1] && nco[1]<=crn[1]+dy;
-       } else {
+       } else if(corner==1) {
                crn[0]= pos[0]+min[0];
                crn[1]= pos[1]+max[1];
 
                inside= nco[0]>=crn[0] && nco[0]<=crn[0]+dx && nco[1]>=crn[1]-dy && nco[1]<=crn[1];
+       } else {
+               crn[0]= pos[0]+min[0];
+               crn[1]= pos[1]+max[1];
+
+               inside= nco[0]>=crn[0]-dx && nco[0]<=crn[0] && nco[1]>=crn[1] && nco[1]<=crn[1]+dy;
        }
 
        return inside;
 }
 
+static int mouse_on_center(SpaceClip *sc, MovieTrackingTrack *track, float size,
+                           float co[2], float *pos, int width, int height)
+{
+       float nco[2], dx, dy;
+
+       nco[0]= co[0]/width;
+       nco[1]= co[1]/height;
+
+       dx= size/width/sc->zoom;
+       dy= size/height/sc->zoom;
+
+       dx=MIN2(dx, (track->pat_max[0]-track->pat_min[0])/3);
+       dy=MIN2(dy, (track->pat_max[1]-track->pat_min[1])/3);
+
+       return nco[0]>=pos[0]-dx && nco[0]<=pos[0]+dx && nco[1]>=pos[1]-dy && nco[1]<=pos[1]+dy;
+}
+
+static void hide_cursor(bContext *C)
+{
+       wmWindow *win= CTX_wm_window(C);
+
+       WM_cursor_set(win, CURSOR_NONE);
+}
+
+static void show_cursor(bContext *C)
+{
+       wmWindow *win= CTX_wm_window(C);
+
+       WM_cursor_set(win, CURSOR_STD);
+}
+
 static int slide_marker_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        SpaceClip *sc= CTX_wm_space_clip(C);
@@ -1734,19 +1777,25 @@ static int slide_marker_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        MovieTrackingMarker *marker= BKE_tracking_get_marker(track, sc->user.framenr);
 
                        if(marker && (marker->flag&MARKER_DISABLED)==0) {
-                               if(sc->flag&SC_SHOW_MARKER_SEARCH) {
-                                       if(mouse_on_corner(sc, track, 15.0f, co, 1, marker->pos, track->search_min, track->search_max, width, height))
-                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT, width, height);
+                               if(mouse_on_center(sc, track, 15.0f, co, marker->pos, width, height))
+                                       op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT, SLIDE_ACTION_POS, width, height);
 
-                                       if(mouse_on_corner(sc, track, 15.0f, co, 0, marker->pos, track->search_min, track->search_max, width, height))
-                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, width, height);
+                               if(!op->customdata && sc->flag&SC_SHOW_MARKER_SEARCH) {
+                                       if(mouse_on_corner(sc, track, 15.0f, co, 1, marker->pos, track->search_min, track->search_max, width, height))
+                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, SLIDE_ACTION_POS, width, height);
+                                       else if(mouse_on_corner(sc, track, 15.0f, co, 0, marker->pos, track->search_min, track->search_max, width, height))
+                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, SLIDE_ACTION_SIZE, width, height);
                                }
 
-                               if(sc->flag&SC_SHOW_MARKER_PATTERN)
-                                       if(mouse_on_corner(sc, track, 10.0f, co, 0, marker->pos, track->pat_min, track->pat_max, width, height))
-                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, width, height);
+                               if(!op->customdata && sc->flag&SC_SHOW_MARKER_PATTERN) {
+                                       if(mouse_on_corner(sc, track, 10.0f, co, 2, marker->pos, track->pat_min, track->pat_max, width, height))
+                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, SLIDE_ACTION_POS, width, height);
+                                       else if(mouse_on_corner(sc, track, 10.0f, co, 0, marker->pos, track->pat_min, track->pat_max, width, height))
+                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, SLIDE_ACTION_SIZE, width, height);
+                               }
 
                                if(op->customdata) {
+                                       hide_cursor(C);
                                        WM_event_add_modal_handler(C, op);
 
                                        return OPERATOR_RUNNING_MODAL;
@@ -1798,22 +1847,33 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
 
                                data->marker->flag&= ~MARKER_TRACKED;
                        } else {
-                               data->min[0]= data->smin[0]-dx;
-                               data->max[0]= data->smax[0]+dx;
+                               if(data->action==SLIDE_ACTION_SIZE) {
+                                       data->min[0]= data->smin[0]-dx;
+                                       data->max[0]= data->smax[0]+dx;
 
-                               data->min[1]= data->smin[1]+dy;
-                               data->max[1]= data->smax[1]-dy;
+                                       data->min[1]= data->smin[1]+dy;
+                                       data->max[1]= data->smax[1]-dy;
 
-                               if(data->lock) {
-                                       float h= (data->max[0]-data->min[0])*data->width/data->height;
+                                       if(data->lock) {
+                                               float h= (data->max[0]-data->min[0])*data->width/data->height;
 
-                                       data->min[1]= data->spos[1]-h/2;
-                                       data->max[1]= data->spos[1]+h/2;
-                               }
+                                               data->min[1]= data->spos[1]-h/2;
+                                               data->max[1]= data->spos[1]+h/2;
+                                       }
+
+
+                                       if(data->area==TRACK_AREA_SEARCH) BKE_tracking_clamp_track(data->track, CLAMP_SEARCH_DIM);
+                                       else BKE_tracking_clamp_track(data->track, CLAMP_PAT_DIM);
+                               } else {
+                                       data->min[0]= data->smin[0]+dx;
+                                       data->max[0]= data->smax[0]+dx;
 
+                                       data->min[1]= data->smin[1]+dy;
+                                       data->max[1]= data->smax[1]+dy;
 
-                               if(data->area==TRACK_AREA_SEARCH) BKE_tracking_clamp_track(data->track, CLAMP_SEARCH_DIM);
-                               else BKE_tracking_clamp_track(data->track, CLAMP_PAT_DIM);
+                                       if(data->area==TRACK_AREA_SEARCH) BKE_tracking_clamp_track(data->track, CLAMP_SEARCH_POS);
+                                       else BKE_tracking_clamp_track(data->track, CLAMP_PAT_POS);
+                               }
                        }
 
                        WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
@@ -1824,6 +1884,8 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
                        if(event->val==KM_RELEASE) {
                                MEM_freeN(op->customdata);
 
+                               show_cursor(C);
+
                                return OPERATOR_FINISHED;
                        }
 
@@ -1842,6 +1904,10 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
                                data->max[1]= data->smax[1];
                        }
 
+                       MEM_freeN(op->customdata);
+
+                       show_cursor(C);
+
                        WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
 
                        return OPERATOR_CANCELLED;
index d7110ac81ba6972ace78c9df88d7e5e72ebeb2c6..f273d6b529ede7f7b2cddce513c95430caf3f53b 100644 (file)
@@ -806,6 +806,15 @@ 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
@@ -1098,6 +1107,14 @@ 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 c2f04228b74ac81eec4ac78640fa34e9ee341e6c..1ce962a8713984c4039d15de38e31815684b9b95 100644 (file)
@@ -396,6 +396,9 @@ 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)
+
 /* TransInfo->modifiers */
 #define        MOD_CONSTRAINT_SELECT   0x01
 #define        MOD_PRECISION                   0x02
index c2d5c0ad252e916d9f275c5c68f1257e57f9820f..1d6d9b784895175cd60b64b501add2f6a26bcd0c 100644 (file)
@@ -5341,6 +5341,9 @@ void flushTransTracking(TransInfo *t)
 
        /* flush to 2d vector from internally used 3d vector */
        for(a=0, td= t->data, td2d= t->data2d; a<t->total; a++, td2d++, td++) {
+               if(t->flag&T_RELATIVE_POSITION && !td->extra)
+                       continue;
+
                td2d->loc2d[0] = td2d->loc[0];
                td2d->loc2d[1] = td2d->loc[1];