diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-09-22 07:33:31 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-09-22 07:33:31 +0400 |
commit | 1a1e37f4a8e4d7fc74a7e2ce057b8a9782216340 (patch) | |
tree | 7ff4367689c907aea8d60369239df52a639798c7 | |
parent | 22e0ffa05b15e407a7c317975861d0666b702d9a (diff) |
replace UV project modifier matrix calculation with BKE_camera_params_* functions, double checled combinations of aspect/scale/shift work as before --- but this reduces the likelyhood of discrepancies for sensor size (corner cases).
-rw-r--r-- | source/blender/modifiers/intern/MOD_uvproject.c | 64 |
1 files changed, 15 insertions, 49 deletions
diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index eb5a74f0dcc..88951919272 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -157,7 +157,6 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, int override_image = ((umd->flags & MOD_UVPROJECT_OVERRIDEIMAGE) != 0); Projector projectors[MOD_UVPROJECT_MAXPROJECTORS]; int num_projectors = 0; - float aspect; char uvname[MAX_CUSTOMDATA_LAYER_NAME]; float aspx = umd->aspectx ? umd->aspectx : 1.0f; float aspy = umd->aspecty ? umd->aspecty : 1.0f; @@ -165,8 +164,6 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, float scay = umd->scaley ? umd->scaley : 1.0f; int free_uci = 0; - aspect = aspx / aspy; - for (i = 0; i < umd->num_projectors; ++i) if (umd->projectors[i]) projectors[num_projectors++].ob = umd->projectors[i]; @@ -199,39 +196,23 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, free_uci = 1; } else { - float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); - int sensor_fit = BKE_camera_sensor_fit(cam->sensor_fit, aspx, aspy); - float scale = (cam->type == CAM_PERSP) ? cam->clipsta * sensor / cam->lens : cam->ortho_scale; - float xmax, xmin, ymax, ymin; - - if (sensor_fit == CAMERA_SENSOR_FIT_HOR) { - xmax = 0.5f * scale; - ymax = xmax / aspect; - } - else { - ymax = 0.5f * scale; - xmax = ymax * aspect; - } + CameraParams params; - xmin = -xmax; - ymin = -ymax; + /* setup parameters */ + BKE_camera_params_init(¶ms); + BKE_camera_params_from_object(¶ms, projectors[i].ob); - /* scale the matrix */ - xmin *= scax; - xmax *= scax; - ymin *= scay; - ymax *= scay; + /* compute matrix, viewplane, .. */ + BKE_camera_params_compute_viewplane(¶ms, 1, 1, aspx, aspy); - if (cam->type == CAM_PERSP) { - float perspmat[4][4]; - perspective_m4(perspmat, xmin, xmax, ymin, ymax, cam->clipsta, cam->clipend); - mult_m4_m4m4(tmpmat, perspmat, projectors[i].projmat); - } - else { /* if (cam->type == CAM_ORTHO) */ - float orthomat[4][4]; - orthographic_m4(orthomat, xmin, xmax, ymin, ymax, cam->clipsta, cam->clipend); - mult_m4_m4m4(tmpmat, orthomat, projectors[i].projmat); - } + /* scale the view-plane */ + params.viewplane.xmin *= scax; + params.viewplane.xmax *= scax; + params.viewplane.ymin *= scay; + params.viewplane.ymax *= scay; + + BKE_camera_params_compute_matrix(¶ms); + mult_m4_m4m4(tmpmat, params.winmat, projectors[i].projmat); } } else { @@ -241,22 +222,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, unit_m4(offsetmat); mul_mat3_m4_fl(offsetmat, 0.5); offsetmat[3][0] = offsetmat[3][1] = offsetmat[3][2] = 0.5; - - if (cam) { - if (aspx == aspy) { - offsetmat[3][0] -= cam->shiftx; - offsetmat[3][1] -= cam->shifty; - } - else if (aspx < aspy) { - offsetmat[3][0] -= (cam->shiftx * aspy / aspx); - offsetmat[3][1] -= cam->shifty; - } - else { - offsetmat[3][0] -= cam->shiftx; - offsetmat[3][1] -= (cam->shifty * aspx / aspy); - } - } - + mult_m4_m4m4(projectors[i].projmat, offsetmat, tmpmat); /* calculate worldspace projector normal (for best projector test) */ |