diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-12-16 00:38:23 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-12-16 00:38:23 +0400 |
commit | 8a9d901c81b0357bca833f3ccb2d4f674873e58d (patch) | |
tree | 16d3d3746a87970ae931c2bf4438b3d92b1ea06f /source/blender | |
parent | e534af906a938b6e3cf0727d577c89a51052f6ff (diff) |
Camera tracking: add camera to follow track and object solver constraint
Object used to be parented to active camera which isn't very convenient when
working with witness cameras.
Now parent camera can be specified in constraint (if it's not specified, active camera is used)
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 118 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 26 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_constraint_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_constraint.c | 61 |
4 files changed, 139 insertions, 68 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 1699cb05fde..2e9934806b8 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3937,6 +3937,7 @@ static void followtrack_id_looper (bConstraint *con, ConstraintIDFunc func, void bFollowTrackConstraint *data= con->data; func(con, (ID**)&data->clip, userdata); + func(con, (ID**)&data->camera, userdata); } static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) @@ -3947,11 +3948,12 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase 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; tracking= &clip->tracking; @@ -3975,12 +3977,8 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase float pos[3], mat[4][4]; if((tracking_object->flag&TRACKING_OBJECT_CAMERA)==0) { - Object *camob= scene->camera; float obmat[4][4], imat[4][4]; - if(!camob) - return; - copy_m4_m4(mat, camob->obmat); BKE_tracking_get_interpolated_camera(tracking, tracking_object, scene->r.cfra, obmat); @@ -4000,77 +3998,73 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase } } else { - Object *camob= 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; + 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); + 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); + /* 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); + /* 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); + len= len_v3(disp); - if (len > FLT_EPSILON) { - CameraParams params; - float pos[2], rmat[4][4]; + 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); + user.framenr= scene->r.cfra; + marker= BKE_tracking_get_marker(track, user.framenr); - add_v2_v2v2(pos, marker->pos, track->offset); + add_v2_v2v2(pos, marker->pos, track->offset); - camera_params_init(¶ms); - camera_params_from_object(¶ms, camob); + camera_params_init(¶ms); + camera_params_from_object(¶ms, 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 (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; + if (aspect > 1.0f) vec[1] /= aspect; + else vec[0] *= aspect; - mul_v3_m4v3(disp, camob->obmat, vec); + 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); + copy_m4_m4(rmat, camob->obmat); + zero_v3(rmat[3]); + mul_m4_m4m4(cob->matrix, rmat, cob->matrix); - copy_v3_v3(cob->matrix[3], disp); - } - else { - d= (len*params.sensor_x) / (2.0f*params.lens); + 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; + 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; + if (aspect > 1.0f) vec[1] /= aspect; + else vec[0] *= aspect; - mul_v3_m4v3(disp, camob->obmat, vec); + 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); + /* 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); - copy_v3_v3(cob->matrix[3], disp); - } + copy_v3_v3(cob->matrix[3], disp); } } } @@ -4162,6 +4156,7 @@ static void objectsolver_id_looper (bConstraint *con, ConstraintIDFunc func, voi 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)) @@ -4169,11 +4164,12 @@ static void objectsolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBas 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(!scene->camera) + if(!camob || !clip) return; if (clip) { @@ -4185,14 +4181,14 @@ static void objectsolver_evaluate (bConstraint *con, bConstraintOb *cob, ListBas 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, scene->camera, cammat); + where_is_object_mat(scene, camob, cammat); BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat); invert_m4_m4(camimat, cammat); mul_m4_m4m4(parmat, data->invmat, cammat); - copy_m4_m4(cammat, scene->camera->obmat); + copy_m4_m4(cammat, camob->obmat); copy_m4_m4(obmat, cob->matrix); invert_m4_m4(imat, mat); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 82ee494630d..21ac4e1431f 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -6818,14 +6818,28 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) { - /* special case for object solver constraint because it doesn't fill - constraint targets properly (design limitation -- scene is needed for - it's target but it can't be accessed from get_targets callvack) */ - if(scene->camera) { + if(ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_OBJECTSOLVER)) { + /* special case for object solver and follow track constraints because they don't fill + constraint targets properly (design limitation -- scene is needed for their target + but it can't be accessed from get_targets callvack) */ + + Object *camob= NULL; + + if(cti->type==CONSTRAINT_TYPE_FOLLOWTRACK) { + bFollowTrackConstraint *data= (bFollowTrackConstraint *)curcon->data; + + camob= data->camera ? data->camera : scene->camera; + } + else if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) { + bObjectSolverConstraint *data= (bObjectSolverConstraint *)curcon->data; + + camob= data->camera ? data->camera : scene->camera; + } + + if(camob) { setlinestyle(3); glBegin(GL_LINES); - glVertex3fv(scene->camera->obmat[3]); + glVertex3fv(camob->obmat[3]); glVertex3fv(ob->obmat[3]); glEnd(); setlinestyle(0); diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index 5403bf26da0..50c1779960d 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -413,6 +413,7 @@ typedef struct bFollowTrackConstraint { char track[24]; int flag, pad; char object[24]; + struct Object *camera; } bFollowTrackConstraint; /* Camera Solver constraints */ @@ -427,6 +428,7 @@ typedef struct bObjectSolverConstraint { int flag, pad; char object[24]; float invmat[4][4]; /* parent-inverse matrix to use */ + struct Object *camera; } bObjectSolverConstraint; /* ------------------------------------------ */ diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 4d064c01fae..6439d22e808 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -330,6 +330,49 @@ static void rna_SplineIKConstraint_joint_bindings_set(PointerRNA *ptr, const flo memcpy(ikData->points, values, ikData->numpoints * sizeof(float)); } +static int rna_Constraint_cameraObject_poll(PointerRNA *ptr, PointerRNA value) +{ + Object *ob= (Object*)value.data; + + if (ob) { + if (ob->type == OB_CAMERA && ob != (Object*)ptr->id.data) { + return 1; + } + } + + return 0; +} + +static void rna_Constraint_followTrack_camera_set(PointerRNA *ptr, PointerRNA value) +{ + bConstraint *con= (bConstraint*)ptr->data; + bFollowTrackConstraint *data= (bFollowTrackConstraint*)con->data; + Object *ob= (Object*)value.data; + + if (ob) { + if (ob->type == OB_CAMERA && ob != (Object*)ptr->id.data) { + data->camera= ob; + } + } else { + data->camera= NULL; + } +} + +static void rna_Constraint_objectSolver_camera_set(PointerRNA *ptr, PointerRNA value) +{ + bConstraint *con= (bConstraint*)ptr->data; + bObjectSolverConstraint *data= (bObjectSolverConstraint*)con->data; + Object *ob= (Object*)value.data; + + if (ob) { + if (ob->type == OB_CAMERA && ob != (Object*)ptr->id.data) { + data->camera= ob; + } + } else { + data->camera= NULL; + } +} + #else EnumPropertyItem constraint_distance_items[] = { @@ -2073,8 +2116,16 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna) /* object */ prop= RNA_def_property(srna, "object", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "object"); - RNA_def_property_ui_text(prop, "Object", "Movie tracking object to follow"); + RNA_def_property_ui_text(prop, "Object", "Movie tracking object to follow (if empty, camera object is used)"); + RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update"); + + /* camera */ + prop= RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "camera"); + RNA_def_property_ui_text(prop, "Camera", "Camera to which motion is parented (if empty active scene camera is used)"); + RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update"); + RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_followTrack_camera_set", NULL, "rna_Constraint_cameraObject_poll"); } static void rna_def_constraint_camera_solver(BlenderRNA *brna) @@ -2127,6 +2178,14 @@ static void rna_def_constraint_object_solver(BlenderRNA *brna) RNA_def_property_string_sdna(prop, NULL, "object"); RNA_def_property_ui_text(prop, "Object", "Movie tracking object to follow"); RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update"); + + /* camera */ + prop= RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "camera"); + RNA_def_property_ui_text(prop, "Camera", "Camera to which motion is parented (if empty active scene camera is used)"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_dependency_update"); + RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_objectSolver_camera_set", NULL, "rna_Constraint_cameraObject_poll"); } /* base struct for constraints */ |