replace view3d_get_view_aligned_coordinate with ED_view3d_win_to_3d_int()

This commit is contained in:
Campbell Barton 2013-03-26 02:37:29 +00:00
parent ae0e356de6
commit 09721bffc0
7 changed files with 46 additions and 40 deletions

@ -4644,7 +4644,7 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
copy_v3_v3(location, give_cursor(vc.scene, vc.v3d));
}
view3d_get_view_aligned_coordinate(vc.ar, location, event->mval, true);
ED_view3d_win_to_3d_int(vc.ar, location, event->mval, location);
RNA_float_set_array(op->ptr, "location", location);
}

@ -199,6 +199,7 @@ float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bo
void ED_view3d_win_to_ray(const struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]);
void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, const float coord[3], float vec[3]);
void ED_view3d_win_to_3d(const struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]);
void ED_view3d_win_to_3d_int(const struct ARegion *ar, const float depth_pt[3], const int mval[2], float out[3]);
void ED_view3d_win_to_delta(const struct ARegion *ar, const float mval[2], float out[3], const float zfac);
void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]);
void ED_view3d_win_to_segment(const struct ARegion *ar, struct View3D *v3d, const float mval[2],
@ -261,7 +262,6 @@ short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigne
void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
void view3d_operator_needs_opengl(const struct bContext *C);
void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar);
bool view3d_get_view_aligned_coordinate(struct ARegion *ar, float fp[3], const int mval[2], const bool do_fallback);
void view3d_opengl_read_pixels(struct ARegion *ar, int x, int y, int w, int h, int format, int type, void *data);
void view3d_get_transformation(const struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats);

@ -861,7 +861,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
copy_v3_v3(min, cent);
mul_m4_v3(vc.obedit->obmat, min); /* view space */
view3d_get_view_aligned_coordinate(vc.ar, min, event->mval, true);
ED_view3d_win_to_3d_int(vc.ar, min, event->mval, min);
mul_m4_v3(vc.obedit->imat, min); // back in object space
sub_v3_v3(min, cent);
@ -910,7 +910,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
BMOIter oiter;
copy_v3_v3(min, curs);
view3d_get_view_aligned_coordinate(vc.ar, min, event->mval, false);
ED_view3d_win_to_3d_int(vc.ar, min, event->mval, min);
invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
mul_m4_v3(vc.obedit->imat, min); // back in object space

@ -2683,7 +2683,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *UNUSED(op), const wmE
else {
/* fallback to simple pan */
negate_v3_v3(new_ofs, rv3d->ofs);
view3d_get_view_aligned_coordinate(ar, new_ofs, event->mval, true);
ED_view3d_win_to_3d_int(ar, new_ofs, event->mval, new_ofs);
}
negate_v3(new_ofs);
view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, NULL, NULL);

@ -347,6 +347,39 @@ void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3],
normalize_v3(vec);
}
/* very similar to ED_view3d_win_to_3d() but has no advantage, de-duplicating */
#if 0
bool view3d_get_view_aligned_coordinate(ARegion *ar, float fp[3], const int mval[2], const bool do_fallback)
{
RegionView3D *rv3d = ar->regiondata;
float dvec[3];
int mval_cpy[2];
eV3DProjStatus ret;
ret = ED_view3d_project_int_global(ar, fp, mval_cpy, V3D_PROJ_TEST_NOP);
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(ar, mval_f, dvec, zfac);
sub_v3_v3(fp, dvec);
return true;
}
else {
/* fallback to the view center */
if (do_fallback) {
negate_v3_v3(fp, rv3d->ofs);
return view3d_get_view_aligned_coordinate(ar, fp, mval, false);
}
else {
return false;
}
}
}
#endif
/**
* Calculate a 3d location from 2d window coordinates.
* \param ar The region (used for the window width and height).
@ -357,7 +390,7 @@ void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3],
void ED_view3d_win_to_3d(const ARegion *ar, const float depth_pt[3], const float mval[2], float out[3])
{
RegionView3D *rv3d = ar->regiondata;
float line_sta[3];
float line_end[3];
@ -384,6 +417,12 @@ void ED_view3d_win_to_3d(const ARegion *ar, const float depth_pt[3], const float
}
}
void ED_view3d_win_to_3d_int(const ARegion *ar, const float depth_pt[3], const int mval[2], float out[3])
{
const float mval_fl[2] = {mval[0], mval[1]};
ED_view3d_win_to_3d(ar, depth_pt, mval_fl, out);
}
/**
* Calculate a 3d difference vector from 2d window offset.
* note that ED_view3d_calc_zfac() must be called first to determine

@ -653,7 +653,7 @@ static void view3d_ruler_free(RulerInfo *ruler_info)
static void view3d_ruler_item_project(RulerInfo *ruler_info, float r_co[3],
const int xy[2])
{
view3d_get_view_aligned_coordinate(ruler_info->ar, r_co, xy, true);
ED_view3d_win_to_3d_int(ruler_info->ar, r_co, xy, r_co);
}
/* use for mousemove events */

@ -108,39 +108,6 @@ void view3d_set_viewcontext(bContext *C, ViewContext *vc)
vc->obedit = CTX_data_edit_object(C);
}
/**
* Re-project \a fp so it stays on the same view-plane but is under \a mval (normally the cursor location).
*/
bool view3d_get_view_aligned_coordinate(ARegion *ar, float fp[3], const int mval[2], const bool do_fallback)
{
RegionView3D *rv3d = ar->regiondata;
float dvec[3];
int mval_cpy[2];
eV3DProjStatus ret;
ret = ED_view3d_project_int_global(ar, fp, mval_cpy, V3D_PROJ_TEST_NOP);
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(ar, mval_f, dvec, zfac);
sub_v3_v3(fp, dvec);
return true;
}
else {
/* fallback to the view center */
if (do_fallback) {
negate_v3_v3(fp, rv3d->ofs);
return view3d_get_view_aligned_coordinate(ar, fp, mval, false);
}
else {
return false;
}
}
}
/*
* ob == NULL if you want global matrices
* */