Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-03-01 02:56:28 +0300
committerCampbell Barton <campbell@blender.org>2022-03-01 03:18:17 +0300
commiteb0f8317e231c4a02940d0269125a96a47e94c7e (patch)
tree03c67854c72c5a4507f22f8c2321c14b2629fccd /source/blender/editors/space_view3d
parentae6400cfb4cae798667eab903d9c463fdec31298 (diff)
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.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_ndof.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_zoom.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_zoom_border.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_project.c59
6 files changed, 47 insertions, 42 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index d6bc7ded92e..5adce170e06 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -832,13 +832,13 @@ void ED_view3d_cursor3d_position(bContext *C,
return;
}
- ED_view3d_calc_zfac(rv3d, cursor_co, &flip);
+ ED_view3d_calc_zfac_ex(rv3d, cursor_co, &flip);
/* Reset the depth based on the view offset (we _know_ the offset is in front of us). */
if (flip) {
negate_v3_v3(cursor_co, rv3d->ofs);
/* re initialize, no need to check flip again */
- ED_view3d_calc_zfac(rv3d, cursor_co, NULL /* &flip */);
+ ED_view3d_calc_zfac(rv3d, cursor_co);
}
if (use_depth) { /* maybe this should be accessed some other way */
diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c
index 21e0459f346..d1e7f6ffb12 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate.c
@@ -396,7 +396,7 @@ ViewOpsData *viewops_data_create(bContext *C, const wmEvent *event, enum eViewOp
{
float tvec[3];
negate_v3_v3(tvec, rv3d->ofs);
- vod->init.zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
+ vod->init.zfac = ED_view3d_calc_zfac(rv3d, tvec);
}
vod->reverse = 1.0f;
@@ -559,7 +559,7 @@ void viewmove_apply(ViewOpsData *vod, int x, int y)
else {
float dvec[3];
- ED_view3d_win_to_delta(vod->region, event_ofs, dvec, vod->init.zfac);
+ ED_view3d_win_to_delta(vod->region, event_ofs, vod->init.zfac, dvec);
sub_v3_v3(vod->rv3d->ofs, dvec);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
index 6b77f464773..1ce9bdcb211 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
@@ -48,7 +48,7 @@ static float view3d_ndof_pan_speed_calc_ex(RegionView3D *rv3d, const float depth
float speed = rv3d->pixsize * NDOF_PIXELS_PER_SECOND;
if (rv3d->is_persp) {
- speed *= ED_view3d_calc_zfac(rv3d, depth_pt, NULL);
+ speed *= ED_view3d_calc_zfac(rv3d, depth_pt);
}
return speed;
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
index 8eb8fffaa31..5f6f9fde324 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
@@ -125,18 +125,18 @@ static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoo
float dvec[3];
float tvec[3];
float tpos[3];
- float mval_f[2];
+ float xy_delta[2];
float zfac;
negate_v3_v3(tpos, rv3d->ofs);
- mval_f[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f;
- mval_f[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f;
+ xy_delta[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f;
+ xy_delta[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f;
/* Project cursor position into 3D space */
- zfac = ED_view3d_calc_zfac(rv3d, tpos, NULL);
- ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
+ zfac = ED_view3d_calc_zfac(rv3d, tpos);
+ ED_view3d_win_to_delta(region, xy_delta, zfac, dvec);
/* Calculate view target position for dolly */
add_v3_v3v3(tvec, tpos, dvec);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
index 4e909151ce4..f834efe4a7b 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
@@ -125,7 +125,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
negate_v3_v3(new_ofs, p);
}
else {
- float mval_f[2];
+ float xy_delta[2];
float zfac;
/* We can't use the depth, fallback to the old way that doesn't set the center depth */
@@ -134,12 +134,12 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
{
float tvec[3];
negate_v3_v3(tvec, new_ofs);
- zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
+ zfac = ED_view3d_calc_zfac(rv3d, tvec);
}
- mval_f[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f;
- mval_f[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f;
- ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
+ xy_delta[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f;
+ xy_delta[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f;
+ ED_view3d_win_to_delta(region, xy_delta, zfac, dvec);
/* center the view to the center of the rectangle */
sub_v3_v3(new_ofs, dvec);
}
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,