svn merge ^/trunk/blender -r42991:43009
[blender.git] / source / blender / editors / space_view3d / view3d_snap.c
index cf61fe9281428cc9e019023cb70fbb21e919ed1a..1f1a17ce5cd74e33969e638d5561c3828bc95b4e 100644 (file)
@@ -57,6 +57,7 @@
 #include "BKE_object.h"
 #include "BKE_tessmesh.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_scene.h"
 #include "BKE_tracking.h"
 
 #include "WM_api.h"
@@ -815,28 +816,55 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot)
 
 static void bundle_midpoint(Scene *scene, Object *ob, float vec[3])
 {
-       MovieTrackingTrack *track;
        MovieClip *clip= object_get_movieclip(scene, ob, 0);
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingObject *object= tracking->objects.first;
        int ok= 0;
-       float min[3], max[3], mat[4][4], pos[3];
+       float min[3], max[3], mat[4][4], pos[3], cammat[4][4];
 
        if(!clip)
                return;
 
+       unit_m4(cammat);
+
+       if(!scene->camera)
+               scene->camera= scene_find_camera(scene);
+
+       if(scene->camera)
+               copy_m4_m4(cammat, scene->camera->obmat);
+
        BKE_get_tracking_mat(scene, ob, mat);
 
        INIT_MINMAX(min, max);
 
-       track= clip->tracking.tracks.first;
-       while(track) {
-               int selected= (track->flag&SELECT) || (track->pat_flag&SELECT) || (track->search_flag&SELECT);
-               if((track->flag&TRACK_HAS_BUNDLE) && selected) {
-                       ok= 1;
-                       mul_v3_m4v3(pos, mat, track->bundle_pos);
-                       DO_MINMAX(pos, min, max);
+       while(object) {
+               ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object);
+               MovieTrackingTrack *track= tracksbase->first;
+               float obmat[4][4];
+
+               if(object->flag & TRACKING_OBJECT_CAMERA) {
+                       copy_m4_m4(obmat, mat);
+               }
+               else {
+                       float imat[4][4];
+
+                       BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, imat);
+                       invert_m4(imat);
+
+                       mult_m4_m4m4(obmat, cammat, imat);
+               }
+
+               while(track) {
+                       if((track->flag&TRACK_HAS_BUNDLE) && TRACK_SELECTED(track)) {
+                               ok= 1;
+                               mul_v3_m4v3(pos, obmat, track->bundle_pos);
+                               DO_MINMAX(pos, min, max);
+                       }
+
+                       track= track->next;
                }
 
-               track= track->next;
+               object= object->next;
        }
 
        if(ok) {