Merging r41564 through r41596 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 6 Nov 2011 18:38:20 +0000 (18:38 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 6 Nov 2011 18:38:20 +0000 (18:38 +0000)
1  2 
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_conversions.c
source/blender/makesdna/DNA_scene_types.h

@@@ -2063,7 -2063,22 +2063,22 @@@ class VIEW3D_PT_view3d_properties(Panel
          subcol.label(text="Local Camera:")
          subcol.prop(view, "camera", text="")
  
-         layout.column().prop(view, "cursor_location")
+ class VIEW3D_PT_view3d_cursor(Panel):
+     bl_space_type = 'VIEW_3D'
+     bl_region_type = 'UI'
+     bl_label = "3D Cursor"
+     @classmethod
+     def poll(cls, context):
+         view = context.space_data
+         return (view)
+     def draw(self, context):
+         layout = self.layout
+         view = context.space_data
+         layout.column().prop(view, "cursor_location", text="Location")
  
  
  class VIEW3D_PT_view3d_name(Panel):
@@@ -2149,16 -2164,6 +2164,16 @@@ class VIEW3D_PT_view3d_display(Panel)
  
          layout.separator()
  
 +        layout.prop(view, "show_reconstruction")
 +        if view.show_reconstruction:
 +            layout.label(text="Bundle type:")
 +            layout.prop(view, "bundle_draw_type", text="")
 +            layout.prop(view, "bundle_draw_size")
 +            layout.prop(view, "show_bundle_name")
 +            layout.prop(view, "show_camera_path")
 +
 +        layout.separator()
 +
          region = view.region_quadview
  
          layout.operator("screen.region_quadview", text="Toggle Quad View")
@@@ -2264,10 -2269,8 +2279,10 @@@ class VIEW3D_PT_background_image(Panel)
              box = layout.box()
              row = box.row(align=True)
              row.prop(bg, "show_expanded", text="", emboss=False)
 -            if bg.image:
 +            if bg.source == 'IMAGE' and bg.image:
                  row.prop(bg.image, "name", text="", emboss=False)
 +            if bg.source == 'MOVIE' and bg.clip:
 +                row.prop(bg.clip, "name", text="", emboss=False)
              else:
                  row.label(text="Not Set")
              row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
  
              if bg.show_expanded:
                  row = box.row()
 -                row.template_ID(bg, "image", open="image.open")
 -                if (bg.image):
 -                    box.template_image(bg, "image", bg.image_user, compact=True)
 +                row.prop(bg, "source", expand=True)
 +
 +                hasbg = False
 +                if bg.source == 'IMAGE':
 +                    row = box.row()
 +                    row.template_ID(bg, "image", open="image.open")
 +                    if (bg.image):
 +                        box.template_image(bg, "image", bg.image_user, compact=True)
 +                        hasbg = True
 +
 +                elif bg.source == 'MOVIE':
 +                    has_clip = False
 +                    box.prop(bg, 'use_camera_clip')
 +
 +                    column = box.column()
 +                    column.active = not bg.use_camera_clip
 +                    column.template_ID(bg, "clip", open="clip.open")
 +
 +                    if bg.clip:
 +                        column.template_movieclip(bg, "clip", compact=True)
 +
 +                    if bg.use_camera_clip or bg.clip:
 +                        hasbg = True
 +
 +                    column = box.column()
 +                    column.active = hasbg
 +                    column.prop(bg.clip_user, "proxy_render_size", text="")
 +                    column.prop(bg.clip_user, "use_render_undistorted")
  
 +                if hasbg:
                      box.prop(bg, "opacity", slider=True)
                      if bg.view_axis != 'CAMERA':
                          box.prop(bg, "size")
@@@ -48,7 -48,6 +48,7 @@@ struct Group
  struct bAction;
  struct RenderData;
  struct rctf;
 +struct MovieClip;
  
  void clear_workob(struct Object *workob);
  void what_does_parent(struct Scene *scene, struct Object *ob, struct Object *workob);
@@@ -87,7 -86,6 +87,6 @@@ void set_mblur_offs(float blur)
  void set_field_offs(float field);
  void disable_speed_curve(int val);
  
- float bsystem_time(struct Scene *scene, struct Object *ob, float cfra, float ofs);
  void object_scale_to_mat3(struct Object *ob, float mat[][3]);
  void object_rot_to_mat3(struct Object *ob, float mat[][3]);
  void object_mat3_to_rot(struct Object *ob, float mat[][3], short use_compat);
@@@ -101,7 -99,6 +100,7 @@@ struct Object *object_pose_armature_get
  void where_is_object_time(struct Scene *scene, struct Object *ob, float ctime);
  void where_is_object(struct Scene *scene, struct Object *ob);
  void where_is_object_simul(struct Scene *scene, struct Object *ob);
 +void where_is_object_mat(struct Scene *scene, struct Object *ob, float obmat[4][4]);
  
  struct BoundBox *unit_boundbox(void);
  void boundbox_set_from_min_max(struct BoundBox *bb, float min[3], float max[3]);
@@@ -109,7 -106,7 +108,7 @@@ struct BoundBox *object_get_boundbox(st
  void object_get_dimensions(struct Object *ob, float *value);
  void object_set_dimensions(struct Object *ob, const float *value);
  void object_boundbox_flag(struct Object *ob, int flag, int set);
- void minmax_object(struct Object *ob, float *min, float *max);
+ void minmax_object(struct Object *ob, float min[3], float max[3]);
  int minmax_object_duplis(struct Scene *scene, struct Object *ob, float *min, float *max);
  void solve_tracking (struct Object *ob, float targetmat[][4]);
  int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3]);
@@@ -120,7 -117,6 +119,6 @@@ void object_tfm_restore(struct Object *
  void object_handle_update(struct Scene *scene, struct Object *ob);
  void object_sculpt_modifiers_changed(struct Object *ob);
  
- float give_timeoffset(struct Object *ob);
  int give_obdata_texspace(struct Object *ob, short **texflag, float **loc, float **size, float **rot);
  
  int object_insert_ptcache(struct Object *ob);
@@@ -131,8 -127,6 +129,8 @@@ int object_is_modified(struct Scene *sc
  
  void object_relink(struct Object *ob);
  
 +struct MovieClip *object_get_movieclip(struct Scene *scene, struct Object *ob, int use_default);
 +
  #ifdef __cplusplus
  }
  #endif
@@@ -292,7 -292,7 +292,7 @@@ void DM_to_meshkey(DerivedMesh *dm, Mes
        mvert=dm->getVertDataArray(dm, CD_MVERT);
        
        for(a=0; a<kb->totelem; a++, fp+=3, mvert++) {
-               VECCOPY(fp, mvert->co);
+               copy_v3_v3(fp, mvert->co);
        }
  }
  
@@@ -604,12 -604,12 +604,12 @@@ static void emDM_drawUVEdges(DerivedMes
  static void emDM__calcFaceCent(EditFace *efa, float cent[3], float (*vertexCos)[3])
  {
        if (vertexCos) {
-               VECCOPY(cent, vertexCos[(int) efa->v1->tmp.l]);
+               copy_v3_v3(cent, vertexCos[(int) efa->v1->tmp.l]);
                add_v3_v3(cent, vertexCos[(int) efa->v2->tmp.l]);
                add_v3_v3(cent, vertexCos[(int) efa->v3->tmp.l]);
                if (efa->v4) add_v3_v3(cent, vertexCos[(int) efa->v4->tmp.l]);
        } else {
-               VECCOPY(cent, efa->v1->co);
+               copy_v3_v3(cent, efa->v1->co);
                add_v3_v3(cent, efa->v2->co);
                add_v3_v3(cent, efa->v3->co);
                if (efa->v4) add_v3_v3(cent, efa->v4->co);
@@@ -1184,13 -1184,12 +1184,13 @@@ static void emDM_getVert(DerivedMesh *d
  
        for(i = 0; i < index; ++i) ev = ev->next;
  
-       VECCOPY(vert_r->co, ev->co);
+       copy_v3_v3(vert_r->co, ev->co);
  
        normal_float_to_short_v3(vert_r->no, ev->no);
  
        /* TODO what to do with vert_r->flag? */
        vert_r->bweight = (unsigned char) (ev->bweight*255.0f);
 +      vert_r->flag= ev->f;
  }
  
  static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r)
@@@ -1540,8 -1539,9 +1540,9 @@@ static float *get_editmesh_orco_verts(E
        
        orco = MEM_mallocN(sizeof(float)*3*totvert, "EditMesh Orco");
  
-       for(a=0, eve=em->verts.first; eve; eve=eve->next, a+=3)
-               VECCOPY(orco+a, eve->co);
+       for(a=0, eve=em->verts.first; eve; eve=eve->next, a+=3) {
+               copy_v3_v3(orco+a, eve->co);
+       }
        
        return orco;
  }
@@@ -2147,7 -2147,7 +2148,7 @@@ float (*editmesh_get_vertex_cos(EditMes
  
        cos = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos");
        for (i=0,eve=em->verts.first; i<numVerts; i++,eve=eve->next) {
-               VECCOPY(cos[i], eve->co);
+               copy_v3_v3(cos[i], eve->co);
        }
  
        return cos;
@@@ -2655,7 -2655,7 +2656,7 @@@ static void GetPosition(const SMikkTSpa
        //assert(vert_index>=0 && vert_index<4);
        SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
        const float *co= pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].co;
-       VECCOPY(fPos, co);
+       copy_v3_v3(fPos, co);
  }
  
  static void GetTextureCoordinate(const SMikkTSpaceContext * pContext, float fUV[], const int face_num, const int vert_index)
@@@ -2681,7 -2681,7 +2682,7 @@@ static void GetNormal(const SMikkTSpace
        const int smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH);
        if(!smoothnormal) {     // flat
                if(pMesh->precomputedFaceNormals) {
-                       VECCOPY(fNorm, &pMesh->precomputedFaceNormals[3*face_num]);
+                       copy_v3_v3(fNorm, &pMesh->precomputedFaceNormals[3*face_num]);
                }
                else {
                        MFace *mf= &pMesh->mface[face_num];
@@@ -2708,7 -2708,7 +2709,7 @@@ static void SetTSpace(const SMikkTSpace
        //assert(vert_index>=0 && vert_index<4);
        SGLSLMeshToTangent * pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
        float * pRes = pMesh->tangent[4*face_num+iVert];
-       VECCOPY(pRes, fvTangent);
+       copy_v3_v3(pRes, fvTangent);
        pRes[3]=fSign;
  }
  
@@@ -46,7 -46,6 +46,7 @@@
  #include "DNA_material_types.h"
  #include "DNA_meta_types.h"
  #include "DNA_meshdata_types.h"
 +#include "DNA_movieclip_types.h"
  #include "DNA_scene_types.h"
  #include "DNA_screen_types.h"
  #include "DNA_sequence_types.h"
@@@ -1420,33 -1419,6 +1420,6 @@@ void object_make_proxy(Object *ob, Obje
  
  /* *************** CALC ****************** */
  
- /* there is also a timing calculation in drawobject() */
- // XXX THIS CRUFT NEEDS SERIOUS RECODING ASAP!
- /* ob can be NULL */
- float bsystem_time(struct Scene *scene, Object *UNUSED(ob), float cfra, float ofs)
- {
-       /* returns float ( see BKE_curframe in scene.c) */
-       cfra += scene->r.subframe;
-       
-       /* global time */
-       if (scene)
-               cfra*= scene->r.framelen;       
-       
- #if 0 // XXX old animation system
-       if (ob) {
-               /* ofset frames */
-               if ((ob->ipoflag & OB_OFFS_PARENT) && (ob->partype & PARSLOW)==0) 
-                       cfra-= give_timeoffset(ob);
-       }
- #endif // XXX old animation system
-       
-       cfra-= ofs;
-       return cfra;
- }
  void object_scale_to_mat3(Object *ob, float mat[][3])
  {
        float vec[3];
        size_to_mat3( mat,vec);
  }
  
  void object_rot_to_mat3(Object *ob, float mat[][3])
  {
        float rmat[3][3], dmat[3][3];
@@@ -1593,12 -1564,6 +1565,6 @@@ static void ob_parcurve(Scene *scene, O
                makeDispListCurveTypes(scene, par, 0);
        if(cu->path==NULL) return;
        
-       /* exception, timeoffset is regarded as distance offset */
-       if(cu->flag & CU_OFFS_PATHDIST) {
-               timeoffs = give_timeoffset(ob);
-               SWAP(float, sf_orig, ob->sf);
-       }
-       
        /* catch exceptions: feature for nla stride editing */
        if(ob->ipoflag & OB_DISABLE_PATH) {
                ctime= 0.0f;
                CLAMP(ctime, 0.0f, 1.0f);
        }
        else {
-               ctime= scene->r.cfra - give_timeoffset(ob);
+               ctime= scene->r.cfra;
                if (IS_EQF(cu->pathlen, 0.0f) == 0)
                        ctime /= cu->pathlen;
                
@@@ -1845,30 -1810,11 +1811,30 @@@ void set_no_parent_ipo(int val
        no_parent_ipo= val;
  }
  
 -void where_is_object_time(Scene *scene, Object *ob, float ctime)
 +static int where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat[4][4])
  {
 -      float *fp1, *fp2, slowmat[4][4] = MAT4_UNITY;
 -      float stime=ctime, fac1, fac2;
 +      float *fp1, *fp2;
 +      float fac1, fac2;
        int a;
-       fac1= ( 1.0f / (1.0f + (float)fabs(give_timeoffset(ob))) );
 +
 +      // include framerate
++      fac1= ( 1.0f / (1.0f + (float)fabs(ob->sf)) );
 +      if(fac1 >= 1.0f) return 0;
 +      fac2= 1.0f-fac1;
 +
 +      fp1= obmat[0];
 +      fp2= slowmat[0];
 +      for(a=0; a<16; a++, fp1++, fp2++) {
 +              fp1[0]= fac1*fp1[0] + fac2*fp2[0];
 +      }
 +
 +      return 1;
 +}
 +
 +void where_is_object_time(Scene *scene, Object *ob, float ctime)
 +{
 +      float slowmat[4][4] = MAT4_UNITY;
 +      float stime=ctime;
        
        /* new version: correct parent+vertexparent and track+parent */
        /* this one only calculates direct attached parent and track */
        if(ob->parent) {
                Object *par= ob->parent;
                
-               // XXX depreceated - animsys
-               if(ob->ipoflag & OB_OFFS_PARENT) ctime-= give_timeoffset(ob);
-               
                /* hurms, code below conflicts with depgraph... (ton) */
                /* and even worse, it gives bad effects for NLA stride too (try ctime != par->ctime, with MBlur) */
                if(no_parent_ipo==0 && stime != par->ctime) {
                        
                        if(par->proxy_from);    // was a copied matrix, no where_is! bad...
                        else where_is_object_time(scene, par, ctime);
+                       
                        solve_parenting(scene, ob, par, ob->obmat, slowmat, 0);
+                       
                        *par= tmp;
                }
                else
                        solve_parenting(scene, ob, par, ob->obmat, slowmat, 0);
                
+               /* "slow parent" is definitely not threadsafe, and may also give bad results jumping around 
+                * An old-fashioned hack which probably doesn't really cut it anymore
+                */
                if(ob->partype & PARSLOW) {
 -                      // include framerate
 -                      fac1= ( 1.0f / (1.0f + (float)fabs(ob->sf)) );
 -                      if(fac1 >= 1.0f) return;
 -                      fac2= 1.0f-fac1;
 -                      
 -                      fp1= ob->obmat[0];
 -                      fp2= slowmat[0];
 -                      for(a=0; a<16; a++, fp1++, fp2++) {
 -                              fp1[0]= fac1*fp1[0] + fac2*fp2[0];
 -                      }
 +                      if(!where_is_object_parslow(ob, ob->obmat, slowmat))
 +                              return;
                }
        }
        else {
        else                                                    ob->transflag &= ~OB_NEG_SCALE;
  }
  
 +/* get object transformation matrix without recalculating dependencies and
 +   constraints -- assume dependencies are already solved by depsgraph.
 +   no changes to object and it's parent would be done.
 +   used for bundles orientation in 3d space relative to parented blender camera */
 +void where_is_object_mat(Scene *scene, Object *ob, float obmat[4][4])
 +{
 +      float slowmat[4][4] = MAT4_UNITY;
 +
 +      if(ob->parent) {
 +              Object *par= ob->parent;
 +
 +              solve_parenting(scene, ob, par, obmat, slowmat, 1);
 +
 +              if(ob->partype & PARSLOW)
 +                      where_is_object_parslow(ob, obmat, slowmat);
 +      }
 +      else {
 +              object_to_mat4(ob, obmat);
 +      }
 +}
 +
  static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul)
  {
        float totmat[4][4];
@@@ -2039,7 -1972,6 +2005,6 @@@ void where_is_object_simul(Scene *scene
  for a lamp that is the child of another object */
  {
        Object *par;
-       //Ipo *ipo;
        float *fp1, *fp2;
        float slowmat[4][4];
        float fac1, fac2;
                par= ob->parent;
                
                solve_parenting(scene, ob, par, ob->obmat, slowmat, 1);
+               
                if(ob->partype & PARSLOW) {
-                       fac1= (float)(1.0/(1.0+ fabs(give_timeoffset(ob))));
+                       fac1= (float)(1.0/(1.0+ fabs(ob->sf)));
                        fac2= 1.0f-fac1;
                        fp1= ob->obmat[0];
                        fp2= slowmat[0];
                                fp1[0]= fac1*fp1[0] + fac2*fp2[0];
                        }
                }
-               
        }
        else {
                object_to_mat4(ob, ob->obmat);
@@@ -2190,7 -2120,7 +2153,7 @@@ void object_set_dimensions(Object *ob, 
        }
  }
  
- void minmax_object(Object *ob, float *min, float *max)
+ void minmax_object(Object *ob, float min[3], float max[3])
  {
        BoundBox bb;
        float vec[3];
@@@ -2587,15 -2517,6 +2550,6 @@@ void object_sculpt_modifiers_changed(Ob
        }
  }
  
- float give_timeoffset(Object *ob)
- {
-       if ((ob->ipoflag & OB_OFFS_PARENTADD) && ob->parent) {
-               return ob->sf + give_timeoffset(ob->parent);
-       } else {
-               return ob->sf;
-       }
- }
  int give_obdata_texspace(Object *ob, short **texflag, float **loc, float **size, float **rot)
  {
        
@@@ -2890,28 -2811,3 +2844,28 @@@ void object_relink(Object *ob
        ID_NEW(ob->proxy);
        ID_NEW(ob->proxy_group);
  }
 +
 +MovieClip *object_get_movieclip(Scene *scene, Object *ob, int use_default)
 +{
 +      MovieClip *clip= use_default ? scene->clip : NULL;
 +      bConstraint *con= ob->constraints.first, *scon= NULL;
 +
 +      while(con){
 +              if(con->type==CONSTRAINT_TYPE_CAMERASOLVER){
 +                      if(scon==NULL || (scon->flag&CONSTRAINT_OFF))
 +                              scon= con;
 +              }
 +
 +              con= con->next;
 +      }
 +
 +      if(scon) {
 +              bCameraSolverConstraint *solver= scon->data;
 +              if((solver->flag&CAMERASOLVER_ACTIVECLIP)==0)
 +                      clip= solver->clip;
 +              else
 +                      clip= scene->clip;
 +      }
 +
 +      return clip;
 +}
@@@ -88,7 -88,6 +88,7 @@@
  #include "DNA_space_types.h"
  #include "DNA_vfont_types.h"
  #include "DNA_world_types.h"
 +#include "DNA_movieclip_types.h"
  
  #include "MEM_guardedalloc.h"
  
  #include "BKE_screen.h"
  #include "BKE_sequencer.h"
  #include "BKE_texture.h" // for open_plugin_tex
 +#include "BKE_tracking.h"
  #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
  #include "BKE_sound.h"
  
@@@ -1039,8 -1037,6 +1039,8 @@@ void blo_freefiledata(FileData *fd
                        oldnewmap_free(fd->globmap);
                if (fd->imamap)
                        oldnewmap_free(fd->imamap);
 +              if (fd->movieclipmap)
 +                      oldnewmap_free(fd->movieclipmap);
                if (fd->libmap && !(fd->flags & FD_FLAGS_NOT_MY_LIBMAP))
                        oldnewmap_free(fd->libmap);
                if (fd->bheadmap)
@@@ -1116,13 -1112,6 +1116,13 @@@ static void *newimaadr(FileData *fd, vo
        return NULL;
  }
  
 +static void *newmclipadr(FileData *fd, void *adr)              /* used to restore movie clip data after undo */
 +{
 +      if(fd->movieclipmap && adr)
 +              return oldnewmap_lookup_and_inc(fd->movieclipmap, adr);
 +      return NULL;
 +}
 +
  
  static void *newlibadr(FileData *fd, void *lib, void *adr)            /* only lib data */
  {
@@@ -1251,62 -1240,6 +1251,62 @@@ void blo_end_image_pointer_map(FileDat
        }
  }
  
 +void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain)
 +{
 +      MovieClip *clip= oldmain->movieclip.first;
 +      Scene *sce= oldmain->scene.first;
 +
 +      fd->movieclipmap= oldnewmap_new();
 +
 +      for(;clip; clip= clip->id.next) {
 +              if(clip->cache)
 +                      oldnewmap_insert(fd->movieclipmap, clip->cache, clip->cache, 0);
 +
 +              if(clip->tracking.camera.intrinsics)
 +                      oldnewmap_insert(fd->movieclipmap, clip->tracking.camera.intrinsics, clip->tracking.camera.intrinsics, 0);
 +      }
 +
 +      for(; sce; sce= sce->id.next) {
 +              if(sce->nodetree) {
 +                      bNode *node;
 +                      for(node= sce->nodetree->nodes.first; node; node= node->next)
 +                              if(node->type==CMP_NODE_MOVIEDISTORTION)
 +                                      oldnewmap_insert(fd->movieclipmap, node->storage, node->storage, 0);
 +              }
 +      }
 +}
 +
 +/* set old main movie clips caches to zero if it has been restored */
 +/* this works because freeing old main only happens after this call */
 +void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain)
 +{
 +      OldNew *entry= fd->movieclipmap->entries;
 +      MovieClip *clip= oldmain->movieclip.first;
 +      Scene *sce= oldmain->scene.first;
 +      int i;
 +
 +      /* used entries were restored, so we put them to zero */
 +      for (i=0; i<fd->movieclipmap->nentries; i++, entry++) {
 +              if (entry->nr>0)
 +                              entry->newp= NULL;
 +      }
 +
 +      for(;clip; clip= clip->id.next) {
 +              clip->cache= newmclipadr(fd, clip->cache);
 +              clip->tracking.camera.intrinsics= newmclipadr(fd, clip->tracking.camera.intrinsics);
 +      }
 +
 +      for(; sce; sce= sce->id.next) {
 +              if(sce->nodetree) {
 +                      bNode *node;
 +                      for(node= sce->nodetree->nodes.first; node; node= node->next)
 +                              if(node->type==CMP_NODE_MOVIEDISTORTION)
 +                                      node->storage= newmclipadr(fd, node->storage);
 +              }
 +      }
 +}
 +
 +
  /* undo file support: add all library pointers in lookup */
  void blo_add_library_pointer_map(ListBase *mainlist, FileData *fd)
  {
@@@ -2293,11 -2226,7 +2293,11 @@@ static void direct_link_nodetree(FileDa
                link_list(fd, &node->inputs);
                link_list(fd, &node->outputs);
                
 -              node->storage= newdataadr(fd, node->storage);
 +              if(node->type == CMP_NODE_MOVIEDISTORTION) {
 +                      node->storage= newmclipadr(fd, node->storage);
 +              } else
 +                      node->storage= newdataadr(fd, node->storage);
 +
                if(node->storage) {
                        /* could be handlerized at some point */
                        if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
@@@ -4483,7 -4412,7 +4483,7 @@@ static void direct_link_object(FileDat
                         * a hook we need to make sure it gets converted
                         * and free'd, regardless of version.
                         */
-               VECCOPY(hmd->cent, hook->cent);
+               copy_v3_v3(hmd->cent, hook->cent);
                hmd->falloff = hook->falloff;
                hmd->force = hook->force;
                hmd->indexar = hook->indexar;
@@@ -4610,6 -4539,8 +4610,8 @@@ static void lib_link_scene(FileData *fd
                                        marker->camera= newlibadr(fd, sce->id.lib, marker->camera);
                                }
                        }
+ #else
+                       (void)marker;
  #endif
  
                        if(sce->ed)
@@@ -4831,7 -4762,6 +4833,7 @@@ static void direct_link_scene(FileData 
        if(sce->nodetree)
                direct_link_nodetree(fd, sce->nodetree);
        
 +      sce->clip= newlibadr_us(fd, sce->id.lib, sce->clip);
  }
  
  /* ************ READ WM ***************** */
@@@ -4986,7 -4916,6 +4988,7 @@@ static void lib_link_screen(FileData *f
  
                                                for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
                                                        bgpic->ima= newlibadr_us(fd, sc->id.lib, bgpic->ima);
 +                                                      bgpic->clip= newlibadr_us(fd, sc->id.lib, bgpic->clip);
                                                }
                                                if(v3d->localvd) {
                                                        v3d->localvd->camera= newlibadr(fd, sc->id.lib, v3d->localvd->camera);
                                                
                                                snode->linkdrag.first = snode->linkdrag.last = NULL;
                                        }
 +                                      else if(sl->spacetype==SPACE_CLIP) {
 +                                              SpaceClip *sclip= (SpaceClip *)sl;
 +
 +                                              sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
 +
 +                                              sclip->scopes.track_preview = NULL;
 +                                              sclip->scopes.ok = 0;
 +                                      }
                                }
                                sa= sa->next;
                        }
@@@ -5204,7 -5125,6 +5206,7 @@@ void lib_link_screen_restore(Main *newm
                                        
                                        for(bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
                                                bgpic->ima= restore_pointer_by_name(newmain, (ID *)bgpic->ima, 1);
 +                                              bgpic->clip= restore_pointer_by_name(newmain, (ID *)bgpic->clip, 1);
                                        }
                                        if(v3d->localvd) {
                                                /*Base *base;*/
                                                snode->nodetree= restore_pointer_by_name(newmain, &snode->nodetree->id, 1);
                                        }
                                }
 +                              else if(sl->spacetype==SPACE_CLIP) {
 +                                      SpaceClip *sclip= (SpaceClip *)sl;
 +
 +                                      sclip->clip= restore_pointer_by_name(newmain, (ID *)sclip->clip, 1);
 +
 +                                      sclip->scopes.ok = 0;
 +                              }
                        }
                        sa= sa->next;
                }
@@@ -5837,55 -5750,6 +5839,55 @@@ static void lib_link_group(FileData *fd
        }
  }
  
 +/* ***************** READ MOVIECLIP *************** */
 +
 +static void direct_link_movieclip(FileData *fd, MovieClip *clip)
 +{
 +      MovieTracking *tracking= &clip->tracking;
 +      MovieTrackingTrack *track;
 +
 +      if(fd->movieclipmap) clip->cache= newmclipadr(fd, clip->cache);
 +      else clip->cache= NULL;
 +
 +      if(fd->movieclipmap) clip->tracking.camera.intrinsics= newmclipadr(fd, clip->tracking.camera.intrinsics);
 +      else clip->tracking.camera.intrinsics= NULL;
 +
 +      tracking->reconstruction.cameras= newdataadr(fd, tracking->reconstruction.cameras);
 +
 +      link_list(fd, &tracking->tracks);
 +
 +      track= tracking->tracks.first;
 +      while(track) {
 +              track->markers= newdataadr(fd, track->markers);
 +
 +              track= track->next;
 +      }
 +
 +      clip->tracking.act_track= newdataadr(fd, clip->tracking.act_track);
 +
 +      clip->anim= NULL;
 +      clip->tracking_context= NULL;
 +
 +      clip->tracking.stabilization.ok= 0;
 +      clip->tracking.stabilization.scaleibuf= NULL;
 +      clip->tracking.stabilization.rot_track= newdataadr(fd, clip->tracking.stabilization.rot_track);
 +}
 +
 +static void lib_link_movieclip(FileData *fd, Main *main)
 +{
 +      MovieClip *clip;
 +
 +      clip= main->movieclip.first;
 +      while(clip) {
 +              if(clip->id.flag & LIB_NEEDLINK) {
 +                      clip->gpd= newlibadr_us(fd, clip->id.lib, clip->gpd);
 +
 +                      clip->id.flag -= LIB_NEEDLINK;
 +              }
 +              clip= clip->id.next;
 +      }
 +}
 +
  /* ************** GENERAL & MAIN ******************** */
  
  
@@@ -5920,7 -5784,6 +5922,7 @@@ static const char *dataname(short id_co
                case ID_BR: return "Data from BR";
                case ID_PA: return "Data from PA";
                case ID_GD: return "Data from GD";
 +              case ID_MC: return "Data from MC";
        }
        return "Data from Lib Block";
        
@@@ -6090,9 -5953,6 +6092,9 @@@ static BHead *read_libblock(FileData *f
                case ID_GD:
                        direct_link_gpencil(fd, (bGPdata *)id);
                        break;
 +              case ID_MC:
 +                      direct_link_movieclip(fd, (MovieClip *)id);
 +                      break;
        }
        
        /*link direct data of ID properties*/
@@@ -7295,7 -7155,7 +7297,7 @@@ static void do_versions(FileData *fd, L
                while(ob) {
                        if(ob->transflag & 1) {
                                ob->transflag -= 1;
-                               ob->ipoflag |= OB_OFFS_OB;
+                               //ob->ipoflag |= OB_OFFS_OB;
                        }
                        ob= ob->id.next;
                }
                }
                ob= main->object.first;
                while(ob) {
-                       ob->ipoflag |= OB_OFFS_PARENT;
+                       //ob->ipoflag |= OB_OFFS_PARENT;
                        if(ob->dt==0) ob->dt= OB_SOLID;
                        ob= ob->id.next;
                }
                                part->obfac = paf->obfac;
                                part->randfac = paf->randfac * 25.0f;
                                part->dampfac = paf->damp;
-                               VECCOPY(part->acc, paf->force);
+                               copy_v3_v3(part->acc, paf->force);
  
                                /* flags */
                                if(paf->stype & PAF_VECT) {
                                tot= MIN2(me->totvert, key->refkey->totelem);
  
                                for(a=0; a<tot; a++, data+=3)
-                                       VECCOPY(me->mvert[a].co, data)
+                                       copy_v3_v3(me->mvert[a].co, data);
                        }
                }
  
                                tot= MIN2(lt->pntsu*lt->pntsv*lt->pntsw, key->refkey->totelem);
  
                                for(a=0; a<tot; a++, data+=3)
-                                       VECCOPY(lt->def[a].vec, data)
+                                       copy_v3_v3(lt->def[a].vec, data);
                        }
                }
  
                                                BezTriple *bezt = nu->bezt;
  
                                                for(a=0; a<nu->pntsu; a++, bezt++) {
-                                                       VECCOPY(bezt->vec[0], data); data+=3;
-                                                       VECCOPY(bezt->vec[1], data); data+=3;
-                                                       VECCOPY(bezt->vec[2], data); data+=3;
+                                                       copy_v3_v3(bezt->vec[0], data); data+=3;
+                                                       copy_v3_v3(bezt->vec[1], data); data+=3;
+                                                       copy_v3_v3(bezt->vec[2], data); data+=3;
                                                        bezt->alfa= *data; data++;
                                                }
                                        }
                                                BPoint *bp = nu->bp;
  
                                                for(a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
-                                                       VECCOPY(bp->vec, data); data+=3;
+                                                       copy_v3_v3(bp->vec, data); data+=3;
                                                        bp->alfa= *data; data++;
                                                }
                                        }
                                ma= ma->id.next;
                        }
                }
 -
        }
  
        if (main->versionfile < 260){
                                }
                        }
                }
 -
        }
  
        if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 1)){
  
        /* put compatibility code here until next subversion bump */
        {
 -              
 +              {
 +                      bScreen *sc;
 +                      Camera *cam;
 +                      MovieClip *clip;
 +
 +                      for (sc= main->screen.first; sc; sc= sc->id.next) {
 +                              ScrArea *sa;
 +                              for (sa= sc->areabase.first; sa; sa= sa->next) {
 +                                      SpaceLink *sl;
 +                                      for (sl= sa->spacedata.first; sl; sl= sl->next) {
 +                                              if(sl->spacetype==SPACE_VIEW3D) {
 +                                                      View3D *v3d= (View3D *)sl;
 +                                                      if(v3d->bundle_size==0.0f) {
 +                                                              v3d->bundle_size= 0.2f;
 +                                                              v3d->flag2 |= V3D_SHOW_RECONSTRUCTION;
 +                                                      }
 +                                                      else if(sl->spacetype==SPACE_CLIP) {
 +                                                              SpaceClip *sc= (SpaceClip *)sl;
 +                                                              if(sc->scopes.track_preview_height==0)
 +                                                                      sc->scopes.track_preview_height= 120;
 +                                                      }
 +
 +                                                      if(v3d->bundle_drawtype==0)
 +                                                              v3d->bundle_drawtype= OB_PLAINAXES;
 +                                              }
 +                                      }
 +                              }
 +                      }
 +
 +                      for(cam= main->camera.first; cam; cam= cam->id.next) {
 +                              if (cam->sensor_x < 0.01)
 +                                      cam->sensor_x = DEFAULT_SENSOR_WIDTH;
 +
 +                              if (cam->sensor_y < 0.01)
 +                                      cam->sensor_y = DEFAULT_SENSOR_HEIGHT;
 +                      }
 +
 +                      for (clip= main->movieclip.first; clip; clip= clip->id.next) {
 +                              MovieTrackingTrack *track;
 +
 +                              if(clip->aspx<1.0f) {
 +                                      clip->aspx= 1.0f;
 +                                      clip->aspy= 1.0f;
 +                              }
 +
 +                              /* XXX: a bit hacky, probably include imbuf and use real constants are nicer */
 +                              clip->proxy.build_tc_flag= 7;
 +                              if(clip->proxy.build_size_flag==0)
 +                                      clip->proxy.build_size_flag= 1;
 +
 +                              if(clip->proxy.quality==0)
 +                                      clip->proxy.quality= 90;
 +
 +                              if(clip->tracking.camera.pixel_aspect<0.01f)
 +                                      clip->tracking.camera.pixel_aspect= 1.f;
 +
 +                              track= clip->tracking.tracks.first;
 +                              while(track) {
 +                                      if(track->pyramid_levels==0)
 +                                              track->pyramid_levels= 2;
 +
 +                                      if(track->minimum_correlation==0.0f)
 +                                              track->minimum_correlation= 0.75f;
 +
 +                                      track= track->next;
 +                              }
 +                      }
 +              }
        }
  
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@@ -12433,7 -12228,6 +12435,7 @@@ static void lib_link_all(FileData *fd, 
        lib_link_nodetree(fd, main);    /* has to be done after scene/materials, this will verify group nodes */
        lib_link_brush(fd, main);
        lib_link_particlesettings(fd, main);
 +      lib_link_movieclip(fd, main);
  
        lib_link_mesh(fd, main);                /* as last: tpage images with users at zero */
  
@@@ -13582,7 -13376,7 +13584,7 @@@ static void give_base_to_groups(Main *m
                        ob->dup_group= group;
                        ob->transflag |= OB_DUPLIGROUP;
                        rename_id(&ob->id, group->id.name+2);
-                       VECCOPY(ob->loc, scene->cursor);
+                       copy_v3_v3(ob->loc, scene->cursor);
                }
        }
  }
@@@ -56,7 -56,6 +56,7 @@@
  #include "BKE_idprop.h"
  #include "BKE_report.h"
  #include "BKE_texture.h"
 +#include "BKE_tracking.h"
  #include "BKE_unit.h"
  
  #include "ED_screen.h"
@@@ -260,7 -259,7 +260,7 @@@ static uiBut *ui_but_last(uiBlock *bloc
  static int ui_is_a_warp_but(uiBut *but)
  {
        if(U.uiflag & USER_CONTINUOUS_MOUSE)
 -              if(ELEM3(but->type, NUM, NUMABS, HSVCIRCLE))
 +              if(ELEM4(but->type, NUM, NUMABS, HSVCIRCLE, TRACKPREVIEW))
                        return TRUE;
  
        return FALSE;
@@@ -923,13 -922,6 +923,13 @@@ static void ui_apply_but_WAVEFORM(bCont
        data->applied= 1;
  }
  
 +static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data)
 +{
 +      ui_apply_but_func(C, but);
 +      data->retval= but->retval;
 +      data->applied= 1;
 +}
 +
  
  static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, int interactive)
  {
                data->origstr= NULL;
                data->value= data->origvalue;
                data->origvalue= 0.0;
-               VECCOPY(data->vec, data->origvec);
+               copy_v3_v3(data->vec, data->origvec);
                data->origvec[0]= data->origvec[1]= data->origvec[2]= 0.0f;
        }
        else {
                case WAVEFORM:
                        ui_apply_but_WAVEFORM(C, but, data);
                        break;
 +              case TRACKPREVIEW:
 +                      ui_apply_but_TRACKPREVIEW(C, but, data);
 +                      break;
                default:
                        break;
        }
@@@ -2132,7 -2121,7 +2132,7 @@@ static void ui_blockopen_begin(bContex
                        break;
                case COL:
                        ui_get_but_vectorf(but, data->origvec);
-                       VECCOPY(data->vec, data->origvec);
+                       copy_v3_v3(data->vec, data->origvec);
                        but->editvec= data->vec;
  
                        handlefunc= ui_block_func_COL;
@@@ -4265,88 -4254,6 +4265,88 @@@ static int ui_do_but_LINK(bContext *C, 
        return WM_UI_HANDLER_CONTINUE;
  }
  
 +static int ui_numedit_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data, int mx, int my, int shift)
 +{
 +      MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
 +      int changed= 1;
 +      float dx, dy;
 +
 +      dx = mx - data->draglastx;
 +      dy = my - data->draglasty;
 +
 +      if(shift) {
 +              dx /= 5.0f;
 +              dy /= 5.0f;
 +      }
 +
 +      if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
 +               /* resize preview widget itself */
 +              scopes->track_preview_height = (but->y2 - but->y1) + (data->dragstarty - my);
 +      } else {
 +              if(scopes->marker) {
 +                      if(scopes->marker->framenr!=scopes->framenr)
 +                              scopes->marker= BKE_tracking_ensure_marker(scopes->track, scopes->framenr);
 +
 +                      scopes->marker->flag&= ~(MARKER_DISABLED|MARKER_TRACKED);
 +                      scopes->marker->pos[0]+= -dx*scopes->slide_scale[0] / (but->block->maxx-but->block->minx);
 +                      scopes->marker->pos[1]+= -dy*scopes->slide_scale[1] / (but->block->maxy-but->block->miny);
 +
 +                      WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
 +              }
 +
 +              scopes->ok= 0;
 +      }
 +
 +      data->draglastx= mx;
 +      data->draglasty= my;
 +
 +      return changed;
 +}
 +
 +static int ui_do_but_TRACKPREVIEW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event)
 +{
 +      int mx, my;
 +
 +      mx= event->x;
 +      my= event->y;
 +      ui_window_to_block(data->region, block, &mx, &my);
 +
 +      if(data->state == BUTTON_STATE_HIGHLIGHT) {
 +              if(event->type==LEFTMOUSE && event->val==KM_PRESS) {
 +                      data->dragstartx= mx;
 +                      data->dragstarty= my;
 +                      data->draglastx= mx;
 +                      data->draglasty= my;
 +                      button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
 +
 +                      /* also do drag the first time */
 +                      if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
 +                              ui_numedit_apply(C, block, but, data);
 +
 +                      return WM_UI_HANDLER_BREAK;
 +              }
 +      }
 +      else if(data->state == BUTTON_STATE_NUM_EDITING) {
 +              if(event->type == ESCKEY) {
 +                      data->cancel= 1;
 +                      data->escapecancel= 1;
 +                      button_activate_state(C, but, BUTTON_STATE_EXIT);
 +              }
 +              else if(event->type == MOUSEMOVE) {
 +                      if(mx!=data->draglastx || my!=data->draglasty) {
 +                              if(ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift))
 +                                      ui_numedit_apply(C, block, but, data);
 +                      }
 +              }
 +              else if(event->type==LEFTMOUSE && event->val!=KM_PRESS) {
 +                      button_activate_state(C, but, BUTTON_STATE_EXIT);
 +              }
 +              return WM_UI_HANDLER_BREAK;
 +      }
 +
 +      return WM_UI_HANDLER_CONTINUE;
 +}
 +
  static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
  {
        uiBut *but = (uiBut *)arg1;
@@@ -4884,9 -4791,6 +4884,9 @@@ static int ui_do_button(bContext *C, ui
        case INLINK:
                retval= ui_do_but_LINK(C, but, data, event);
                break;
 +      case TRACKPREVIEW:
 +              retval= ui_do_but_TRACKPREVIEW(C, block, but, data, event);
 +              break;
        }
        
        return retval;
@@@ -5823,7 -5727,7 +5823,7 @@@ static void ui_handle_button_return_sub
        /* copy over return values from the closing menu */
        if(menu->menuretval == UI_RETURN_OK || menu->menuretval == UI_RETURN_UPDATE) {
                if(but->type == COL)
-                       VECCOPY(data->vec, menu->retvec)
+                       copy_v3_v3(data->vec, menu->retvec);
                else if(ELEM3(but->type, MENU, ICONROW, ICONTEXTROW))
                        data->value= menu->retvalue;
        }
@@@ -1874,38 -1874,38 +1874,38 @@@ void ui_draw_gradient(rcti *rect, floa
                        break;
                case UI_GRAD_H:
                        hsv_to_rgb(0.0, 1.0, 1.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
-                       VECCOPY(col1[1], col1[0]);
-                       VECCOPY(col1[2], col1[0]);
-                       VECCOPY(col1[3], col1[0]);
+                       copy_v3_v3(col1[1], col1[0]);
+                       copy_v3_v3(col1[2], col1[0]);
+                       copy_v3_v3(col1[3], col1[0]);
                        break;
                case UI_GRAD_S:
                        hsv_to_rgb(1.0, 0.0, 1.0,   &col1[1][0], &col1[1][1], &col1[1][2]);
-                       VECCOPY(col1[0], col1[1]);
-                       VECCOPY(col1[2], col1[1]);
-                       VECCOPY(col1[3], col1[1]);
+                       copy_v3_v3(col1[0], col1[1]);
+                       copy_v3_v3(col1[2], col1[1]);
+                       copy_v3_v3(col1[3], col1[1]);
                        break;
                case UI_GRAD_V:
                        hsv_to_rgb(1.0, 1.0, 0.0,   &col1[2][0], &col1[2][1], &col1[2][2]);
-                       VECCOPY(col1[0], col1[2]);
-                       VECCOPY(col1[1], col1[2]);
-                       VECCOPY(col1[3], col1[2]);
+                       copy_v3_v3(col1[0], col1[2]);
+                       copy_v3_v3(col1[1], col1[2]);
+                       copy_v3_v3(col1[3], col1[2]);
                        break;
                default:
                        assert(!"invalid 'type' argument");
                        hsv_to_rgb(1.0, 1.0, 1.0,   &col1[2][0], &col1[2][1], &col1[2][2]);
-                       VECCOPY(col1[0], col1[2]);
-                       VECCOPY(col1[1], col1[2]);
-                       VECCOPY(col1[3], col1[2]);                      
+                       copy_v3_v3(col1[0], col1[2]);
+                       copy_v3_v3(col1[1], col1[2]);
+                       copy_v3_v3(col1[3], col1[2]);
        }
        
        /* old below */
        
        for(dx=0.0f; dx<1.0f; dx+= 0.05f) {
                // previous color
-               VECCOPY(col0[0], col1[0]);
-               VECCOPY(col0[1], col1[1]);
-               VECCOPY(col0[2], col1[2]);
-               VECCOPY(col0[3], col1[3]);
+               copy_v3_v3(col0[0], col1[0]);
+               copy_v3_v3(col0[1], col1[1]);
+               copy_v3_v3(col0[2], col1[2]);
+               copy_v3_v3(col0[3], col1[3]);
                
                // new color
                switch(type) {
                                break;
                        case UI_GRAD_H:
                                hsv_to_rgb(dx, 1.0, 1.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
-                               VECCOPY(col1[1], col1[0]);
-                               VECCOPY(col1[2], col1[0]);
-                               VECCOPY(col1[3], col1[0]);
+                               copy_v3_v3(col1[1], col1[0]);
+                               copy_v3_v3(col1[2], col1[0]);
+                               copy_v3_v3(col1[3], col1[0]);
                                break;
                        case UI_GRAD_S:
                                hsv_to_rgb(h, dx, 1.0,   &col1[1][0], &col1[1][1], &col1[1][2]);
-                               VECCOPY(col1[0], col1[1]);
-                               VECCOPY(col1[2], col1[1]);
-                               VECCOPY(col1[3], col1[1]);
+                               copy_v3_v3(col1[0], col1[1]);
+                               copy_v3_v3(col1[2], col1[1]);
+                               copy_v3_v3(col1[3], col1[1]);
                                break;
                        case UI_GRAD_V:
                                hsv_to_rgb(h, 1.0, dx,   &col1[2][0], &col1[2][1], &col1[2][2]);
-                               VECCOPY(col1[0], col1[2]);
-                               VECCOPY(col1[1], col1[2]);
-                               VECCOPY(col1[3], col1[2]);
+                               copy_v3_v3(col1[0], col1[2]);
+                               copy_v3_v3(col1[1], col1[2]);
+                               copy_v3_v3(col1[3], col1[2]);
                                break;
                }
                
@@@ -3078,10 -3078,6 +3078,10 @@@ void ui_draw_but(const bContext *C, ARe
                                wt= widget_type(UI_WTYPE_SCROLL);
                                break;
  
 +                      case TRACKPREVIEW:
 +                              ui_draw_but_TRACKPREVIEW(ar, but, &tui->wcol_regular, rect);
 +                              break;
 +
                        default:
                                wt= widget_type(UI_WTYPE_REGULAR);
                }
  #include "BKE_paint.h"
  #include "BKE_particle.h"
  #include "BKE_pointcache.h"
+ #include "BKE_scene.h"
  #include "BKE_unit.h"
 +#include "BKE_movieclip.h"
 +#include "BKE_tracking.h"
  
  #include "smoke_API.h"
  
@@@ -203,40 -202,6 +204,40 @@@ static void view3d_project_short_noclip
        }
  }
  
 +/* same as view3d_project_short_clip but use persmat instead of persmatob for projection */
 +static void view3d_project_short_clip_persmat(ARegion *ar, float *vec, short *adr, int local)
 +{
 +      RegionView3D *rv3d= ar->regiondata;
 +      float fx, fy, vec4[4];
 +
 +      adr[0]= IS_CLIPPED;
 +
 +      /* clipplanes in eye space */
 +      if(rv3d->rflag & RV3D_CLIPPING) {
 +              if(ED_view3d_test_clipping(rv3d, vec, local))
 +                      return;
 +      }
 +
 +      copy_v3_v3(vec4, vec);
 +      vec4[3]= 1.0;
 +
 +      mul_m4_v4(rv3d->persmat, vec4);
 +
 +      /* clipplanes in window space */
 +      if( vec4[3] > (float)BL_NEAR_CLIP ) {   /* is the NEAR clipping cutoff for picking */
 +              fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]);
 +
 +              if( fx>0 && fx<ar->winx) {
 +
 +                      fy= (ar->winy/2)*(1 + vec4[1]/vec4[3]);
 +
 +                      if(fy > 0.0f && fy < (float)ar->winy) {
 +                              adr[0]= (short)floorf(fx);
 +                              adr[1]= (short)floorf(fy);
 +                      }
 +              }
 +      }
 +}
  /* ************************ */
  
  /* check for glsl drawing */
@@@ -768,12 -733,7 +769,12 @@@ void view3d_cached_text_draw_end(View3
        for(vos= strings->first; vos; vos= vos->next) {
                if(mat && !(vos->flag & V3D_CACHE_TEXT_WORLDSPACE))
                        mul_m4_v3(mat, vos->vec);
 -              view3d_project_short_clip(ar, vos->vec, vos->sco, 0);
 +
 +              if(vos->flag&V3D_CACHE_TEXT_GLOBALSPACE)
 +                      view3d_project_short_clip_persmat(ar, vos->vec, vos->sco, 0);
 +              else
 +                      view3d_project_short_clip(ar, vos->vec, vos->sco, 0);
 +
                if(vos->sco[0]!=IS_CLIPPED)
                        tot++;
        }
@@@ -1405,203 -1365,16 +1406,203 @@@ float view3d_camera_border_hack_col[4]
  short view3d_camera_border_hack_test= FALSE;
  #endif
  
 +/* ****************** draw clip data *************** */
 +
 +static void draw_bundle_sphere(void)
 +{
 +      static GLuint displist= 0;
 +
 +      if (displist == 0) {
 +              GLUquadricObj *qobj;
 +
 +              displist= glGenLists(1);
 +              glNewList(displist, GL_COMPILE);
 +
 +              qobj= gluNewQuadric();
 +              gluQuadricDrawStyle(qobj, GLU_FILL);
 +              glShadeModel(GL_SMOOTH);
 +              gluSphere(qobj, 0.05, 8, 8);
 +              glShadeModel(GL_FLAT);
 +              gluDeleteQuadric(qobj);
 +
 +              glEndList();
 +      }
 +
 +      glCallList(displist);
 +}
 +
 +static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, MovieClip *clip, int flag)
 +{
 +      MovieTracking *tracking= &clip->tracking;
 +      MovieTrackingTrack *track;
 +      float mat[4][4], imat[4][4], curcol[4];
 +      unsigned char col[4], scol[4];
 +      int bundlenr= 1;
 +
 +      if((v3d->flag2&V3D_SHOW_RECONSTRUCTION)==0)
 +              return;
 +
 +      if(v3d->flag2&V3D_RENDER_OVERRIDE)
 +              return;
 +
 +      glGetFloatv(GL_CURRENT_COLOR, curcol);
 +
 +      UI_GetThemeColor4ubv(TH_TEXT, col);
 +      UI_GetThemeColor4ubv(TH_SELECT, scol);
 +
 +      BKE_get_tracking_mat(scene, base->object, mat);
 +
 +      glEnable(GL_LIGHTING);
 +      glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
 +      glEnable(GL_COLOR_MATERIAL);
 +      glShadeModel(GL_SMOOTH);
 +
 +      /* current ogl matrix is translated in camera space, bundles should
 +         be rendered in world space, so camera matrix should be "removed"
 +         from current ogl matrix */
 +      invert_m4_m4(imat, base->object->obmat);
 +
 +      glPushMatrix();
 +      glMultMatrixf(imat);
 +      glMultMatrixf(mat);
 +
 +      for ( track= tracking->tracks.first; track; track= track->next) {
 +              int selected= track->flag&SELECT || track->pat_flag&SELECT || track->search_flag&SELECT;
 +              if((track->flag&TRACK_HAS_BUNDLE)==0)
 +                      continue;
 +
 +              if(flag&DRAW_PICKING)
 +                      glLoadName(base->selcol + (bundlenr<<16));
 +
 +              glPushMatrix();
 +                      glTranslatef(track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
 +                      glScalef(v3d->bundle_size/0.05, v3d->bundle_size/0.05, v3d->bundle_size/0.05);
 +
 +                      if(v3d->drawtype==OB_WIRE) {
 +                              glDisable(GL_LIGHTING);
 +                              glDepthMask(0);
 +
 +                              if(selected) {
 +                                      if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
 +                                      else UI_ThemeColor(TH_SELECT);
 +                              } else {
 +                                      if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 +                                      else UI_ThemeColor(TH_WIRE);
 +                              }
 +
 +                              drawaxes(0.05f, v3d->bundle_drawtype);
 +
 +                              glDepthMask(1);
 +                              glEnable(GL_LIGHTING);
 +                      } else if(v3d->drawtype>OB_WIRE) {
 +                              if(v3d->bundle_drawtype==OB_EMPTY_SPHERE) {
 +                                      /* selection outline */
 +                                      if(selected) {
 +                                              if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
 +                                              else UI_ThemeColor(TH_SELECT);
 +
 +                                              glDepthMask(0);
 +                                              glLineWidth(2.f);
 +                                              glDisable(GL_LIGHTING);
 +                                              glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 +
 +                                              draw_bundle_sphere();
 +
 +                                              glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 +                                              glEnable(GL_LIGHTING);
 +                                              glLineWidth(1.f);
 +                                              glDepthMask(1);
 +                                      }
 +
 +                                      if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 +                                      else UI_ThemeColor(TH_BUNDLE_SOLID);
 +
 +                                      draw_bundle_sphere();
 +                              } else {
 +                                      glDisable(GL_LIGHTING);
 +                                      glDepthMask(0);
 +
 +                                      if(selected) {
 +                                              if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
 +                                              else UI_ThemeColor(TH_SELECT);
 +                                      } else {
 +                                              if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
 +                                              else UI_ThemeColor(TH_WIRE);
 +                                      }
 +
 +                                      drawaxes(0.05f, v3d->bundle_drawtype);
 +
 +                                      glDepthMask(1);
 +                                      glEnable(GL_LIGHTING);
 +                              }
 +                      }
 +
 +              glPopMatrix();
 +
 +              if((flag & DRAW_PICKING)==0 && (v3d->flag2&V3D_SHOW_BUNDLENAME)) {
 +                      float pos[3];
 +                      unsigned char tcol[4];
 +
 +                      if(selected) memcpy(tcol, scol, sizeof(tcol));
 +                      else memcpy(tcol, col, sizeof(tcol));
 +
 +                      mul_v3_m4v3(pos, mat, track->bundle_pos);
 +                      view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol);
 +              }
 +
 +              bundlenr++;
 +      }
 +
 +      if((flag & DRAW_PICKING)==0) {
 +              if(v3d->flag2&V3D_SHOW_CAMERAPATH && clip->tracking.reconstruction.camnr) {
 +                      int a= 0;
 +                      MovieTrackingReconstruction *reconstruction= &tracking->reconstruction;
 +                      MovieReconstructedCamera *camera= tracking->reconstruction.cameras;
 +
 +                      glDisable(GL_LIGHTING);
 +                      UI_ThemeColor(TH_CAMERA_PATH);
 +                      glLineWidth(2.0f);
 +
 +                      glBegin(GL_LINE_STRIP);
 +                              for(a= 0; a<reconstruction->camnr; a++, camera++) {
 +                                      glVertex3f(camera->mat[3][0], camera->mat[3][1], camera->mat[3][2]);
 +                              }
 +                      glEnd();
 +
 +                      glLineWidth(1.0f);
 +                      glEnable(GL_LIGHTING);
 +              }
 +      }
 +
 +      glPopMatrix();
 +
 +      /* restore */
 +      glShadeModel(GL_FLAT);
 +      glDisable(GL_COLOR_MATERIAL);
 +      glDisable(GL_LIGHTING);
 +
 +      glColor4fv(curcol);
 +
 +      if(flag&DRAW_PICKING)
 +              glLoadName(base->selcol);
 +}
 +
  /* flag similar to draw_object() */
 -static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int flag)
 +static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int flag)
  {
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
 +      Object *ob= base->object;
        float tvec[3];
        float vec[4][3], asp[2], shift[2], scale[3];
        int i;
        float drawsize;
        const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera);
 +      MovieClip *clip= object_get_movieclip(scene, base->object, 0);
 +
 +      /* draw data for movie clip set as active for scene */
 +      if(clip)
 +              draw_viewport_reconstruction(scene, base, v3d, clip, flag);
  
  #ifdef VIEW3D_CAMERA_BORDER_HACK
        if(is_view && !(G.f & G_PICKSEL)) {
@@@ -3900,7 -3673,7 +3901,7 @@@ static void draw_new_particle_system(Sc
  
        totpart=psys->totpart;
  
-       cfra= bsystem_time(scene, NULL, (float)CFRA, 0.0f);
+       cfra= BKE_curframe(scene);
  
        if(draw_as==PART_DRAW_PATH && psys->pathcache==NULL && psys->childcache==NULL)
                draw_as=PART_DRAW_DOT;
@@@ -5976,7 -5749,6 +5977,6 @@@ void draw_object(Scene *scene, ARegion 
        Object *ob;
        Curve *cu;
        RegionView3D *rv3d= ar->regiondata;
-       //float cfraont;
        float vec1[3], vec2[3];
        unsigned int col=0;
        int /*sel, drawtype,*/ colindex= 0;
        /* no return after this point, otherwise leaks */
        view3d_cached_text_draw_begin();
        
-       /* draw keys? */
- #if 0 // XXX old animation system
-       if(base==(scene->basact) || (base->flag & (SELECT+BA_WAS_SEL))) {
-               if(flag==0 && warning_recursive==0 && ob!=scene->obedit) {
-                       if(ob->ipo && ob->ipo->showkey && (ob->ipoflag & OB_DRAWKEY)) {
-                               ListBase elems;
-                               CfraElem *ce;
-                               float temp[7][3];
-                               warning_recursive= 1;
-                               elems.first= elems.last= 0;
-                               // warning: no longer checks for certain ob-keys only... (so does this need to use the proper ipokeys then?)
-                               make_cfra_list(ob->ipo, &elems); 
-                               cfraont= (scene->r.cfra);
-                               drawtype= v3d->drawtype;
-                               if(drawtype>OB_WIRE) v3d->drawtype= OB_WIRE;
-                               sel= base->flag;
-                               memcpy(temp, &ob->loc, 7*3*sizeof(float));
-                               ipoflag= ob->ipoflag;
-                               ob->ipoflag &= ~OB_OFFS_OB;
-                               set_no_parent_ipo(1);
-                               disable_speed_curve(1);
-                               if ((ob->ipoflag & OB_DRAWKEYSEL)==0) {
-                                       ce= elems.first;
-                                       while(ce) {
-                                               if(!ce->sel) {
-                                                       (scene->r.cfra)= ce->cfra/scene->r.framelen;
-                                                       base->flag= 0;
-                                                       where_is_object_time(scene, ob, (scene->r.cfra));
-                                                       draw_object(scene, ar, v3d, base, 0);
-                                               }
-                                               ce= ce->next;
-                                       }
-                               }
-                               ce= elems.first;
-                               while(ce) {
-                                       if(ce->sel) {
-                                               (scene->r.cfra)= ce->cfra/scene->r.framelen;
-                                               base->flag= SELECT;
-                                               where_is_object_time(scene, ob, (scene->r.cfra));
-                                               draw_object(scene, ar, v3d, base, 0);
-                                       }
-                                       ce= ce->next;
-                               }
-                               set_no_parent_ipo(0);
-                               disable_speed_curve(0);
-                               base->flag= sel;
-                               ob->ipoflag= ipoflag;
-                               /* restore icu->curval */
-                               (scene->r.cfra)= cfraont;
-                               memcpy(&ob->loc, temp, 7*3*sizeof(float));
-                               where_is_object(scene, ob);
-                               v3d->drawtype= drawtype;
-                               BLI_freelistN(&elems);
-                               warning_recursive= 0;
-                       }
-               }
-       }
- #endif // XXX old animation system
        /* patch? children objects with a timeoffs change the parents. How to solve! */
        /* if( ((int)ob->ctime) != F_(scene->r.cfra)) where_is_object(scene, ob); */
        
                                        if(base->flag & (SELECT+BA_WAS_SEL)) {
                                                /* uses darker active color for non-active + selected*/
                                                theme_id= TH_GROUP_ACTIVE;
+                                               
                                                if(scene->basact != base) {
                                                        theme_shade= -16;
                                                }
                        break;
                case OB_CAMERA:
                        if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0 || (rv3d->persp==RV3D_CAMOB && v3d->camera==ob)) /* special exception for active camera */
 -                              drawcamera(scene, v3d, rv3d, ob, flag);
 +                              drawcamera(scene, v3d, rv3d, base, flag);
                        break;
                case OB_SPEAKER:
                        if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
                                        for (ct= targets.first; ct; ct= ct->next) {
                                                /* calculate target's matrix */
                                                if (cti->get_target_matrix) 
-                                                       cti->get_target_matrix(curcon, cob, ct, bsystem_time(scene, ob, (float)(scene->r.cfra), give_timeoffset(ob)));
+                                                       cti->get_target_matrix(curcon, cob, ct, BKE_curframe(scene));
                                                else
                                                        unit_m4(ct->matrix);
                                                
@@@ -48,7 -48,6 +48,7 @@@
  #include "DNA_armature_types.h"
  #include "DNA_constraint_types.h"
  #include "DNA_meshdata_types.h"
 +#include "DNA_movieclip_types.h"
  #include "DNA_scene_types.h"          /* PET modes                    */
  
  #include "RNA_access.h"
@@@ -72,7 -71,6 +72,7 @@@
  #include "ED_markers.h"
  #include "ED_view3d.h"
  #include "ED_mesh.h"
 +#include "ED_clip.h"
  
  #include "UI_view2d.h"
  #include "WM_types.h"
@@@ -157,17 -155,6 +157,17 @@@ void convertViewVec(TransInfo *t, floa
        else if(ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) {
                convertViewVec2D(&t->ar->v2d, vec, dx, dy);
        }
 +      else if(t->spacetype==SPACE_CLIP) {
 +              View2D *v2d = t->view;
 +              float divx, divy;
 +
 +              divx= v2d->mask.xmax-v2d->mask.xmin;
 +              divy= v2d->mask.ymax-v2d->mask.ymin;
 +
 +              vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
 +              vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
 +              vec[2]= 0.0f;
 +      }
  }
  
  void projectIntView(TransInfo *t, float *vec, int *adr)
                adr[0]= out[0];
                adr[1]= out[1];
        }
 +      else if(t->spacetype==SPACE_CLIP) {
 +              UI_view2d_to_region_no_clip(t->view, vec[0], vec[1], adr, adr+1);
 +      }
  }
  
  void projectFloatView(TransInfo *t, float *vec, float *adr)
                if(t->ar->regiontype == RGN_TYPE_WINDOW)
                        project_float_noclip(t->ar, vec, adr);
        }
 -      else if(t->spacetype==SPACE_IMAGE) {
 +      else if(ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) {
                int a[2];
  
                projectIntView(t, vec, a);
@@@ -327,15 -311,6 +327,15 @@@ static void viewRedrawForce(const bCont
                if(sima->lock) WM_event_add_notifier(C, NC_GEOM|ND_DATA, t->obedit->data);
                else ED_area_tag_redraw(t->sa);
        }
 +      else if (t->spacetype==SPACE_CLIP) {
 +              SpaceClip *sc= (SpaceClip*)t->sa->spacedata.first;
 +              MovieClip *clip= ED_space_clip(sc);
 +
 +              /* objects could be parented to tracking data, so send this for viewport refresh */
 +              WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 +
 +              WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
 +      }
  }
  
  static void viewRedrawPost(bContext *C, TransInfo *t)
@@@ -604,18 -579,10 +604,18 @@@ int transformEvent(TransInfo *t, wmEven
                                        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... */
 -                              if(!(t->options & CTX_TEXTURE)) {
 +                              if(!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
                                        if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
                                                
                                                resetTransRestrictions(t);
                        break;
                case RKEY:
                        /* only switch when... */
 -                      if(!(t->options & CTX_TEXTURE)) {
 +                      if(!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
                                if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
  
                                        resetTransRestrictions(t);
@@@ -1535,11 -1502,6 +1535,11 @@@ int initTransform(bContext *C, TransInf
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
                //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
        }
 +      else if(t->spacetype == SPACE_CLIP) {
 +              unit_m3(t->spacemtx);
 +              t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
 +              t->options |= CTX_MOVIECLIP;
 +      }
        else
                unit_m3(t->spacemtx);
  
@@@ -3331,7 -3293,7 +3331,7 @@@ void initTranslation(TransInfo *t
                        t->snap[2] = t->snap[1] * 0.1f;
                }
        }
 -      else if(t->spacetype == SPACE_IMAGE) {
 +      else if(ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) {
                t->snap[0] = 0.0f;
                t->snap[1] = 0.125f;
                t->snap[2] = 0.0625f;
@@@ -3920,7 -3882,7 +3920,7 @@@ int Bevel(TransInfo *t, const int UNUSE
                else {
                        d = distance;
                }
-               VECADDFAC(td->loc,td->center,td->axismtx[0],(*td->val)*d);
+               madd_v3_v3v3fl(td->loc, td->center, td->axismtx[0], (*td->val) * d);
        }
  
        recalcData(t);
@@@ -4885,7 -4847,7 +4885,7 @@@ int doEdgeSlide(TransInfo *t, float per
                                                interp_v2_v2v2(uv_tmp, suv->origuv,  (perc>=0)?suv->uv_up:suv->uv_down, fabs(perc));
                                                fuv_link = suv->fuv_list;
                                                while (fuv_link) {
-                                                       VECCOPY2D(((float *)fuv_link->link), uv_tmp);
+                                                       copy_v2_v2(((float *)fuv_link->link), uv_tmp);
                                                        fuv_link = fuv_link->next;
                                                }
                                        }
                                                        interp_v2_v2v2(uv_tmp, suv->uv_down, suv->uv_up, fabs(newlen));
                                                        fuv_link = suv->fuv_list;
                                                        while (fuv_link) {
-                                                               VECCOPY2D(((float *)fuv_link->link), uv_tmp);
+                                                               copy_v2_v2(((float *)fuv_link->link), uv_tmp);
                                                                fuv_link = fuv_link->next;
                                                        }
                                                }
                                                        interp_v2_v2v2(uv_tmp, suv->uv_up, suv->uv_down, fabs(newlen));
                                                        fuv_link = suv->fuv_list;
                                                        while (fuv_link) {
-                                                               VECCOPY2D(((float *)fuv_link->link), uv_tmp);
+                                                               copy_v2_v2(((float *)fuv_link->link), uv_tmp);
                                                                fuv_link = fuv_link->next;
                                                        }
                                                }
@@@ -51,7 -51,6 +51,7 @@@
  #include "DNA_scene_types.h"
  #include "DNA_meshdata_types.h"
  #include "DNA_gpencil_types.h"
 +#include "DNA_movieclip_types.h"
  
  #include "MEM_guardedalloc.h"
  
@@@ -75,9 -74,6 +75,9 @@@
  #include "BKE_bmesh.h"
  #include "BKE_scene.h"
  #include "BKE_report.h"
 +#include "BKE_tracking.h"
 +#include "BKE_movieclip.h"
 +#include "BKE_node.h"
  
  
  #include "ED_anim_api.h"
  #include "ED_node.h"
  #include "ED_types.h"
  #include "ED_uvedit.h"
 +#include "ED_clip.h"
  #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"
@@@ -2968,8 -2960,8 +2968,8 @@@ static TransData *ActionFCurveToTransDa
                                td2d->h1 = bezt->vec[0];
                                td2d->h2 = bezt->vec[2];
                                
-                               VECCOPY2D(td2d->ih1, td2d->h1);
-                               VECCOPY2D(td2d->ih2, td2d->h2);
+                               copy_v2_v2(td2d->ih1, td2d->h1);
+                               copy_v2_v2(td2d->ih2, td2d->h2);
                                
                                td++;
                                td2d++;
@@@ -3225,14 -3217,14 +3225,14 @@@ static void bezt_to_transdata (TransDat
  
        if (td->flag & TD_MOVEHANDLE1) {
                td2d->h1 = bezt->vec[0];
-               VECCOPY2D(td2d->ih1, td2d->h1);
+               copy_v2_v2(td2d->ih1, td2d->h1);
        } 
        else    
                td2d->h1 = NULL;
  
        if (td->flag & TD_MOVEHANDLE2) {
                td2d->h2 = bezt->vec[2];
-               VECCOPY2D(td2d->ih2, td2d->h2);
+               copy_v2_v2(td2d->ih2, td2d->h2);
        } 
        else 
                td2d->h2 = NULL;
@@@ -4804,17 -4796,6 +4804,17 @@@ void special_aftertrans_update(bContex
                /* clear link line */
                ED_node_link_intersect_test(t->sa, 0);
        }
 +      else if (t->spacetype == SPACE_CLIP) {
 +              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 */
 +                      nodeUpdateID(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;
                bAnimContext ac;
@@@ -5283,229 -5264,6 +5283,229 @@@ static void createTransNodeData(bContex
        CTX_DATA_END
  }
  
 +/* *** CLIP EDITOR *** */
 +
 +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)
 +{
 +      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;
 +
 +      tdt->relative= rel;
 +      tdt->area= area;
 +
 +      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);
 +      }
 +
 +      if(off)
 +              copy_v2_v2(tdt->soffset, off);
 +
 +      td->flag = 0;
 +      td->loc = td2d->loc;
 +      VECCOPY(td->center, td->loc);
 +      VECCOPY(td->iloc, td->loc);
 +
 +      memset(td->axismtx, 0, sizeof(td->axismtx));
 +      td->axismtx[2][2] = 1.0f;
 +
 +      td->ext= NULL; td->val= NULL;
 +
 +      td->flag |= TD_SELECTED;
 +      td->dist= 0.0;
 +
 +      unit_m3(td->mtx);
 +      unit_m3(td->smtx);
 +}
 +
 +static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
 +                      TransDataTracking *tdt, MovieTrackingTrack *track)
 +{
 +      MovieTrackingMarker *marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
 +
 +      track->transflag= marker->flag;
 +
 +      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++, tdt++, track, TRACK_AREA_POINT, marker->pos, NULL, NULL);
 +
 +      if(track->pat_flag&SELECT) {
 +              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, 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);
 +      }
 +}
 +
 +static void createTransTrackingData(bContext *C, TransInfo *t)
 +{
 +      TransData *td;
 +      TransData2D *td2d;
 +      SpaceClip *sc = CTX_wm_space_clip(C);
 +      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)) {
 +              t->total = 0;
 +              return;
 +      }
 +
 +      /* count */
 +      t->total = 0;
 +
 +      track = clip->tracking.tracks.first;
 +      while(track) {
 +              if(TRACK_VIEW_SELECTED(sc, track) && (track->flag&TRACK_LOCKED)==0) {
 +                      marker= BKE_tracking_get_marker(track, framenr);
 +
 +                      if(marker) {
 +                              t->total++;     /* offset */
 +
 +                              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_VIEW_SELECTED(sc, track) && (track->flag&TRACK_LOCKED)==0) {
 +                      marker= BKE_tracking_get_marker(track, framenr);
 +
 +                      trackToTransData(sc, td, td2d, tdt, track);
 +
 +                      /* offset */
 +                      td++;
 +                      td2d++;
 +                      tdt++;
 +
 +                      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(track->search_flag&SELECT) {
 +                              td+= 2;
 +                              td2d+= 2;
 +                              tdt+= 2;
 +
 +                              if(marker->flag&MARKER_DISABLED) {
 +                                      td+= 3;
 +                                      td2d+= 3;
 +                                      tdt+= 3;
 +                              };
 +                      }
 +              }
 +
 +              track = track->next;
 +      }
 +}
 +
 +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, 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);
 +
 +                              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);
 +              }
 +      }
 +}
 +
  void createTransData(bContext *C, TransInfo *t)
  {
        Scene *scene = t->scene;
                        sort_trans_data_dist(t);
                }
        }
 +      else if (t->spacetype == SPACE_CLIP) {
 +              t->flag |= T_POINTS|T_2D_EDIT;
 +              createTransTrackingData(C, t);
 +      }
        else if (t->obedit) {
                t->ext = NULL;
                if (t->obedit->type == OB_MESH) {
@@@ -31,7 -31,7 +31,7 @@@
   *  \ingroup DNA
   */
  
- // XXX, temp feature
+ // XXX, temp feature - campbell
  #define DURIAN_CAMERA_SWITCH
  
  #ifdef __cplusplus
@@@ -54,7 -54,6 +54,7 @@@ struct AnimData
  struct Editing;
  struct SceneStats;
  struct bGPdata;
 +struct MovieClip;
  
  typedef struct Base {
        struct Base *next, *prev;
@@@ -864,9 -863,6 +864,9 @@@ typedef struct Scene 
  
        /* Physics simulation settings */
        struct PhysicsSettings physics_settings;
 +
 +      /* Movie Tracking */
 +      struct MovieClip *clip;                 /* active movie clip */
  } Scene;
  
  
@@@ -1341,6 -1337,7 +1341,6 @@@ typedef enum SculptFlags 
  #define       USER_UNIT_OPT_SPLIT             1
  #define USER_UNIT_ROT_RADIANS 2
  
 -
  #ifdef __cplusplus
  }
  #endif