diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-05 05:27:28 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-05 05:27:28 +0400 |
commit | 7339b09e7f2fa59cb672ce103036552fcbea0a72 (patch) | |
tree | cd38eda04934f2617cc9b6502c02d48b8e4ca94a /source/blender | |
parent | 3eba19881894c17d2645f9e9723eae1be822e55a (diff) |
add ED_view3d_project_float_global, ED_view3d_project_float_object, ED_view3d_project_float_ex function calls and cleanup cursor3d set function which had some odd logic.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 6 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 51 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 36 |
3 files changed, 60 insertions, 33 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 30eb38a14bb..7642ce565a0 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -144,6 +144,12 @@ eV3DProjStatus ED_view3d_project_int_ex(struct ARegion *ar, float perspmat[4][4] eV3DProjStatus ED_view3d_project_int_global(struct ARegion *ar, const float co[3], int r_co[2], eV3DProjTest flag); eV3DProjStatus ED_view3d_project_int_object(struct ARegion *ar, const float co[3], int r_co[2], eV3DProjTest flag); +/* *** float *** */ +eV3DProjStatus ED_view3d_project_float_ex(struct ARegion *ar, float perspmat[4][4], const int is_local, + const float co[3], float r_co[2], eV3DProjTest flag); +eV3DProjStatus ED_view3d_project_float_global(struct ARegion *ar, const float co[3], float r_co[2], eV3DProjTest flag); +eV3DProjStatus ED_view3d_project_float_object(struct ARegion *ar, const float co[3], float r_co[2], eV3DProjTest flag); + void ED_view3d_project_float(struct ARegion *ar, const float co[3], float r_co[2]); void ED_view3d_project_float_noclip(struct ARegion *ar, const float co[3], float r_co[2]); void ED_view3d_project_float_v2_m4(const struct ARegion *a, const float co[3], float r_co[2], float mat[4][4]); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 800b4ac53c8..735f7b5ea4a 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -3514,60 +3514,49 @@ void VIEW3D_OT_clip_border(wmOperatorType *ot) /* ***************** 3d cursor cursor op ******************* */ /* mx my in region coords */ -static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) +static int view3d_cursor3d_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) { Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3]; - int mval[2]; -// short ctrl= 0; // XXX + float *fp = NULL; + float mval_fl[2]; int flip; - eV3DProjStatus ret; fp = give_cursor(scene, v3d); -// if (obedit && ctrl) lr_click= 1; - copy_v3_v3(oldcurs, fp); - - mval[0] = IS_CLIPPED; - ret = ED_view3d_project_int_global(ar, fp, mval, V3D_PROJ_TEST_NOP); flip = initgrabz(rv3d, fp[0], fp[1], fp[2]); - /* reset the depth based on the view offset */ + /* reset the depth based on the view offset (we _know_ the offset is infront of us) */ if (flip) { negate_v3_v3(fp, rv3d->ofs); - - /* re initialize */ - mval[0] = IS_CLIPPED; - ED_view3d_project_int_global(ar, fp, mval, V3D_PROJ_TEST_NOP); - flip = initgrabz(rv3d, fp[0], fp[1], fp[2]); - (void)flip; + /* re initialize, no need to check flip again */ + /* flip = */ initgrabz(rv3d, fp[0], fp[1], fp[2]); } - if (mval[0] != IS_CLIPPED) { - short depth_used = 0; + if (ED_view3d_project_float_global(ar, fp, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) { + short depth_used = FALSE; if (U.uiflag & USER_ZBUF_CURSOR) { /* maybe this should be accessed some other way */ view3d_operator_needs_opengl(C); if (ED_view3d_autodist(scene, ar, v3d, event->mval, fp)) - depth_used = 1; + depth_used = TRUE; } - if (depth_used == 0) { - float mval_f[2]; - VECSUB2D(mval_f, mval, event->mval); - ED_view3d_win_to_delta(ar, mval_f, dvec); + if (depth_used == FALSE) { + float dvec[3]; + VECSUB2D(mval_fl, mval_fl, event->mval); + ED_view3d_win_to_delta(ar, mval_fl, dvec); sub_v3_v3(fp, dvec); } } else { - - dx = ((float)(event->mval[0] - (ar->winx / 2))) * rv3d->zfac / (ar->winx / 2); - dy = ((float)(event->mval[1] - (ar->winy / 2))) * rv3d->zfac / (ar->winy / 2); - - fz = rv3d->persmat[0][3] * fp[0] + rv3d->persmat[1][3] * fp[1] + rv3d->persmat[2][3] * fp[2] + rv3d->persmat[3][3]; - fz = fz / rv3d->zfac; + const float dx = ((float)(event->mval[0] - (ar->winx / 2))) * rv3d->zfac / (ar->winx / 2); + const float dy = ((float)(event->mval[1] - (ar->winy / 2))) * rv3d->zfac / (ar->winy / 2); + const float fz = (rv3d->persmat[0][3] * fp[0] + + rv3d->persmat[1][3] * fp[1] + + rv3d->persmat[2][3] * fp[2] + + rv3d->persmat[3][3]) / rv3d->zfac; fp[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy + rv3d->persinv[2][0] * fz) - rv3d->ofs[0]; fp[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy + rv3d->persinv[2][1] * fz) - rv3d->ofs[1]; @@ -3591,7 +3580,7 @@ void VIEW3D_OT_cursor3d(wmOperatorType *ot) ot->idname = "VIEW3D_OT_cursor3d"; /* api callbacks */ - ot->invoke = set_3dcursor_invoke; + ot->invoke = view3d_cursor3d_invoke; ot->poll = ED_operator_view3d_active; diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index cdb75cdfa74..ac721f3ea2e 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -965,7 +965,7 @@ eV3DProjStatus ED_view3d_project_short_ex(ARegion *ar, float perspmat[4][4], con r_co[1] = (short)floor(tvec[1]); } else { - return V3D_PROJ_RET_OVERFLOW; + ret = V3D_PROJ_RET_OVERFLOW; } } return ret; @@ -984,7 +984,25 @@ eV3DProjStatus ED_view3d_project_int_ex(ARegion *ar, float perspmat[4][4], const r_co[1] = (int)floor(tvec[1]); } else { - return V3D_PROJ_RET_OVERFLOW; + ret = V3D_PROJ_RET_OVERFLOW; + } + } + return ret; +} + +eV3DProjStatus ED_view3d_project_float_ex(ARegion *ar, float perspmat[4][4], const int is_local, + const float co[3], float r_co[2], eV3DProjTest flag) +{ + float tvec[2]; + eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag); + if (ret == V3D_PROJ_RET_SUCCESS) { + if (finite(tvec[0]) && + finite(tvec[1])) + { + copy_v2_v2(r_co, tvec); + } + else { + ret = V3D_PROJ_RET_OVERFLOW; } } return ret; @@ -1016,6 +1034,20 @@ eV3DProjStatus ED_view3d_project_int_object(ARegion *ar, const float co[3], int return ED_view3d_project_int_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag); } +/* --- float --- */ +eV3DProjStatus ED_view3d_project_float_global(ARegion *ar, const float co[3], float r_co[2], eV3DProjTest flag) +{ + RegionView3D *rv3d = ar->regiondata; + return ED_view3d_project_float_ex(ar, rv3d->persmat, FALSE, co, r_co, flag); +} +/* object space, use ED_view3d_init_mats_rv3d before calling */ +eV3DProjStatus ED_view3d_project_float_object(ARegion *ar, const float co[3], float r_co[2], eV3DProjTest flag) +{ + RegionView3D *rv3d = ar->regiondata; + return ED_view3d_project_float_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag); +} + + void ED_view3d_project_float(ARegion *ar, const float co[3], float r_co[2]) { RegionView3D *rv3d = ar->regiondata; |