diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-09 20:57:02 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-09 20:57:02 +0400 |
commit | 9f30c7147cdb726e503ff37ba585f5e35b090d8c (patch) | |
tree | ef90a368102f7a5925d87eaaaa821f024eb107cd /source/blender/blenkernel/intern/constraint.c | |
parent | 9a32fd05db015c514aa9af42e380ac1032f1b345 (diff) |
Frame matching methods for follow track constraint
This is needed in cases when using blender camera with different
resolution than original footage. Behaves in the same way as
background picture framing.
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index e08c9e9d39e..16edbc3f0a9 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -82,8 +82,6 @@ #include "BKE_tessmesh.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" -#include "BKE_tracking.h" -#include "BKE_movieclip.h" #ifdef WITH_PYTHON #include "BPY_extern.h" @@ -3985,6 +3983,41 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase add_v2_v2v2(pos, marker->pos, track->offset); + /* aspect correction */ + if (data->frame_method != FOLLOWTRACK_FRAME_STRETCH) { + int width, height; + float w_src, h_src, w_dst, h_dst, asp_src, asp_dst; + + BKE_movieclip_get_size(clip, NULL, &width, &height); + + /* apply clip display aspect */ + w_src = width * clip->aspx; + h_src = height * clip->aspy; + + w_dst = scene->r.xsch * scene->r.xasp; + h_dst = scene->r.ysch * scene->r.yasp; + + asp_src = w_src / h_src; + asp_dst = w_dst / h_dst; + + if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) { + if ((asp_src > asp_dst) == (data->frame_method == FOLLOWTRACK_FRAME_CROP)) { + /* fit X */ + float div = asp_src / asp_dst; + float cent = (float) width / 2.0f; + + pos[0] = (((pos[0] * width - cent) * div) + cent) / width; + } + else { + /* fit Y */ + float div = asp_dst / asp_src; + float cent = (float) height / 2.0f; + + pos[1] = (((pos[1] * height - cent) * div) + cent) / height; + } + } + } + BKE_camera_params_init(¶ms); BKE_camera_params_from_object(¶ms, camob); |