diff options
author | Campbell Barton <campbell@blender.org> | 2022-10-06 04:26:48 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-10-06 04:35:28 +0300 |
commit | 86352364a60f62ef338655085a4a227e3cd01c5b (patch) | |
tree | 39bd5c8f650b30aefa2fe229e81c143b51496e65 /source/blender/editors/space_view3d | |
parent | 87d737cd792183d409760ab1f0a778abb9f1daa3 (diff) |
3D View: use float for ED_view3d_project_base & minor changes
Using 'short' was historic (as the value was stored in the Base).
Prefer floats which allow sub-pixel distances to be differentiated.
Also remove IS_CLIPPED assignment as this only made sense when the
values were stored in the Base, without any other ways to check
if projection failed.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_project.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_select.cc | 23 |
2 files changed, 21 insertions, 12 deletions
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 498f86e36fd..c5f951bd64c 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -77,14 +77,16 @@ void ED_view3d_project_float_v3_m4(const ARegion *region, eV3DProjStatus ED_view3d_project_base(const struct ARegion *region, struct Base *base, - short r_co[2]) + float r_co[2]) { - eV3DProjStatus ret = ED_view3d_project_short_global( + eV3DProjStatus ret = ED_view3d_project_float_global( region, base->object->obmat[3], r_co, V3D_PROJ_TEST_CLIP_DEFAULT); + /* Prevent uninitialized values when projection fails, + * although the callers should check the return value. */ if (ret != V3D_PROJ_RET_OK) { - r_co[0] = IS_CLIPPED; - r_co[1] = 0; + r_co[0] = -1.0; + r_co[1] = -1.0; } return ret; diff --git a/source/blender/editors/space_view3d/view3d_select.cc b/source/blender/editors/space_view3d/view3d_select.cc index 5e9720d119e..b14536213b7 100644 --- a/source/blender/editors/space_view3d/view3d_select.cc +++ b/source/blender/editors/space_view3d/view3d_select.cc @@ -574,11 +574,16 @@ static bool do_lasso_select_objects(ViewContext *vc, BKE_view_layer_synced_ensure(vc->scene, vc->view_layer); LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(vc->view_layer)) { if (BASE_SELECTABLE(v3d, base)) { /* Use this to avoid unnecessary lasso look-ups. */ - short region_co[2]; + float region_co[2]; const bool is_select = base->flag & BASE_SELECTED; - const bool is_inside = - (ED_view3d_project_base(vc->region, base, region_co) == V3D_PROJ_RET_OK) && - BLI_lasso_is_point_inside(mcoords, mcoords_len, region_co[0], region_co[1], IS_CLIPPED); + const bool is_inside = (ED_view3d_project_base(vc->region, base, region_co) == + V3D_PROJ_RET_OK) && + BLI_lasso_is_point_inside(mcoords, + mcoords_len, + int(region_co[0]), + int(region_co[1]), + /* Dummy value. */ + INT_MAX); const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside); if (sel_op_result != -1) { ED_object_base_select(base, sel_op_result ? BA_SELECT : BA_DESELECT); @@ -1589,6 +1594,10 @@ static bool object_mouse_select_menu(bContext *C, const SelectPick_Params *params, Base **r_basact) { + + const float mval_fl[2] = {float(mval[0]), float(mval[1])}; + /* Distance from object center to use for selection. */ + const float dist_threshold = 15 * U.pixelsize; int base_count = 0; bool ok; LinkNodePair linklist = {nullptr, nullptr}; @@ -1608,11 +1617,9 @@ static bool object_mouse_select_menu(bContext *C, } } else { - const int dist = 15 * U.pixelsize; - short region_co[2]; + float region_co[2]; if (ED_view3d_project_base(vc->region, base, region_co) == V3D_PROJ_RET_OK) { - const int delta_px[2] = {region_co[0] - mval[0], region_co[1] - mval[1]}; - if (len_manhattan_v2_int(delta_px) < dist) { + if (len_manhattan_v2v2(mval_fl, region_co) < dist_threshold) { ok = true; } } |