Merging r42648 through r42722 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 19 Dec 2011 10:39:40 +0000 (10:39 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 19 Dec 2011 10:39:40 +0000 (10:39 +0000)
1  2 
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/tracking.c
source/blender/blenlib/intern/math_matrix.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/object/object_constraint.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c

index 831d4d1bc0703af88fb15f3193036e625fa68209,927a98c174fabd4e51261b4ed77b103ce2c0f3df..820f6b9ef5a03c98209aea12c406bbed08aa5c63
@@@ -3945,126 -3944,105 +3945,126 @@@ static void followtrack_evaluate (bCons
        Scene *scene= cob->scene;
        bFollowTrackConstraint *data= con->data;
        MovieClip *clip= data->clip;
 +      MovieTracking *tracking;
        MovieTrackingTrack *track;
 -      
 +      MovieTrackingObject *tracking_object;
 +      Object *camob= data->camera ? data->camera : scene->camera;
 +
        if (data->flag & FOLLOWTRACK_ACTIVECLIP)
                clip= scene->clip;
 -      
 -      if (!clip || !data->track[0])
 +
 +      if (!clip || !data->track[0] || !camob)
                return;
 -      
 -      track= BKE_tracking_named_track(&clip->tracking, data->track);
 -      
 +
 +      tracking= &clip->tracking;
 +
 +      if(data->object[0])
 +              tracking_object= BKE_tracking_named_object(tracking, data->object);
 +      else
 +              tracking_object= BKE_tracking_get_camera_object(tracking);
 +
 +      if(!tracking_object)
 +              return;
 +
 +      track= BKE_tracking_named_track(tracking, tracking_object, data->track);
 +
        if (!track)
                return;
 -      
 +
        if (data->flag & FOLLOWTRACK_USE_3D_POSITION) {
                if (track->flag & TRACK_HAS_BUNDLE) {
 -                      float pos[3], mat[4][4], obmat[4][4];
 -                      
 +                      MovieTracking *tracking= &clip->tracking;
 +                      float obmat[4][4], mat[4][4];
 +
                        copy_m4_m4(obmat, cob->matrix);
 -                      
 -                      BKE_get_tracking_mat(cob->scene, NULL, mat);
 -                      mul_v3_m4v3(pos, mat, track->bundle_pos);
 -                      
 -                      cob->matrix[3][0] += pos[0];
 -                      cob->matrix[3][1] += pos[1];
 -                      cob->matrix[3][2] += pos[2];
 +
 +                      if((tracking_object->flag&TRACKING_OBJECT_CAMERA)==0) {
 +                              float imat[4][4];
 +
 +                              copy_m4_m4(mat, camob->obmat);
 +
 +                              BKE_tracking_get_interpolated_camera(tracking, tracking_object, scene->r.cfra, imat);
 +                              invert_m4(imat);
 +
 +                              mul_serie_m4(cob->matrix, obmat, mat, imat, NULL, NULL, NULL, NULL, NULL);
 +                              translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
 +                      }
 +                      else {
 +                              BKE_get_tracking_mat(cob->scene, camob, mat);
 +
-                               mul_m4_m4m4(cob->matrix, mat, obmat);
++                              mult_m4_m4m4(cob->matrix, obmat, mat);
 +                              translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
 +                      }
                }
        } 
        else {
 -              Object *camob= cob->scene->camera;
 -              
 -              if (camob) {
 -                      MovieClipUser user;
 -                      MovieTrackingMarker *marker;
 -                      float vec[3], disp[3], axis[3], mat[4][4];
 -                      float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp);
 -                      float len, d;
 -                      
 -                      where_is_object_mat(scene, camob, mat);
 -                      
 -                      /* camera axis */
 -                      vec[0]= 0.0f;
 -                      vec[1]= 0.0f;
 -                      vec[2]= 1.0f;
 -                      mul_v3_m4v3(axis, mat, vec);
 -                      
 -                      /* distance to projection plane */
 -                      copy_v3_v3(vec, cob->matrix[3]);
 -                      sub_v3_v3(vec, mat[3]);
 -                      project_v3_v3v3(disp, vec, axis);
 -                      
 -                      len= len_v3(disp);
 -                      
 -                      if (len > FLT_EPSILON) {
 -                              CameraParams params;
 -                              float pos[2], rmat[4][4];
 -                              
 -                              user.framenr= scene->r.cfra;
 -                              marker= BKE_tracking_get_marker(track, user.framenr);
 -                              
 -                              add_v2_v2v2(pos, marker->pos, track->offset);
 -                              
 -                              camera_params_init(&params);
 -                              camera_params_from_object(&params, camob);
 +              MovieClipUser user;
 +              MovieTrackingMarker *marker;
 +              float vec[3], disp[3], axis[3], mat[4][4];
 +              float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp);
 +              float len, d;
  
 -                              if (params.is_ortho) {
 -                                      vec[0]= params.ortho_scale * (pos[0]-0.5f+params.shiftx);
 -                                      vec[1]= params.ortho_scale * (pos[1]-0.5f+params.shifty);
 -                                      vec[2]= -len;
 -                                      
 -                                      if (aspect > 1.0f) vec[1] /= aspect;
 -                                      else vec[0] *= aspect;
 -                                      
 -                                      mul_v3_m4v3(disp, camob->obmat, vec);
 -                                      
 -                                      copy_m4_m4(rmat, camob->obmat);
 -                                      zero_v3(rmat[3]);
 -                                      mult_m4_m4m4(cob->matrix, cob->matrix, rmat);
 -                                      
 -                                      copy_v3_v3(cob->matrix[3], disp);
 -                              }
 -                              else {
 -                                      d= (len*params.sensor_x) / (2.0f*params.lens);
 -                                      
 -                                      vec[0]= d*(2.0f*(pos[0]+params.shiftx)-1.0f);
 -                                      vec[1]= d*(2.0f*(pos[1]+params.shifty)-1.0f);
 -                                      vec[2]= -len;
 -                                      
 -                                      if (aspect > 1.0f) vec[1] /= aspect;
 -                                      else vec[0] *= aspect;
 -                                      
 -                                      mul_v3_m4v3(disp, camob->obmat, vec);
 -                                      
 -                                      /* apply camera rotation so Z-axis would be co-linear */
 -                                      copy_m4_m4(rmat, camob->obmat);
 -                                      zero_v3(rmat[3]);
 -                                      mult_m4_m4m4(cob->matrix, cob->matrix, rmat);
 -                                      
 -                                      copy_v3_v3(cob->matrix[3], disp);
 -                              }
 +              where_is_object_mat(scene, camob, mat);
 +
 +              /* camera axis */
 +              vec[0]= 0.0f;
 +              vec[1]= 0.0f;
 +              vec[2]= 1.0f;
 +              mul_v3_m4v3(axis, mat, vec);
 +
 +              /* distance to projection plane */
 +              copy_v3_v3(vec, cob->matrix[3]);
 +              sub_v3_v3(vec, mat[3]);
 +              project_v3_v3v3(disp, vec, axis);
 +
 +              len= len_v3(disp);
 +
 +              if (len > FLT_EPSILON) {
 +                      CameraParams params;
 +                      float pos[2], rmat[4][4];
 +
 +                      user.framenr= scene->r.cfra;
 +                      marker= BKE_tracking_get_marker(track, user.framenr);
 +
 +                      add_v2_v2v2(pos, marker->pos, track->offset);
 +
 +                      camera_params_init(&params);
 +                      camera_params_from_object(&params, camob);
 +
 +                      if (params.is_ortho) {
 +                              vec[0]= params.ortho_scale * (pos[0]-0.5f+params.shiftx);
 +                              vec[1]= params.ortho_scale * (pos[1]-0.5f+params.shifty);
 +                              vec[2]= -len;
 +
 +                              if (aspect > 1.0f) vec[1] /= aspect;
 +                              else vec[0] *= aspect;
 +
 +                              mul_v3_m4v3(disp, camob->obmat, vec);
 +
 +                              copy_m4_m4(rmat, camob->obmat);
 +                              zero_v3(rmat[3]);
-                               mul_m4_m4m4(cob->matrix, rmat, cob->matrix);
++                              mult_m4_m4m4(cob->matrix, cob->matrix, rmat);
 +
 +                              copy_v3_v3(cob->matrix[3], disp);
 +                      }
 +                      else {
 +                              d= (len*params.sensor_x) / (2.0f*params.lens);
 +
 +                              vec[0]= d*(2.0f*(pos[0]+params.shiftx)-1.0f);
 +                              vec[1]= d*(2.0f*(pos[1]+params.shifty)-1.0f);
 +                              vec[2]= -len;
 +
 +                              if (aspect > 1.0f) vec[1] /= aspect;
 +                              else vec[0] *= aspect;
 +
 +                              mul_v3_m4v3(disp, camob->obmat, vec);
 +
 +                              /* apply camera rotation so Z-axis would be co-linear */
 +                              copy_m4_m4(rmat, camob->obmat);
 +                              zero_v3(rmat[3]);
-                               mul_m4_m4m4(cob->matrix, rmat, cob->matrix);
++                              mult_m4_m4m4(cob->matrix, cob->matrix, rmat);
 +
 +                              copy_v3_v3(cob->matrix[3], disp);
                        }
                }
        }
@@@ -4108,20 -4086,17 +4108,20 @@@ static void camerasolver_evaluate (bCon
        Scene *scene= cob->scene;
        bCameraSolverConstraint *data= con->data;
        MovieClip *clip= data->clip;
 -      
 +
        if (data->flag & CAMERASOLVER_ACTIVECLIP)
                clip= scene->clip;
 -      
 +
        if (clip) {
                float mat[4][4], obmat[4][4];
 -              
 -              BKE_tracking_get_interpolated_camera(&clip->tracking, scene->r.cfra, mat);
 -              
 +              MovieTracking *tracking= &clip->tracking;
 +              MovieTrackingObject *object= BKE_tracking_get_camera_object(tracking);
 +
 +              BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat);
 +
                copy_m4_m4(obmat, cob->matrix);
-               mul_m4_m4m4(cob->matrix, mat, obmat);
 +
+               mult_m4_m4m4(cob->matrix, obmat, mat);
        }
  }
  
@@@ -4141,80 -4116,6 +4141,80 @@@ static bConstraintTypeInfo CTI_CAMERASO
        camerasolver_evaluate /* evaluate */
  };
  
-                       mul_m4_m4m4(parmat, data->invmat, cammat);
 +/* ----------- Object Solver ------------- */
 +
 +static void objectsolver_new_data (void *cdata)
 +{
 +      bObjectSolverConstraint *data= (bObjectSolverConstraint *)cdata;
 +
 +      data->clip = NULL;
 +      data->flag |= OBJECTSOLVER_ACTIVECLIP;
 +      unit_m4(data->invmat);
 +}
 +
 +static void objectsolver_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 +{
 +      bObjectSolverConstraint *data= con->data;
 +
 +      func(con, (ID**)&data->clip, userdata);
 +      func(con, (ID**)&data->camera, userdata);
 +}
 +
 +static void objectsolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
 +{
 +      Scene *scene= cob->scene;
 +      bObjectSolverConstraint *data= con->data;
 +      MovieClip *clip= data->clip;
 +      Object *camob= data->camera ? data->camera : scene->camera;
 +
 +      if (data->flag & OBJECTSOLVER_ACTIVECLIP)
 +              clip= scene->clip;
 +
 +      if(!camob || !clip)
 +              return;
 +
 +      if (clip) {
 +              MovieTracking *tracking= &clip->tracking;
 +              MovieTrackingObject *object;
 +
 +              object= BKE_tracking_named_object(tracking, data->object);
 +
 +              if(object) {
 +                      float mat[4][4], obmat[4][4], imat[4][4], cammat[4][4], camimat[4][4], parmat[4][4];
 +
 +                      where_is_object_mat(scene, camob, cammat);
 +
 +                      BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat);
 +
 +                      invert_m4_m4(camimat, cammat);
++                      mult_m4_m4m4(parmat, cammat, data->invmat);
 +
 +                      copy_m4_m4(cammat, camob->obmat);
 +                      copy_m4_m4(obmat, cob->matrix);
 +
 +                      invert_m4_m4(imat, mat);
 +
 +                      mul_serie_m4(cob->matrix, cammat, imat, camimat, parmat, obmat, NULL, NULL, NULL);
 +              }
 +      }
 +}
 +
 +static bConstraintTypeInfo CTI_OBJECTSOLVER = {
 +      CONSTRAINT_TYPE_OBJECTSOLVER, /* type */
 +      sizeof(bObjectSolverConstraint), /* size */
 +      "Object Solver", /* name */
 +      "bObjectSolverConstraint", /* struct name */
 +      NULL, /* free data */
 +      NULL, /* relink data */
 +      objectsolver_id_looper, /* id looper */
 +      NULL, /* copy data */
 +      objectsolver_new_data, /* new data */
 +      NULL, /* get constraint targets */
 +      NULL, /* flush constraint targets */
 +      NULL, /* get target matrix */
 +      objectsolver_evaluate /* evaluate */
 +};
 +
  /* ************************* Constraints Type-Info *************************** */
  /* All of the constraints api functions use bConstraintTypeInfo structs to carry out
   * and operations that involve constraint specific code.
index fa4f50e240f8e398e088539493351f9e0c828b2f,796ca01a6a953748ce29772681991228f42b76e7..8266f3501c5acce73c4a6ed297663885dced0052
@@@ -754,8 -747,8 +754,8 @@@ static void child_get_inverse_matrix (S
                 * the effect of the constraint
                 */
                invert_m4_m4(imat, pchan->pose_mat);
-               mul_m4_m4m4(tmat, imat, pmat);
+               mult_m4_m4m4(tmat, pmat, imat);
 -              invert_m4_m4(data->invmat, tmat);
 +              invert_m4_m4(invmat, tmat);
                
                /* 5. restore constraints */
                pchan->constraints.last = lastcon;
index ca854c7befe53f6cca930d40707cb0a68aa0b839,8a11c8815274a9ee8ca5ce82dafd8f6fb864376f..c37113e924cc97cc47a539753b0919b39b0c4c4e
@@@ -1936,29 -1906,6 +1936,29 @@@ static int count_selected_bundles(bCont
        return tot;
  }
  
-                       mul_m4_m4m4(invmat, data->invmat, invmat);
 +static void object_solver_inverted_matrix(Scene *scene, Object *ob, float invmat[4][4])
 +{
 +      Object *cam= scene->camera;
 +      bConstraint *con;
 +
 +      where_is_object_mat(scene, cam, invmat);
 +
 +      for (con= ob->constraints.first; con; con=con->next) {
 +              bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 +
 +              if(!cti)
 +                      continue;
 +
 +              if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) {
 +                      bObjectSolverConstraint *data= (bObjectSolverConstraint *)con->data;
 +
++                      mult_m4_m4m4(invmat, invmat, data->invmat);
 +              }
 +      }
 +
 +      invert_m4(invmat);
 +}
 +
  static int set_origin_exec(bContext *C, wmOperator *op)
  {
        SpaceClip *sc= CTX_wm_space_clip(C);
@@@ -2123,30 -2002,10 +2123,30 @@@ static void set_axis(Scene *scene,  Obj
        normalize_v3(mat[1]);
        normalize_v3(mat[2]);
  
 -      invert_m4(mat);
 +      if(is_camera) {
 +              invert_m4(mat);
 +
-               mul_m4_m4m4(mat, obmat, mat);
++              mult_m4_m4m4(mat, mat, obmat);
 +      }
 +      else {
 +              if(!flip) {
 +                      float lmat[4][4], ilmat[4][4], rmat[3][3];
 +
 +                      object_rot_to_mat3(ob, rmat);
 +                      invert_m3(rmat);
 +                      mul_m4_m4m3(mat, mat, rmat);
 +
 +                      unit_m4(lmat);
 +                      copy_v3_v3(lmat[3], obmat[3]);
 +                      invert_m4_m4(ilmat, lmat);
 +
 +                      mul_serie_m4(mat, lmat, mat, ilmat, obmat, NULL, NULL, NULL, NULL);
 +              }
 +              else {
-                       mul_m4_m4m4(mat, mat, obmat);
++                      mult_m4_m4m4(mat, obmat, mat);
 +              }
 +      }
  
 -      object_to_mat4(ob, obmat);
 -      mult_m4_m4m4(mat, mat, obmat);
        object_apply_mat4(ob, mat, 0, 0);
  }
  
@@@ -2223,30 -2070,25 +2223,30 @@@ static int set_floor_exec(bContext *C, 
        mat[3][1]= orig[1];
        mat[3][2]= orig[2];
  
 -      invert_m4(mat);
 -
 -      object_to_mat4(parent, obmat);
 -      mult_m4_m4m4(mat, mat, obmat);
 -      mult_m4_m4m4(newmat, rot, mat);
 -      object_apply_mat4(parent, newmat, 0, 0);
 +      if(tracking_object->flag&TRACKING_OBJECT_CAMERA) {
 +              invert_m4(mat);
  
 -      /* make camera have positive z-coordinate */
 -      if(parent->loc[2]<0) {
 -              invert_m4(rot);
 +              object_to_mat4(object, obmat);
-               mul_m4_m4m4(mat, obmat, mat);
-               mul_m4_m4m4(newmat, mat, rot);
++              mult_m4_m4m4(mat, mat, obmat);
+               mult_m4_m4m4(newmat, rot, mat);
 -              object_apply_mat4(parent, newmat, 0, 0);
 +              object_apply_mat4(object, newmat, 0, 0);
 +
 +              /* make camera have positive z-coordinate */
 +              if(object->loc[2]<0) {
 +                invert_m4(rot);
-                 mul_m4_m4m4(newmat, mat, rot);
++                mult_m4_m4m4(newmat, rot, mat);
 +                object_apply_mat4(object, newmat, 0, 0);
 +              }
 +      }
 +      else {
 +              object_apply_mat4(object, mat, 0, 0);
        }
  
 -      where_is_object(scene, parent);
 -      set_axis(scene, parent, axis_track, 'X');
 +      where_is_object(scene, object);
 +      set_axis(scene, object, tracking_object, axis_track, 'X');
  
        DAG_id_tag_update(&clip->id, 0);
 -      DAG_id_tag_update(&parent->id, OB_RECALC_OB);
 +      DAG_id_tag_update(&object->id, OB_RECALC_OB);
  
        WM_event_add_notifier(C, NC_MOVIECLIP|NA_EVALUATED, clip);
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
index db33426a804ba0f64354f2f48fcbca5b3117062b,ecb54c77e0cdbbb163b51cc77bd76f55a3fdafec..a2173537c8c5a55e6604c211f128b82f45077617
@@@ -778,34 -768,16 +778,34 @@@ static void bundle_midpoint(Scene *scen
  
        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);
 +
-                       mul_m4_m4m4(obmat, imat, cammat);
++                      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) {