Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 1 Aug 2011 08:29:17 +0000 (08:29 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 1 Aug 2011 08:29:17 +0000 (08:29 +0000)
===========================

- If "Zoom To Mouse" is enabled in user preferences then
  zooming would happen to mouse position in clip editor.
- Fixed 1px padding from shot boundary rectangle.
- Allow for some operators grab cursor.
- Enlarge marker anchor sliding area and make it prioritized
  on pattern/search slide zones,

source/blender/editors/include/ED_clip.h
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_clip/clip_editor.c
source/blender/editors/space_clip/clip_ops.c
source/blender/editors/space_clip/tracking_ops.c

index d422deb51b00ee58c896db364e004ce05da13cc9..b73ffff804c8313fb7014c1f951505f47e8ed37d 100644 (file)
@@ -39,6 +39,7 @@ struct ImBuf;
 struct Main;
 struct MovieClip;
 struct SpaceClip;
+struct wmEvent;
 
 /* clip_editor.c */
 void ED_space_clip_set(struct bContext *C, struct SpaceClip *sc, struct MovieClip *clip);
@@ -54,6 +55,9 @@ struct ImBuf *ED_space_clip_acquire_stable_buffer(struct SpaceClip *sc, float ma
 void ED_clip_update_frame(const struct Main *mainp, int cfra);
 void ED_clip_view_selection(struct SpaceClip *sc, struct ARegion *ar, int fit);
 
+void ED_clip_point_stable_pos(struct bContext *C, float x, float y, float *xr, float *yr);
+void ED_clip_mouse_pos(struct bContext *C, struct wmEvent *event, float co[2]);
+
 /* clip_ops.c */
 void ED_operatormacros_clip(void);
 
index 62ee0f8596a91c2d8bb6033a91e7dea3643abdbe..b46f3fd5b6d1d9dfeb5b889a27f05d9ada5d1ab6 100644 (file)
@@ -178,10 +178,10 @@ static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf, float
                        glMultMatrixf(sc->stabmat);
 
                        glBegin(GL_LINE_LOOP);
-                               glVertex2f(-1.f, -1.f);
-                               glVertex2f(ibuf->x+1.f, -1.f);
-                               glVertex2f(ibuf->x+1.f, ibuf->y+1.f);
-                               glVertex2f(-1.f, ibuf->y+1.f);
+                               glVertex2f(0.f, 0.f);
+                               glVertex2f(ibuf->x, 0.f);
+                               glVertex2f(ibuf->x, ibuf->y);
+                               glVertex2f(0.f, ibuf->y);
                        glEnd();
 
                        glPopMatrix();
index 23f6de5b353142f7d84ef9bd888bcab04581af35..8201341fd897822803064f1eacf05f7fee8ba9b0 100644 (file)
@@ -53,6 +53,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "UI_view2d.h"
+
 void ED_space_clip_set(bContext *C, SpaceClip *sc, MovieClip *clip)
 {
        sc->clip= clip;
@@ -234,3 +236,30 @@ void ED_clip_view_selection(SpaceClip *sc, ARegion *ar, int fit)
                        sc->zoom= newzoom;
        }
 }
+
+void ED_clip_point_stable_pos(bContext *C, float x, float y, float *xr, float *yr)
+{
+       ARegion *ar= CTX_wm_region(C);
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       int sx, sy, width, height;
+       float zoomx, zoomy, pos[3]={0.f, 0.f, 0.f}, imat[4][4];
+
+       ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
+       ED_space_clip_size(sc, &width, &height);
+
+       UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+
+       pos[0]= (x-sx)/zoomx;
+       pos[1]= (y-sy)/zoomy;
+
+       invert_m4_m4(imat, sc->stabmat);
+       mul_v3_m4v3(pos, imat, pos);
+
+       *xr= pos[0]/width;
+       *yr= pos[1]/height;
+}
+
+void ED_clip_mouse_pos(bContext *C, wmEvent *event, float co[2])
+{
+       ED_clip_point_stable_pos(C, event->mval[0], event->mval[1], &co[0], &co[1]);
+}
index 7f534c2e2dd20f9a5bfe9f92e6dce8adc15e36fd..6701192d8e07f2a37d110b5b8ccb2e029c054b21 100644 (file)
@@ -74,8 +74,8 @@ static void sclip_zoom_set(SpaceClip *sc, ARegion *ar, float zoom)
        /* check zoom limits */
        ED_space_clip_size(sc, &width, &height);
 
-       width *= sc->zoom;
-       height *= sc->zoom;
+       width*= sc->zoom;
+       height*= sc->zoom;
 
        if((width < 4) && (height < 4))
                sc->zoom= oldzoom;
@@ -542,7 +542,7 @@ void CLIP_OT_view_zoom(wmOperatorType *ot)
        ot->poll= space_clip_poll;
 
        /* flags */
-       ot->flag= OPTYPE_BLOCKING;
+       ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
 
        /* properties */
        RNA_def_float(ot->srna, "factor", 0.0f, 0.0f, FLT_MAX,
@@ -563,6 +563,47 @@ static int view_zoom_in_exec(bContext *C, wmOperator *UNUSED(op))
        return OPERATOR_FINISHED;
 }
 
+static int view_zoom_out_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       ARegion *ar= CTX_wm_region(C);
+
+       sclip_zoom_set_factor(sc, ar, 0.8f);
+
+       ED_region_tag_redraw(CTX_wm_region(C));
+
+       return OPERATOR_FINISHED;
+}
+
+static int view_zoom_inout_invoke(bContext *C, wmOperator *op, wmEvent *event, int out)
+{
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       float co[2], oldzoom= sc->zoom;
+
+       ED_clip_mouse_pos(C, event, co);
+
+       if(out)
+               view_zoom_out_exec(C, op);
+       else
+               view_zoom_in_exec(C, op);
+
+       if(U.uiflag&USER_ZOOM_TO_MOUSEPOS) {
+               int width, height;
+
+               ED_space_clip_size(sc, &width, &height);
+
+               sc->xof+= ((co[0]-0.5)*width-sc->xof)*(sc->zoom-oldzoom)/sc->zoom;
+               sc->yof+= ((co[1]-0.5)*height-sc->yof)*(sc->zoom-oldzoom)/sc->zoom;
+       }
+
+       return OPERATOR_FINISHED;
+}
+
+static int view_zoom_in_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       return view_zoom_inout_invoke(C, op, event, 0);
+}
+
 void CLIP_OT_view_zoom_in(wmOperatorType *ot)
 {
        /* identifiers */
@@ -571,19 +612,13 @@ void CLIP_OT_view_zoom_in(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= view_zoom_in_exec;
+       ot->invoke= view_zoom_in_invoke;
        ot->poll= space_clip_poll;
 }
 
-static int view_zoom_out_exec(bContext *C, wmOperator *UNUSED(op))
+static int view_zoom_out_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       ARegion *ar= CTX_wm_region(C);
-
-       sclip_zoom_set_factor(sc, ar, 0.8f);
-
-       ED_region_tag_redraw(CTX_wm_region(C));
-
-       return OPERATOR_FINISHED;
+       return view_zoom_inout_invoke(C, op, event, 1);
 }
 
 void CLIP_OT_view_zoom_out(wmOperatorType *ot)
@@ -594,6 +629,7 @@ void CLIP_OT_view_zoom_out(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= view_zoom_out_exec;
+       ot->invoke= view_zoom_out_invoke;
        ot->poll= space_clip_poll;
 }
 
index e8fd58e80ce48352d37287356a00e2ee6afd5075..bf9d8aaf0e770c3ba729919e74361829d34c5146 100644 (file)
@@ -162,38 +162,11 @@ static int add_marker_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-static void point_stable_pos(bContext *C, float x, float y, float *xr, float *yr)
-{
-       ARegion *ar= CTX_wm_region(C);
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       int sx, sy, width, height;
-       float zoomx, zoomy, pos[3]={0.f, 0.f, 0.f}, imat[4][4];
-
-       ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
-       ED_space_clip_size(sc, &width, &height);
-
-       UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
-
-       pos[0]= (x-sx)/zoomx;
-       pos[1]= (y-sy)/zoomy;
-
-       invert_m4_m4(imat, sc->stabmat);
-       mul_v3_m4v3(pos, imat, pos);
-
-       *xr= pos[0]/width;
-       *yr= pos[1]/height;
-}
-
-static void mouse_pos(bContext *C, wmEvent *event, float co[2])
-{
-       point_stable_pos(C, event->mval[0], event->mval[1], &co[0], &co[1]);
-}
-
 static int add_marker_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        float co[2];
 
-       mouse_pos(C, event, co);
+       ED_clip_mouse_pos(C, event, co);
 
        RNA_float_set_array(op->ptr, "location", co);
 
@@ -443,8 +416,8 @@ static int mouse_on_offset(SpaceClip *sc, MovieTrackingTrack *track, MovieTracki
        dx= 12.f/width/sc->zoom;
        dy= 12.f/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);
+       dx=MIN2(dx, (track->pat_max[0]-track->pat_min[0])/2.f);
+       dy=MIN2(dy, (track->pat_max[1]-track->pat_min[1])/2.f);
 
        return co[0]>=pos[0]-dx && co[0]<=pos[0]+dx && co[1]>=pos[1]-dy && co[1]<=pos[1]+dy;
 }
@@ -477,7 +450,7 @@ static void *slide_marker_customdata(bContext *C, wmEvent *event)
        if(width==0 || height==0)
                return NULL;
 
-       mouse_pos(C, event, co);
+       ED_clip_mouse_pos(C, event, co);
 
        track= clip->tracking.tracks.first;
        while(track) {
@@ -485,6 +458,10 @@ static void *slide_marker_customdata(bContext *C, wmEvent *event)
                        MovieTrackingMarker *marker= BKE_tracking_get_marker(track, sc->user.framenr);
 
                        if((marker->flag&MARKER_DISABLED)==0) {
+                               if(!customdata)
+                                       if(mouse_on_offset(sc, track, marker, co, width, height))
+                                               customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT, SLIDE_ACTION_POS, width, height);
+
                                if(sc->flag&SC_SHOW_MARKER_SEARCH) {
                                        if(mouse_on_corner(sc, track, marker, TRACK_AREA_SEARCH, co, 1, width, height))
                                                customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, SLIDE_ACTION_OFFSET, width, height);
@@ -500,10 +477,6 @@ static void *slide_marker_customdata(bContext *C, wmEvent *event)
                                                customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, SLIDE_ACTION_SIZE, width, height);
                                }
 
-                               if(!customdata)
-                                       if(mouse_on_offset(sc, track, marker, co, width, height))
-                                               customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT, SLIDE_ACTION_POS, width, height);
-
                                if(customdata)
                                        break;
                        }
@@ -664,7 +637,7 @@ void CLIP_OT_slide_marker(wmOperatorType *ot)
        ot->modal= slide_marker_modal;
 
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_GRAB_POINTER|OPTYPE_BLOCKING;
 
        /* properties */
        RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
@@ -836,7 +809,7 @@ static int select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                }
        }
 
-       mouse_pos(C, event, co);
+       ED_clip_mouse_pos(C, event, co);
        RNA_float_set_array(op->ptr, "location", co);
 
        return select_exec(C, op);
@@ -881,8 +854,8 @@ static int border_select_exec(bContext *C, wmOperator *op)
        rect.xmax= RNA_int_get(op->ptr, "xmax");
        rect.ymax= RNA_int_get(op->ptr, "ymax");
 
-       point_stable_pos(C, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
-       point_stable_pos(C, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
+       ED_clip_point_stable_pos(C, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
+       ED_clip_point_stable_pos(C, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
 
        mode= RNA_int_get(op->ptr, "gesture_mode");
 
@@ -969,7 +942,7 @@ static int circle_select_exec(bContext *C, wmOperator *op)
        ellipse[0]= width*zoomx/radius;
        ellipse[1]= height*zoomy/radius;
 
-       point_stable_pos(C, x, y, &offset[0], &offset[1]);
+       ED_clip_point_stable_pos(C, x, y, &offset[0], &offset[1]);
 
        /* do selection */
        track= clip->tracking.tracks.first;
@@ -1579,7 +1552,7 @@ static int clear_reconstruction_exec(bContext *C, wmOperator *UNUSED(op))
 void CLIP_OT_clear_reconstruction(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Clear Reconstruciton";
+       ot->name= "Clear Reconstruction";
        ot->description= "Clear all reconstruciton data";
        ot->idname= "CLIP_OT_clear_reconstruction";