Object tracking: various fixes and improvements
[blender-staging.git] / source / blender / blenkernel / intern / tracking.c
index 931f3f5fc7275edbd7a88bdf5592e100dd0183b6..262c0576186b2599df146befb84f8b1ce4ad5e46 100644 (file)
@@ -2257,23 +2257,34 @@ void BKE_tracking_detect_fast(MovieTracking *tracking, ListBase *tracksbase, ImB
 #endif
 }
 
-MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int tracknr)
+MovieTrackingTrack *BKE_tracking_indexed_track(MovieTracking *tracking, int tracknr, ListBase **tracksbase_r)
 {
-       ListBase *tracksbase= &tracking->tracks;        /* XXX: need proper tracks base */
-       MovieTrackingTrack *track= tracksbase->first;
+       MovieTrackingObject *object;
        int cur= 1;
 
-       while(track) {
-               if(track->flag&TRACK_HAS_BUNDLE) {
-                       if(cur==tracknr)
-                               return track;
+       object= tracking->objects.first;
+       while(object) {
+               ListBase *tracksbase= BKE_tracking_object_tracks(tracking, object);
+               MovieTrackingTrack *track= tracksbase->first;
+
+               while(track) {
+                       if(track->flag&TRACK_HAS_BUNDLE) {
+                               if(cur==tracknr) {
+                                       *tracksbase_r= tracksbase;
+                                       return track;
+                               }
 
-                       cur++;
+                               cur++;
+                       }
+
+                       track= track->next;
                }
 
-               track= track->next;
+               object= object->next;
        }
 
+       *tracksbase_r= NULL;
+
        return NULL;
 }