ruler3d: replace ED_view3d_cursor3d_position() with lower level function view3d_get_view_aligned_coordinate()

This commit is contained in:
2013-03-09 10:28:28 +00:00
parent 35b9fcb871
commit 4a01ba4ba5
5 changed files with 19 additions and 18 deletions

View File

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

View File

@@ -255,7 +255,7 @@ 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);
int view3d_get_view_aligned_coordinate(struct ViewContext *vc, float fp[3], const int mval[2], const short do_fallback);
bool view3d_get_view_aligned_coordinate(struct ARegion *ar, float fp[3], const int mval[2], const bool do_fallback);
void view3d_get_transformation(const struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats);
/* XXX should move to BLI_math */

View File

@@ -862,7 +862,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
copy_v3_v3(min, cent);
mul_m4_v3(vc.obedit->obmat, min); /* view space */
view3d_get_view_aligned_coordinate(&vc, min, event->mval, TRUE);
view3d_get_view_aligned_coordinate(vc.ar, min, event->mval, true);
mul_m4_v3(vc.obedit->imat, min); // back in object space
sub_v3_v3(min, cent);
@@ -911,7 +911,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
BMOIter oiter;
copy_v3_v3(min, curs);
view3d_get_view_aligned_coordinate(&vc, min, event->mval, FALSE);
view3d_get_view_aligned_coordinate(vc.ar, min, event->mval, false);
invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
mul_m4_v3(vc.obedit->imat, min); // back in object space

View File

@@ -657,10 +657,10 @@ static void view3d_ruler_free(RulerInfo *ruler_info)
MEM_freeN(ruler_info);
}
static void view3d_ruler_item_project(bContext *C, RulerInfo *UNUSED(ruler_info), float r_co[3],
static void view3d_ruler_item_project(RulerInfo *ruler_info, float r_co[3],
const int xy[2])
{
ED_view3d_cursor3d_position(C, r_co, xy);
view3d_get_view_aligned_coordinate(ruler_info->ar, r_co, xy, true);
}
/* use for mousemove events */
@@ -670,7 +670,7 @@ static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, cons
if (ruler_item) {
float *co = ruler_item->co[ruler_item->co_index];
view3d_ruler_item_project(C, ruler_info, co, event->mval);
view3d_ruler_item_project(ruler_info, co, event->mval);
if (event->ctrl) {
const float mval_fl[2] = {UNPACK2(event->mval)};
ED_view3d_snap_co(C, co, mval_fl, true, true, true);
@@ -761,7 +761,7 @@ static int view3d_ruler_modal(bContext *C, wmOperator *op, wmEvent *event)
ruler_item->co_index = 2;
negate_v3_v3(ruler_item->co[0], rv3d->ofs);
view3d_ruler_item_project(C, ruler_info, ruler_item->co[0], event->mval);
view3d_ruler_item_project(ruler_info, ruler_item->co[0], event->mval);
copy_v3_v3(ruler_item->co[2], ruler_item->co[0]);
do_draw = true;

View File

@@ -108,23 +108,24 @@ void view3d_set_viewcontext(bContext *C, ViewContext *vc)
vc->obedit = CTX_data_edit_object(C);
}
int view3d_get_view_aligned_coordinate(ViewContext *vc, float fp[3], const int mval[2], const short do_fallback)
/**
* 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;
mval_cpy[0] = mval[0];
mval_cpy[1] = mval[1];
ret = ED_view3d_project_int_global(ar, fp, mval_cpy, V3D_PROJ_TEST_NOP);
ret = ED_view3d_project_int_global(vc->ar, fp, mval_cpy, V3D_PROJ_TEST_NOP);
initgrabz(vc->rv3d, fp[0], fp[1], fp[2]);
initgrabz(rv3d, fp[0], fp[1], fp[2]);
if (ret == V3D_PROJ_RET_OK) {
const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]),
(float)(mval_cpy[1] - mval[1])};
ED_view3d_win_to_delta(vc->ar, mval_f, dvec);
ED_view3d_win_to_delta(ar, mval_f, dvec);
sub_v3_v3(fp, dvec);
return TRUE;
@@ -132,11 +133,11 @@ int view3d_get_view_aligned_coordinate(ViewContext *vc, float fp[3], const int m
else {
/* fallback to the view center */
if (do_fallback) {
negate_v3_v3(fp, vc->rv3d->ofs);
return view3d_get_view_aligned_coordinate(vc, fp, mval, FALSE);
negate_v3_v3(fp, rv3d->ofs);
return view3d_get_view_aligned_coordinate(ar, fp, mval, false);
}
else {
return FALSE;
return false;
}
}
}