From eb0f8317e231c4a02940d0269125a96a47e94c7e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 1 Mar 2022 10:56:28 +1100 Subject: Cleanup: ED_view3d_win_to_delta & ED_view3d_calc_zfac usage - Rename ED_view3d_win_to_delta `mval` argument to `xy_delta` as it as it was misleading since this is an screen-space offset not a region relative cursor position (typical use of the name `mval`). Also rename the variable passed to this function which also used the term `mval` in many places. - Re-order the output argument of ED_view3d_win_to_delta last. use an r_ prefix for return arguments. - Document how the `zfac` argument is intended to be used. - Split ED_view3d_calc_zfac into two functions as the `r_flip` argument was only used in some special cases. --- .../blender/editors/space_view3d/view3d_project.c | 59 ++++++++++++---------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'source/blender/editors/space_view3d/view3d_project.c') diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 2cf9ac0a52e..85d239507ce 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -276,7 +276,7 @@ float ED_view3d_pixel_size_no_ui_scale(const RegionView3D *rv3d, const float co[ return mul_project_m4_v3_zfac(rv3d->persmat, co) * rv3d->pixsize; } -float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_flip) +float ED_view3d_calc_zfac_ex(const RegionView3D *rv3d, const float co[3], bool *r_flip) { float zfac = mul_project_m4_v3_zfac(rv3d->persmat, co); @@ -299,10 +299,15 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f return zfac; } +float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3]) +{ + return ED_view3d_calc_zfac_ex(rv3d, co, NULL); +} + float ED_view3d_calc_depth_for_comparison(const RegionView3D *rv3d, const float co[3]) { if (rv3d->is_persp) { - return ED_view3d_calc_zfac(rv3d, co, NULL); + return ED_view3d_calc_zfac(rv3d, co); } return -dot_v3v3(rv3d->viewinv[2], co); } @@ -436,8 +441,8 @@ bool view3d_get_view_aligned_coordinate(ARegion *region, if (ret == V3D_PROJ_RET_OK) { const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]), (float)(mval_cpy[1] - mval[1])}; - const float zfac = ED_view3d_calc_zfac(rv3d, fp, NULL); - ED_view3d_win_to_delta(region, mval_f, dvec, zfac); + const float zfac = ED_view3d_calc_zfac(rv3d, fp); + ED_view3d_win_to_delta(region, mval_f, zfac, dvec); sub_v3_v3(fp, dvec); return true; @@ -584,57 +589,57 @@ bool ED_view3d_win_to_3d_on_plane_with_fallback(const ARegion *region, } void ED_view3d_win_to_delta(const ARegion *region, - const float mval[2], - float out[3], - const float zfac) + const float xy_delta[2], + const float zfac, + float r_out[3]) { RegionView3D *rv3d = region->regiondata; float dx, dy; - dx = 2.0f * mval[0] * zfac / region->winx; - dy = 2.0f * mval[1] * zfac / region->winy; + dx = 2.0f * xy_delta[0] * zfac / region->winx; + dy = 2.0f * xy_delta[1] * zfac / region->winy; - out[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy); - out[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy); - out[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy); + r_out[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy); + r_out[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy); + r_out[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy); } -void ED_view3d_win_to_origin(const ARegion *region, const float mval[2], float out[3]) +void ED_view3d_win_to_origin(const ARegion *region, const float mval[2], float r_out[3]) { RegionView3D *rv3d = region->regiondata; if (rv3d->is_persp) { - copy_v3_v3(out, rv3d->viewinv[3]); + copy_v3_v3(r_out, rv3d->viewinv[3]); } else { - out[0] = 2.0f * mval[0] / region->winx - 1.0f; - out[1] = 2.0f * mval[1] / region->winy - 1.0f; + r_out[0] = 2.0f * mval[0] / region->winx - 1.0f; + r_out[1] = 2.0f * mval[1] / region->winy - 1.0f; if (rv3d->persp == RV3D_CAMOB) { - out[2] = -1.0f; + r_out[2] = -1.0f; } else { - out[2] = 0.0f; + r_out[2] = 0.0f; } - mul_project_m4_v3(rv3d->persinv, out); + mul_project_m4_v3(rv3d->persinv, r_out); } } -void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float out[3]) +void ED_view3d_win_to_vector(const ARegion *region, const float mval[2], float r_out[3]) { RegionView3D *rv3d = region->regiondata; if (rv3d->is_persp) { - out[0] = 2.0f * (mval[0] / region->winx) - 1.0f; - out[1] = 2.0f * (mval[1] / region->winy) - 1.0f; - out[2] = -0.5f; - mul_project_m4_v3(rv3d->persinv, out); - sub_v3_v3(out, rv3d->viewinv[3]); + r_out[0] = 2.0f * (mval[0] / region->winx) - 1.0f; + r_out[1] = 2.0f * (mval[1] / region->winy) - 1.0f; + r_out[2] = -0.5f; + mul_project_m4_v3(rv3d->persinv, r_out); + sub_v3_v3(r_out, rv3d->viewinv[3]); } else { - negate_v3_v3(out, rv3d->viewinv[2]); + negate_v3_v3(r_out, rv3d->viewinv[2]); } - normalize_v3(out); + normalize_v3(r_out); } bool ED_view3d_win_to_segment_clipped(struct Depsgraph *depsgraph, -- cgit v1.2.3