[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55091] trunk/blender/source/blender: ruler arc draw clamps to line length and simplify projection.
Campbell Barton
ideasman42 at gmail.com
Thu Mar 7 17:12:36 CET 2013
Revision: 55091
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55091
Author: campbellbarton
Date: 2013-03-07 16:12:36 +0000 (Thu, 07 Mar 2013)
Log Message:
-----------
ruler arc draw clamps to line length and simplify projection.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_utildefines.h
trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c
Modified: trunk/blender/source/blender/blenlib/BLI_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_utildefines.h 2013-03-07 12:11:38 UTC (rev 55090)
+++ trunk/blender/source/blender/blenlib/BLI_utildefines.h 2013-03-07 16:12:36 UTC (rev 55091)
@@ -295,9 +295,9 @@
#define UNPACK3(a) ((a)[0]), ((a)[1]), ((a)[2])
#define UNPACK4(a) ((a)[0]), ((a)[1]), ((a)[2]), ((a)[3])
/* op may be '&' or '*' */
-#define UNPACK2OP(a, op) op((a)[0]), op((a)[1])
-#define UNPACK3OP(a, op) op((a)[0]), op((a)[1]), op((a)[2])
-#define UNPACK4OP(a, op) op((a)[0]), op((a)[1]), op((a)[2]), op((a)[3])
+#define UNPACK2OP(op, a) op((a)[0]), op((a)[1])
+#define UNPACK3OP(op, a) op((a)[0]), op((a)[1]), op((a)[2])
+#define UNPACK4OP(op, a) op((a)[0]), op((a)[1]), op((a)[2]), op((a)[3])
/* array helpers */
#define ARRAY_LAST_ITEM(arr_start, arr_dtype, elem_size, tot) \
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c 2013-03-07 12:11:38 UTC (rev 55090)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c 2013-03-07 16:12:36 UTC (rev 55091)
@@ -280,7 +280,10 @@
float axis[3];
float angle;
int j;
- const float px_scale = ED_view3d_pixel_size(rv3d, ruler_item->co[1]) * arc_size;
+ const float px_scale = (ED_view3d_pixel_size(rv3d, ruler_item->co[1]) *
+ min_fff(arc_size,
+ len_v2v2(co_ss[0], co_ss[1]) / 2.0f,
+ len_v2v2(co_ss[2], co_ss[1]) / 2.0f));
sub_v3_v3v3(dir_a, ruler_item->co[0], ruler_item->co[1]);
sub_v3_v3v3(dir_b, ruler_item->co[2], ruler_item->co[1]);
@@ -508,31 +511,18 @@
}
static void view3d_ruler_item_project(bContext *C, RulerInfo *UNUSED(ruler_info), float r_co[3],
- const int xy[2], const float ref[3])
+ const int xy[2])
{
- copy_v3_v3(r_co, ref);
ED_view3d_cursor3d_position(C, r_co, xy);
}
/* use for mousemove events */
-static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, const wmEvent *event, const bool use_ofs)
+static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, const wmEvent *event)
{
RulerItem *ruler_item = ruler_item_active_get(ruler_info);
if (ruler_item) {
- RegionView3D *rv3d = ruler_info->ar->regiondata;
- float _ref_ofs[3];
- float const *ref;
-
- if (use_ofs) {
- negate_v3_v3(_ref_ofs, rv3d->ofs);
- ref = _ref_ofs;
- }
- else {
- ref = ruler_item->co[ruler_item->co_index];
- }
-
- view3d_ruler_item_project(C, ruler_info, ruler_item->co[ruler_item->co_index], event->mval, ref);
+ view3d_ruler_item_project(C, ruler_info, ruler_item->co[ruler_item->co_index], event->mval);
return true;
}
else {
@@ -578,7 +568,8 @@
bool do_draw = false;
int exit_code = OPERATOR_RUNNING_MODAL;
RulerInfo *ruler_info = op->customdata;
- RegionView3D *rv3d = ruler_info->ar->regiondata;
+ ARegion *ar = ruler_info->ar;
+ RegionView3D *rv3d = ar->regiondata;
(void)C;
@@ -589,7 +580,7 @@
/* rubber-band angle removal */
RulerItem *ruler_item = ruler_item_active_get(ruler_info);
if (ruler_item && (ruler_item->co_index == 1) && (ruler_item->flag & RULERITEM_USE_ANGLE)) {
- if (!BLI_rcti_isect_pt_v(&ruler_info->ar->winrct, &event->x)) {
+ if (!BLI_rcti_isect_pt_v(&ar->winrct, &event->x)) {
ruler_item->flag &= ~RULERITEM_USE_ANGLE;
do_draw = true;
}
@@ -602,7 +593,6 @@
if (event->ctrl) {
/* Create new line */
- const float ref[3] = {UNPACK3OP(rv3d->ofs, -)};
RulerItem *ruler_item;
/* check if we want to drag an existing point or add a new one */
ruler_info->state = RULER_STATE_DRAG;
@@ -611,7 +601,8 @@
ruler_item_active_set(ruler_info, ruler_item);
ruler_item->co_index = 2;
- view3d_ruler_item_project(C, ruler_info, ruler_item->co[0], event->mval, ref); // XXX
+ negate_v3_v3(ruler_item->co[0], rv3d->ofs);
+ view3d_ruler_item_project(C, ruler_info, ruler_item->co[0], event->mval);
copy_v3_v3(ruler_item->co[2], ruler_item->co[0]);
do_draw = true;
@@ -631,8 +622,24 @@
ruler_item_pick->co_index = 1;
ruler_info->state = RULER_STATE_DRAG;
+ /* find the factor */
+ {
+ float co_ss[2][2];
+ float fac;
+
+ ED_view3d_project_float_global(ar, ruler_item_pick->co[0], co_ss[0], V3D_PROJ_TEST_NOP);
+ ED_view3d_project_float_global(ar, ruler_item_pick->co[2], co_ss[1], V3D_PROJ_TEST_NOP);
+
+ fac = line_point_factor_v2(mval_fl, co_ss[0], co_ss[1]);
+ CLAMP(fac, 0.0f, 1.0f);
+
+ interp_v3_v3v3(ruler_item_pick->co[1],
+ ruler_item_pick->co[0],
+ ruler_item_pick->co[2], fac);
+ }
+
/* update the new location */
- view3d_ruler_item_mousemove(C, ruler_info, event, true);
+ view3d_ruler_item_mousemove(C, ruler_info, event);
do_draw = true;
}
}
@@ -654,7 +661,7 @@
case MOUSEMOVE:
{
if (ruler_info->state == RULER_STATE_DRAG) {
- if (view3d_ruler_item_mousemove(C, ruler_info, event, false)) {
+ if (view3d_ruler_item_mousemove(C, ruler_info, event)) {
do_draw = true;
}
}
@@ -674,7 +681,7 @@
}
if (do_draw) {
- ED_region_tag_redraw(ruler_info->ar);
+ ED_region_tag_redraw(ar);
}
if (ELEM(exit_code, OPERATOR_FINISHED, OPERATOR_CANCELLED)) {
More information about the Bf-blender-cvs
mailing list