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
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')
-rw-r--r--source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c6
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c12
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c12
-rw-r--r--source/blender/editors/gpencil/gpencil_sculpt_paint.c19
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c37
-rw-r--r--source/blender/editors/include/ED_view3d.h43
-rw-r--r--source/blender/editors/mesh/editmesh_bisect.c4
-rw-r--r--source/blender/editors/physics/particle_edit.c6
-rw-r--r--source/blender/editors/sculpt_paint/paint_utils.c7
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c8
-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
-rw-r--r--source/blender/editors/transform/transform.c4
-rw-r--r--source/blender/editors/transform/transform_constraints.c3
-rw-r--r--source/blender/editors/transform/transform_generics.c17
-rw-r--r--source/blender/editors/transform/transform_mode_vert_slide.c14
-rw-r--r--source/blender/io/gpencil/intern/gpencil_io_base.cc2
21 files changed, 150 insertions, 133 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
index aea6d41202e..447fe1005a1 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
@@ -147,7 +147,7 @@ static void move3d_get_translate(const wmGizmo *gz,
float co_delta[3])
{
MoveInteraction *inter = gz->interaction_data;
- const float mval_delta[2] = {
+ const float xy_delta[2] = {
event->mval[0] - inter->init.mval[0],
event->mval[1] - inter->init.mval[1],
};
@@ -155,9 +155,9 @@ static void move3d_get_translate(const wmGizmo *gz,
RegionView3D *rv3d = region->regiondata;
float co_ref[3];
mul_v3_mat3_m4v3(co_ref, gz->matrix_space, inter->init.prop_co);
- const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL);
+ const float zfac = ED_view3d_calc_zfac(rv3d, co_ref);
- ED_view3d_win_to_delta(region, mval_delta, co_delta, zfac);
+ ED_view3d_win_to_delta(region, xy_delta, zfac, co_delta);
float matrix_space_inv[3][3];
copy_m3_m4(matrix_space_inv, gz->matrix_space);
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index b40dda146dc..5ab4a663efe 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -326,8 +326,7 @@ static void annotation_stroke_convertcoords(tGPsdata *p,
}
else {
float mval_prj[2];
- float rvec[3], dvec[3];
- float zfac;
+ float rvec[3];
/* Current method just converts each point in screen-coordinates to
* 3D-coordinates using the 3D-cursor as reference. In general, this
@@ -339,13 +338,14 @@ static void annotation_stroke_convertcoords(tGPsdata *p,
*/
annotation_get_3d_reference(p, rvec);
- zfac = ED_view3d_calc_zfac(p->region->regiondata, rvec, NULL);
+ const float zfac = ED_view3d_calc_zfac(p->region->regiondata, rvec);
if (ED_view3d_project_float_global(p->region, rvec, mval_prj, V3D_PROJ_TEST_NOP) ==
V3D_PROJ_RET_OK) {
- float mval_f[2];
- sub_v2_v2v2(mval_f, mval_prj, mval);
- ED_view3d_win_to_delta(p->region, mval_f, dvec, zfac);
+ float dvec[3];
+ float xy_delta[2];
+ sub_v2_v2v2(xy_delta, mval_prj, mval);
+ ED_view3d_win_to_delta(p->region, xy_delta, zfac, dvec);
sub_v3_v3v3(out, rvec, dvec);
}
else {
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 9442b2edc13..5409cea2a2a 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -447,21 +447,21 @@ static void gpencil_stroke_convertcoords(tGPsdata *p,
}
float mval_prj[2];
- float rvec[3], dvec[3];
- float mval_f[2];
- float zfac;
+ float rvec[3];
/* Current method just converts each point in screen-coordinates to
* 3D-coordinates using the 3D-cursor as reference. In general, this
* works OK, but it could of course be improved. */
gpencil_get_3d_reference(p, rvec);
- zfac = ED_view3d_calc_zfac(p->region->regiondata, rvec, NULL);
+ const float zfac = ED_view3d_calc_zfac(p->region->regiondata, rvec);
if (ED_view3d_project_float_global(p->region, rvec, mval_prj, V3D_PROJ_TEST_NOP) ==
V3D_PROJ_RET_OK) {
- sub_v2_v2v2(mval_f, mval_prj, mval);
- ED_view3d_win_to_delta(p->region, mval_f, dvec, zfac);
+ float dvec[3];
+ float xy_delta[2];
+ sub_v2_v2v2(xy_delta, mval_prj, mval);
+ ED_view3d_win_to_delta(p->region, xy_delta, zfac, dvec);
sub_v3_v3v3(out, rvec, dvec);
}
else {
diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c
index ebe879959c9..67325e8a3d1 100644
--- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c
+++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c
@@ -507,7 +507,7 @@ static void gpencil_brush_grab_calc_dvec(tGP_BrushEditData *gso)
/* Convert mouse-movements to movement vector */
RegionView3D *rv3d = gso->region->regiondata;
float *rvec = gso->object->loc;
- float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
+ const float zfac = ED_view3d_calc_zfac(rv3d, rvec);
float mval_f[2];
@@ -525,7 +525,7 @@ static void gpencil_brush_grab_calc_dvec(tGP_BrushEditData *gso)
copy_v2_v2(mval_f, r);
}
- ED_view3d_win_to_delta(gso->region, mval_f, gso->dvec, zfac);
+ ED_view3d_win_to_delta(gso->region, mval_f, zfac, gso->dvec);
}
/* Apply grab transform to all relevant points of the affected strokes */
@@ -624,17 +624,16 @@ static void gpencil_brush_calc_midpoint(tGP_BrushEditData *gso)
*/
RegionView3D *rv3d = gso->region->regiondata;
const float *rvec = gso->object->loc;
- float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
+ const float zfac = ED_view3d_calc_zfac(rv3d, rvec);
- float mval_f[2];
- copy_v2_v2(mval_f, gso->mval);
float mval_prj[2];
- float dvec[3];
if (ED_view3d_project_float_global(gso->region, rvec, mval_prj, V3D_PROJ_TEST_NOP) ==
V3D_PROJ_RET_OK) {
- sub_v2_v2v2(mval_f, mval_prj, mval_f);
- ED_view3d_win_to_delta(gso->region, mval_f, dvec, zfac);
+ float dvec[3];
+ float xy_delta[2];
+ sub_v2_v2v2(xy_delta, mval_prj, gso->mval);
+ ED_view3d_win_to_delta(gso->region, xy_delta, zfac, dvec);
sub_v3_v3v3(gso->dvec, rvec, dvec);
}
else {
@@ -830,10 +829,10 @@ static bool gpencil_brush_randomize_apply(tGP_BrushEditData *gso,
/* 3D: Project to 3D space */
bool flip;
RegionView3D *rv3d = gso->region->regiondata;
- float zfac = ED_view3d_calc_zfac(rv3d, &pt->x, &flip);
+ const float zfac = ED_view3d_calc_zfac_ex(rv3d, &pt->x, &flip);
if (flip == false) {
float dvec[3];
- ED_view3d_win_to_delta(gso->gsc.region, svec, dvec, zfac);
+ ED_view3d_win_to_delta(gso->gsc.region, svec, zfac, dvec);
add_v3_v3(&pt->x, dvec);
/* compute lock axis */
gpencil_sculpt_compute_lock_axis(gso, pt, save_pt);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index c0777ac3105..9a658b68f21 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -822,17 +822,16 @@ bool gpencil_point_xy_to_3d(const GP_SpaceConversion *gsc,
ED_gpencil_drawing_reference_get(scene, gsc->ob, scene->toolsettings->gpencil_v3d_align, rvec);
- float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
+ float zfac = ED_view3d_calc_zfac(rv3d, rvec);
- float mval_f[2], mval_prj[2];
- float dvec[3];
-
- copy_v2_v2(mval_f, screen_co);
+ float mval_prj[2];
if (ED_view3d_project_float_global(gsc->region, rvec, mval_prj, V3D_PROJ_TEST_NOP) ==
V3D_PROJ_RET_OK) {
- sub_v2_v2v2(mval_f, mval_prj, mval_f);
- ED_view3d_win_to_delta(gsc->region, mval_f, dvec, zfac);
+ float dvec[3];
+ float xy_delta[2];
+ sub_v2_v2v2(xy_delta, mval_prj, screen_co);
+ ED_view3d_win_to_delta(gsc->region, xy_delta, zfac, dvec);
sub_v3_v3v3(r_out, rvec, dvec);
return true;
@@ -863,21 +862,21 @@ void gpencil_stroke_convertcoords_tpoint(Scene *scene,
*/
}
else {
- float mval_f[2] = {UNPACK2(point2D->m_xy)};
float mval_prj[2];
- float rvec[3], dvec[3];
- float zfac;
+ float rvec[3];
/* Current method just converts each point in screen-coordinates to
* 3D-coordinates using the 3D-cursor as reference.
*/
ED_gpencil_drawing_reference_get(scene, ob, ts->gpencil_v3d_align, rvec);
- zfac = ED_view3d_calc_zfac(region->regiondata, rvec, NULL);
+ const float zfac = ED_view3d_calc_zfac(region->regiondata, rvec);
if (ED_view3d_project_float_global(region, rvec, mval_prj, V3D_PROJ_TEST_NOP) ==
V3D_PROJ_RET_OK) {
- sub_v2_v2v2(mval_f, mval_prj, mval_f);
- ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
+ float dvec[3];
+ float xy_delta[2];
+ sub_v2_v2v2(xy_delta, mval_prj, point2D->m_xy);
+ ED_view3d_win_to_delta(region, xy_delta, zfac, dvec);
sub_v3_v3v3(r_out, rvec, dvec);
}
else {
@@ -2005,19 +2004,19 @@ static void gpencil_stroke_convertcoords(ARegion *region,
const float origin[3],
float out[3])
{
- float mval_f[2] = {UNPACK2(point2D->m_xy)};
float mval_prj[2];
- float rvec[3], dvec[3];
- float zfac;
+ float rvec[3];
copy_v3_v3(rvec, origin);
- zfac = ED_view3d_calc_zfac(region->regiondata, rvec, NULL);
+ const float zfac = ED_view3d_calc_zfac(region->regiondata, rvec);
if (ED_view3d_project_float_global(region, rvec, mval_prj, V3D_PROJ_TEST_NOP) ==
V3D_PROJ_RET_OK) {
- sub_v2_v2v2(mval_f, mval_prj, mval_f);
- ED_view3d_win_to_delta(region, mval_f, dvec, zfac);
+ float dvec[3];
+ float xy_delta[2];
+ sub_v2_v2v2(xy_delta, mval_prj, point2D->m_xy);
+ ED_view3d_win_to_delta(region, xy_delta, zfac, dvec);
sub_v3_v3v3(out, rvec, dvec);
}
else {
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 18b63403fcb..b1435e76eb2 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -507,9 +507,18 @@ float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3]);
float ED_view3d_pixel_size_no_ui_scale(const struct RegionView3D *rv3d, const float co[3]);
/**
- * Calculate a depth value from \a co, use with #ED_view3d_win_to_delta
+ * Calculate a depth value from \a co, use with #ED_view3d_win_to_delta.
+ *
+ * \param r_flip: Set to `zfac < 0.0` before the value is made signed.
+ * Since it's important in some cases to know if the value was flipped.
+ *
+ * \return The unsigned depth component of `co` multiplied by `rv3d->persmat` matrix,
+ * with additional sanitation to ensure the result is never negative
+ * as this isn't useful for tool-code.
*/
-float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip);
+float ED_view3d_calc_zfac_ex(const struct RegionView3D *rv3d, const float co[3], bool *r_flip);
+/** See #ED_view3d_calc_zfac_ex doc-string. */
+float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3]);
/**
* Calculate a depth value from `co` (result should only be used for comparison).
*/
@@ -627,16 +636,24 @@ bool ED_view3d_win_to_3d_on_plane_int(const struct ARegion *region,
float r_out[3]);
/**
* Calculate a 3d difference vector from 2d window offset.
- * note that #ED_view3d_calc_zfac() must be called first to determine
+ *
+ * \note that #ED_view3d_calc_zfac() must be called first to determine
* the depth used to calculate the delta.
+ *
+ * When the `zfac` is calculated based on a world-space location directly under the cursor,
+ * the value of `r_out` can be subtracted from #RegionView3D.ofs to pan the view
+ * with the contents following the cursor perfectly (without sliding).
+ *
* \param region: The region (used for the window width and height).
- * \param mval: The area relative 2d difference (such as `event->mval[0] - other_x`).
- * \param out: The resulting world-space delta.
+ * \param xy_delta: 2D difference (in pixels) such as `event->mval[0] - other_x`.
+ * \param zfac: The depth result typically calculated by by #ED_view3d_calc_zfac
+ * (see it's doc-string for details).
+ * \param r_out: The resulting world-space delta.
*/
void ED_view3d_win_to_delta(const struct ARegion *region,
- const float mval[2],
- float out[3],
- float zfac);
+ const float xy_delta[2],
+ float zfac,
+ float r_out[3]);
/**
* Calculate a 3d origin from 2d window coordinates.
* \note Orthographic views have a less obvious origin,
@@ -645,23 +662,23 @@ void ED_view3d_win_to_delta(const struct ARegion *region,
*
* \param region: The region (used for the window width and height).
* \param mval: The area relative 2d location (such as event->mval converted to floats).
- * \param out: The resulting normalized world-space direction vector.
+ * \param r_out: The resulting normalized world-space direction vector.
*/
-void ED_view3d_win_to_origin(const struct ARegion *region, const float mval[2], float out[3]);
+void ED_view3d_win_to_origin(const struct ARegion *region, const float mval[2], float r_out[3]);
/**
* Calculate a 3d direction vector from 2d window coordinates.
* This direction vector starts and the view in the direction of the 2d window coordinates.
* In orthographic view all window coordinates yield the same vector.
*
- * \note doesn't rely on ED_view3d_calc_zfac
+ * \note doesn't rely on #ED_view3d_calc_zfac
* for perspective view, get the vector direction to
* the mouse cursor as a normalized vector.
*
* \param region: The region (used for the window width and height).
* \param mval: The area relative 2d location (such as event->mval converted to floats).
- * \param out: The resulting normalized world-space direction vector.
+ * \param r_out: The resulting normalized world-space direction vector.
*/
-void ED_view3d_win_to_vector(const struct ARegion *region, const float mval[2], float out[3]);
+void ED_view3d_win_to_vector(const struct ARegion *region, const float mval[2], float r_out[3]);
/**
* Calculate a 3d segment from 2d window coordinates.
* This ray_start is located at the viewpoint, ray_end is a far point.
diff --git a/source/blender/editors/mesh/editmesh_bisect.c b/source/blender/editors/mesh/editmesh_bisect.c
index 58bd906101c..7b251b77750 100644
--- a/source/blender/editors/mesh/editmesh_bisect.c
+++ b/source/blender/editors/mesh/editmesh_bisect.c
@@ -77,14 +77,14 @@ static void mesh_bisect_interactive_calc(bContext *C,
const float *co_ref = rv3d->ofs;
float co_a_ss[2] = {x_start, y_start}, co_b_ss[2] = {x_end, y_end}, co_delta_ss[2];
float co_a[3], co_b[3];
- const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL);
+ const float zfac = ED_view3d_calc_zfac(rv3d, co_ref);
/* view vector */
ED_view3d_win_to_vector(region, co_a_ss, co_a);
/* view delta */
sub_v2_v2v2(co_delta_ss, co_a_ss, co_b_ss);
- ED_view3d_win_to_delta(region, co_delta_ss, co_b, zfac);
+ ED_view3d_win_to_delta(region, co_delta_ss, zfac, co_b);
/* cross both to get a normal */
cross_v3_v3v3(plane_no, co_a, co_b);
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index 6307f6dc37f..fc815ebe682 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -4684,7 +4684,7 @@ static int brush_edit_init(bContext *C, wmOperator *op)
bedit->ob = ob;
bedit->edit = edit;
- bedit->zfac = ED_view3d_calc_zfac(region->regiondata, min, NULL);
+ bedit->zfac = ED_view3d_calc_zfac(region->regiondata, min);
/* cache view depths and settings for re-use */
PE_set_view3d_data(C, &bedit->data);
@@ -4757,7 +4757,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
switch (pset->brushtype) {
case PE_BRUSH_COMB: {
- const float mval_f[2] = {dx, dy};
+ const float xy_delta[2] = {dx, dy};
data.mval = mval;
data.rad = pe_brush_size_get(scene, brush);
@@ -4771,7 +4771,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
invert_m4_m4(ob->imat, ob->obmat);
- ED_view3d_win_to_delta(region, mval_f, vec, bedit->zfac);
+ ED_view3d_win_to_delta(region, xy_delta, bedit->zfac, vec);
data.dvec = vec;
foreach_mouse_hit_key(&data, brush_comb, selected);
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index d470e6a3050..31b965c6a92 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -130,13 +130,12 @@ float paint_calc_object_space_radius(ViewContext *vc, const float center[3], flo
{
Object *ob = vc->obact;
float delta[3], scale, loc[3];
- const float mval_f[2] = {pixel_radius, 0.0f};
- float zfac;
+ const float xy_delta[2] = {pixel_radius, 0.0f};
mul_v3_m4v3(loc, ob->obmat, center);
- zfac = ED_view3d_calc_zfac(vc->rv3d, loc, NULL);
- ED_view3d_win_to_delta(vc->region, mval_f, delta, zfac);
+ const float zfac = ED_view3d_calc_zfac(vc->rv3d, loc);
+ ED_view3d_win_to_delta(vc->region, xy_delta, zfac, delta);
scale = fabsf(mat4_to_scale(ob->obmat));
scale = (scale == 0.0f) ? 1.0f : scale;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 919385f82e7..70ff7596d6d 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2648,13 +2648,13 @@ static void update_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int t
static void calc_local_y(ViewContext *vc, const float center[3], float y[3])
{
Object *ob = vc->obact;
- float loc[3], mval_f[2] = {0.0f, 1.0f};
- float zfac;
+ float loc[3];
+ const float xy_delta[2] = {0.0f, 1.0f};
mul_v3_m4v3(loc, ob->imat, center);
- zfac = ED_view3d_calc_zfac(vc->rv3d, loc, NULL);
+ const float zfac = ED_view3d_calc_zfac(vc->rv3d, loc);
- ED_view3d_win_to_delta(vc->region, mval_f, y, zfac);
+ ED_view3d_win_to_delta(vc->region, xy_delta, zfac, y);
normalize_v3(y);
add_v3_v3(y, ob->loc);
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,
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index b006b13d217..67b0d5c85ac 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -177,8 +177,8 @@ void convertViewVec(TransInfo *t, float r_vec[3], double dx, double dy)
r_vec[1] = dy;
}
else {
- const float mval_f[2] = {(float)dx, (float)dy};
- ED_view3d_win_to_delta(t->region, mval_f, r_vec, t->zfac);
+ const float xy_delta[2] = {(float)dx, (float)dy};
+ ED_view3d_win_to_delta(t->region, xy_delta, t->zfac, r_vec);
}
}
else if (t->spacetype == SPACE_IMAGE) {
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index 64ef170a13f..81b35e4539b 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -1041,8 +1041,7 @@ static void setNearestAxis3d(TransInfo *t)
* and to overflow the short integers.
* The formula used is a bit stupid, just a simplification of the subtraction
* of two 2D points 30 pixels apart (that's the last factor in the formula) after
- * projecting them with ED_view3d_win_to_delta and then get the length of that vector.
- */
+ * projecting them with #ED_view3d_win_to_delta and then get the length of that vector. */
zfac = mul_project_m4_v3_zfac(t->persmat, t->center_global);
zfac = len_v3(t->persinv[0]) * 2.0f / t->region->winx * zfac * 30.0f;
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 2b523461800..8987325145c 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1146,7 +1146,7 @@ void calculateCenter(TransInfo *t)
projectFloatView(t, axis, t->center2d);
- /* rotate only needs correct 2d center, grab needs ED_view3d_calc_zfac() value */
+ /* Rotate only needs correct 2d center, grab needs #ED_view3d_calc_zfac() value. */
if (t->mode == TFM_TRANSLATION) {
copy_v3_v3(t->center_global, axis);
}
@@ -1155,17 +1155,16 @@ void calculateCenter(TransInfo *t)
}
if (t->spacetype == SPACE_VIEW3D) {
- /* ED_view3d_calc_zfac() defines a factor for perspective depth correction,
- * used in ED_view3d_win_to_delta() */
+ /* #ED_view3d_calc_zfac() defines a factor for perspective depth correction,
+ * used in #ED_view3d_win_to_delta(). */
- /* zfac is only used convertViewVec only in cases operator was invoked in RGN_TYPE_WINDOW
- * and never used in other cases.
+ /* NOTE: `t->zfac` is only used #convertViewVec only in cases operator was invoked in
+ * #RGN_TYPE_WINDOW and never used in other cases.
*
- * We need special case here as well, since ED_view3d_calc_zfac will crash when called
- * for a region different from RGN_TYPE_WINDOW.
- */
+ * We need special case here as well, since #ED_view3d_calc_zfac will crash when called
+ * for a region different from #RGN_TYPE_WINDOW. */
if (t->region->regiontype == RGN_TYPE_WINDOW) {
- t->zfac = ED_view3d_calc_zfac(t->region->regiondata, t->center_global, NULL);
+ t->zfac = ED_view3d_calc_zfac(t->region->regiondata, t->center_global);
}
else {
t->zfac = 0.0f;
diff --git a/source/blender/editors/transform/transform_mode_vert_slide.c b/source/blender/editors/transform/transform_mode_vert_slide.c
index 0afc527d4a8..77c5707d814 100644
--- a/source/blender/editors/transform/transform_mode_vert_slide.c
+++ b/source/blender/editors/transform/transform_mode_vert_slide.c
@@ -146,9 +146,9 @@ static void calcVertSlideMouseActiveEdges(struct TransInfo *t, const int mval[2]
* by finding the closest edge in local-space.
* However this skews the outcome with non-uniform-scale. */
- /* first get the direction of the original mouse position */
+ /* First get the direction of the original mouse position. */
sub_v2_v2v2(dir, imval_fl, mval_fl);
- ED_view3d_win_to_delta(t->region, dir, dir, t->zfac);
+ ED_view3d_win_to_delta(t->region, dir, t->zfac, dir);
normalize_v3(dir);
for (i = 0, sv = sld->sv; i < sld->totsv; i++, sv++) {
@@ -425,18 +425,18 @@ void drawVertSlide(TransInfo *t)
/* direction from active vertex! */
if ((t->mval[0] != t->mouse.imval[0]) || (t->mval[1] != t->mouse.imval[1])) {
float zfac;
- float mval_ofs[2];
+ float xy_delta[2];
float co_orig_3d[3];
float co_dest_3d[3];
- mval_ofs[0] = t->mval[0] - t->mouse.imval[0];
- mval_ofs[1] = t->mval[1] - t->mouse.imval[1];
+ xy_delta[0] = t->mval[0] - t->mouse.imval[0];
+ xy_delta[1] = t->mval[1] - t->mouse.imval[1];
mul_v3_m4v3(
co_orig_3d, TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat, curr_sv->co_orig_3d);
- zfac = ED_view3d_calc_zfac(t->region->regiondata, co_orig_3d, NULL);
+ zfac = ED_view3d_calc_zfac(t->region->regiondata, co_orig_3d);
- ED_view3d_win_to_delta(t->region, mval_ofs, co_dest_3d, zfac);
+ ED_view3d_win_to_delta(t->region, xy_delta, zfac, co_dest_3d);
invert_m4_m4(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->imat,
TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat);
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index 9d4311bd693..9379e72bdd9 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -158,7 +158,7 @@ void GpencilIO::create_object_list()
float zdepth = 0;
if (rv3d_) {
if (rv3d_->is_persp) {
- zdepth = ED_view3d_calc_zfac(rv3d_, object->obmat[3], nullptr);
+ zdepth = ED_view3d_calc_zfac(rv3d_, object->obmat[3]);
}
else {
zdepth = -dot_v3v3(rv3d_->viewinv[2], object->obmat[3]);