Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 26 Sep 2011 10:25:38 +0000 (10:25 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 26 Sep 2011 10:25:38 +0000 (10:25 +0000)
===========================

Various grease pencil fixes:
- Last segment of distorted poly line wasn't drawing when
  manual calibration is enabled.
- Grease pencil+2d stabilization should live together fine now.

source/blender/editors/gpencil/gpencil_paint.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_clip/space_clip.c
source/blender/makesdna/DNA_space_types.h

index b2e1397388b884f4cf59d412e30da7860c58f1d8..a9259f0d9c8553d6101b2919d988f8c52c1a0b01 100644 (file)
@@ -103,6 +103,8 @@ typedef struct tGPsdata {
        
        short radius;           /* radius of influence for eraser */
        short flags;            /* flags that can get set during runtime */
+
+       float imat[4][4];
 } tGPsdata;
 
 /* values for tGPsdata->status */
@@ -277,6 +279,7 @@ static void gp_stroke_convertcoords (tGPsdata *p, const int mval[2], float out[3
        /* 2d - on 'canvas' (assume that p->v2d is set) */
        else if ((gpd->sbuffer_sflag & GP_STROKE_2DSPACE) && (p->v2d)) {
                UI_view2d_region_to_view(p->v2d, mval[0], mval[1], &out[0], &out[1]);
+               mul_v3_m4v3(out, p->imat, out);
        }
        
 #if 0
@@ -995,6 +998,8 @@ static int gp_session_initdata (bContext *C, tGPsdata *p)
        /* pass on current scene and window */
        p->scene= CTX_data_scene(C);
        p->win= CTX_wm_window(C);
+
+       unit_m4(p->imat);
        
        switch (curarea->spacetype) {
                /* supported views first */
@@ -1098,13 +1103,15 @@ static int gp_session_initdata (bContext *C, tGPsdata *p)
                case SPACE_CLIP:
                {
                        SpaceClip *sc= curarea->spacedata.first;
-                       
+
                        /* set the current area */
                        p->sa= curarea;
                        p->ar= ar;
                        p->v2d= &ar->v2d;
                        //p->ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
-                       
+
+                       invert_m4_m4(p->imat, sc->unistabmat);
+
                        /* check that gpencil data is allowed to be drawn */
                        if ((sc->flag & SC_SHOW_GPENCIL)==0) {
                                p->status= GP_STATUS_ERROR;
@@ -1114,7 +1121,7 @@ static int gp_session_initdata (bContext *C, tGPsdata *p)
                        }
                }
                        break;
-                       
+
                /* unsupported views */
                default:
                {
index 8f770e698c33bfa1ddae079917103f97d068beef..6420a950bd51de54c283621c45c98d398ccb58d7 100644 (file)
@@ -1083,7 +1083,7 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, int wid
                                                                        sub_v2_v2v2(dpos, npos, pos);
                                                                        mul_v2_fl(dpos, 1.f/steps);
 
-                                                                       for(j= 0; j<steps; j++) {
+                                                                       for(j= 0; j<=steps; j++) {
                                                                                BKE_tracking_apply_intrinsics(tracking, pos, tpos);
                                                                                glVertex2f(tpos[0]/width, tpos[1]/(height*aspy));
 
@@ -1130,14 +1130,24 @@ void draw_clip_main(SpaceClip *sc, ARegion *ar, Scene *scene)
        ED_space_clip_zoom(sc, ar, &zoomx, &zoomy);
 
        if(sc->flag&SC_SHOW_STABLE) {
+               float smat[4][4], ismat[4][4];
+
                ibuf= ED_space_clip_acquire_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle);
                BKE_tracking_stabdata_to_mat4(width, height, sc->loc, sc->scale, sc->angle, sc->stabmat);
+
+               unit_m4(smat);
+               smat[0][0]= 1.f/width;
+               smat[1][1]= 1.f/height;
+               invert_m4_m4(ismat, smat);
+
+               mul_serie_m4(sc->unistabmat, smat, sc->stabmat, ismat, NULL, NULL, NULL, NULL, NULL);
        } else {
                ibuf= ED_space_clip_acquire_buffer(sc);
 
                zero_v2(sc->loc);
                sc->scale= 1.f;
                unit_m4(sc->stabmat);
+               unit_m4(sc->unistabmat);
        }
 
        if(ibuf) {
@@ -1168,9 +1178,12 @@ void draw_clip_grease_pencil(bContext *C, int onlyv2d)
                        ibuf= ED_space_clip_acquire_buffer(sc);
 
                        if(ibuf) {
+                               glPushMatrix();
+                               glMultMatrixf(sc->unistabmat);
                                draw_gpencil_2dimage(C, ibuf);
 
                                IMB_freeImBuf(ibuf);
+                               glPopMatrix();
                        }
                }
        } else {
index bb7a650ac9e62884cb9878b3c6fc2f0bff9de119..3457b935b72fa3f8f1c6f60ac9559823e69d316c 100644 (file)
@@ -636,7 +636,11 @@ static void clip_props_area_listener(ARegion *ar, wmNotifier *wmn)
                                ED_region_tag_redraw(ar);
                        break;
                case NC_SPACE:
-                       if(wmn->data == ND_SPACE_VIEW3D)
+                       if(wmn->data == ND_SPACE_CLIP)
+                               ED_region_tag_redraw(ar);
+                       break;
+               case NC_SCREEN:
+                       if(wmn->data == ND_GPENCIL)
                                ED_region_tag_redraw(ar);
                        break;
        }
@@ -726,6 +730,7 @@ void ED_spacetype_clip(void)
        art->regionid= RGN_TYPE_TOOLS;
        art->prefsizex= UI_COMPACT_PANEL_WIDTH;
        art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_UI;
+       art->listener= clip_props_area_listener;
        art->init= clip_tools_area_init;
        art->draw= clip_tools_area_draw;
 
index 9ba63ec243ffe17539f96bf3d0e1d438c343a80d..d5e0951c119473e54dfdc2e288848b6347e36d1b 100644 (file)
@@ -585,8 +585,8 @@ typedef struct SpaceClip {
        /* current stabilization data */
        float loc[2], scale, angle;     /* pre-composed stabilization data */
        int pad;
-       float stabmat[4][4];            /* current stabilization matrix, defined when drawing
-                                                          and used for mouse position calculation */
+       float stabmat[4][4], unistabmat[4][4];          /* current stabilization matrix and the same matrix in unified space,
+                                                                                                  defined when drawing and used for mouse position calculation */
 } SpaceClip;
 
 /* view3d  Now in DNA_view3d_types.h */