Revision: 57283
http://sourceforge.net/p/brlcad/code/57283
Author: n_reed
Date: 2013-08-29 22:22:49 +0000 (Thu, 29 Aug 2013)
Log Message:
-----------
reduce duplicated lines for converting from screen to view coordinates
Modified Paths:
--------------
brlcad/trunk/src/libtclcad/tclcad_obj.c
Modified: brlcad/trunk/src/libtclcad/tclcad_obj.c
===================================================================
--- brlcad/trunk/src/libtclcad/tclcad_obj.c 2013-08-29 21:53:24 UTC (rev
57282)
+++ brlcad/trunk/src/libtclcad/tclcad_obj.c 2013-08-29 22:22:49 UTC (rev
57283)
@@ -1300,7 +1300,18 @@
{(char *)0, (char *)0, 0, TO_WRAPPER_FUNC_PTR_NULL,
GED_FUNC_PTR_NULL}
};
+static fastf_t
+screen_to_view_x(struct dm *dmp, fastf_t x)
+{
+ return x / dmp->dm_width * 2.0 - 1.0;
+}
+static fastf_t
+screen_to_view_y(struct dm *dmp, fastf_t y)
+{
+ return (y / dmp->dm_height * -2.0 + 1.0) / dmp->dm_aspect;
+}
+
/**
* @brief create the Tcl command for to_open
*
@@ -6323,9 +6334,6 @@
{
int ret;
char *av[4];
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t view;
struct bu_vls pt_vls = BU_VLS_INIT_ZERO;
struct ged_dm_view *gdvp;
@@ -6363,11 +6371,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
gedp->ged_gvp = gdvp->gdv_view;
@@ -6627,9 +6632,6 @@
int UNUSED(maxargs))
{
char *av[6];
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t view;
struct bu_vls pt_vls = BU_VLS_INIT_ZERO;
struct ged_dm_view *gdvp;
@@ -6667,11 +6669,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
bu_vls_printf(&pt_vls, "%lf %lf %lf", view[X], view[Y], view[Z]);
@@ -6699,9 +6698,6 @@
int UNUSED(maxargs))
{
char *av[6];
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t view;
struct bu_vls pt_vls = BU_VLS_INIT_ZERO;
struct ged_dm_view *gdvp;
@@ -6739,11 +6735,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
bu_vls_printf(&pt_vls, "%lf %lf %lf", view[X], view[Y], view[Z]);
@@ -6770,9 +6763,6 @@
int UNUSED(maxargs))
{
char *av[6];
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t view;
struct bu_vls pt_vls = BU_VLS_INIT_ZERO;
struct ged_dm_view *gdvp;
@@ -6810,11 +6800,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
bu_vls_printf(&pt_vls, "%lf %lf %lf", view[X], view[Y], view[Z]);
@@ -6841,9 +6828,6 @@
int UNUSED(maxargs))
{
char *av[6];
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t model;
point_t view;
struct bu_vls pt_vls = BU_VLS_INIT_ZERO;
@@ -6882,11 +6866,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
MAT4X3PNT(model, gdvp->gdv_view->gv_view2model, view);
@@ -6913,9 +6894,6 @@
int UNUSED(maxargs))
{
char *av[6];
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t model;
point_t view;
struct bu_vls pt_vls = BU_VLS_INIT_ZERO;
@@ -6954,11 +6932,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
MAT4X3PNT(model, gdvp->gdv_view->gv_view2model, view);
@@ -7270,8 +7245,6 @@
mat_t mat;
size_t vertex_i;
char *last;
- fastf_t inv_height;
- fastf_t inv_aspect;
if ((last = strrchr(argv[2], '/')) == NULL)
last = (char *)argv[2];
@@ -7312,11 +7285,8 @@
MAT4X3PNT(view, gdvp->gdv_view->gv_model2view,
&botip->vertices[vertex_i*3]);
MAT_COPY(v2m_mat, gdvp->gdv_view->gv_view2model);
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- dx = x * inv_width * 2.0 - 1.0;
- dy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ dx = screen_to_view_x(gdvp->gdv_dmp, x);
+ dy = screen_to_view_y(gdvp->gdv_dmp, y);
dz = view[Z];
rt_db_free_internal(&intern);
@@ -7917,9 +7887,6 @@
char *av[7];
int x, y;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t v_pt, m_pt;
struct bu_vls plist = BU_VLS_INIT_ZERO;
struct bu_vls i_vls = BU_VLS_INIT_ZERO;
@@ -7964,11 +7931,8 @@
gdvp->gdv_view->gv_prevMouseX = x;
gdvp->gdv_view->gv_prevMouseY = y;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
bu_vls_printf(&plist, "{0 ");
@@ -8041,9 +8005,6 @@
char *av[8];
int x, y;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t v_pt, m_pt;
struct ged_dm_view *gdvp;
ged_data_polygon_state *gdpsp;
@@ -8086,11 +8047,8 @@
gdvp->gdv_view->gv_prevMouseX = x;
gdvp->gdv_view->gv_prevMouseY = y;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(v_pt, fx, fy, 1.0);
MAT4X3PNT(m_pt, gdvp->gdv_view->gv_view2model, v_pt);
@@ -8139,9 +8097,6 @@
char *av[7];
int x, y;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t m_pt;
struct bu_vls plist = BU_VLS_INIT_ZERO;
struct bu_vls i_vls = BU_VLS_INIT_ZERO;
@@ -8186,11 +8141,8 @@
gdvp->gdv_view->gv_prevMouseX = x;
gdvp->gdv_view->gv_prevMouseY = y;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
bu_vls_printf(&plist, "{0 ");
@@ -8272,9 +8224,6 @@
char *av[7];
int x, y;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t v_pt, m_pt;
struct bu_vls plist = BU_VLS_INIT_ZERO;
struct bu_vls i_vls = BU_VLS_INIT_ZERO;
@@ -8319,11 +8268,8 @@
gdvp->gdv_view->gv_prevMouseX = x;
gdvp->gdv_view->gv_prevMouseY = y;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
if (gdvp->gdv_view->gv_mode == TCLCAD_POLY_SQUARE_MODE) {
fastf_t dx, dy;
@@ -10181,9 +10127,6 @@
char *av[5];
int x, y;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t v_pt, m_pt;
struct bu_vls plist = BU_VLS_INIT_ZERO;
struct bu_vls bindings = BU_VLS_INIT_ZERO;
@@ -10237,12 +10180,8 @@
gdvp->gdv_view->gv_prevMouseY = y;
gdvp->gdv_view->gv_mode = TCLCAD_POLY_CIRCLE_MODE;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
-
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(v_pt, fx, fy, 1.0);
if (gedp->ged_gvp->gv_grid.ggs_snap)
ged_snap_to_grid(gedp, &v_pt[X], &v_pt[Y]);
@@ -10292,9 +10231,6 @@
char *av[8];
int x, y;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t v_pt, m_pt;
struct ged_dm_view *gdvp;
ged_data_polygon_state *gdpsp;
@@ -10346,12 +10282,8 @@
gdvp->gdv_view->gv_prevMouseY = y;
gdvp->gdv_view->gv_mode = TCLCAD_POLY_CONTOUR_MODE;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
-
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(v_pt, fx, fy, 1.0);
if (gedp->ged_gvp->gv_grid.ggs_snap)
ged_snap_to_grid(gedp, &v_pt[X], &v_pt[Y]);
@@ -10481,9 +10413,6 @@
char *av[5];
int x, y;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t v_pt, m_pt;
struct bu_vls plist = BU_VLS_INIT_ZERO;
struct bu_vls bindings = BU_VLS_INIT_ZERO;
@@ -10537,12 +10466,8 @@
gdvp->gdv_view->gv_prevMouseY = y;
gdvp->gdv_view->gv_mode = TCLCAD_POLY_ELLIPSE_MODE;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
-
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(v_pt, fx, fy, 1.0);
if (gedp->ged_gvp->gv_grid.ggs_snap)
ged_snap_to_grid(gedp, &v_pt[X], &v_pt[Y]);
@@ -10593,9 +10518,6 @@
int x, y;
int sflag;
fastf_t fx, fy;
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t v_pt, m_pt;
struct bu_vls plist = BU_VLS_INIT_ZERO;
struct bu_vls bindings = BU_VLS_INIT_ZERO;
@@ -10661,12 +10583,8 @@
else
gdvp->gdv_view->gv_mode = TCLCAD_POLY_RECTANGLE_MODE;
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
-
- fx = x * inv_width * 2.0 - 1.0;
- fy = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ fx = screen_to_view_x(gdvp->gdv_dmp, x);
+ fy = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(v_pt, fx, fy, 1.0);
if (gedp->ged_gvp->gv_grid.ggs_snap)
ged_snap_to_grid(gedp, &v_pt[X], &v_pt[Y]);
@@ -11404,9 +11322,6 @@
const char *usage,
int UNUSED(maxargs))
{
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t view;
point_t model;
struct ged_dm_view *gdvp;
@@ -11444,11 +11359,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
MAT4X3PNT(model, gdvp->gdv_view->gv_view2model, view);
@@ -11465,9 +11377,6 @@
const char *usage,
int UNUSED(maxargs))
{
- fastf_t inv_width;
- fastf_t inv_height;
- fastf_t inv_aspect;
point_t view;
struct ged_dm_view *gdvp;
@@ -11504,11 +11413,8 @@
return GED_ERROR;
}
- inv_width = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_width;
- inv_height = 1.0 / (fastf_t)gdvp->gdv_dmp->dm_height;
- inv_aspect = (fastf_t)gdvp->gdv_dmp->dm_height /
(fastf_t)gdvp->gdv_dmp->dm_width;
- x = x * inv_width * 2.0 - 1.0;
- y = (y * inv_height * -2.0 + 1.0) * inv_aspect;
+ x = screen_to_view_x(gdvp->gdv_dmp, x);
+ y = screen_to_view_y(gdvp->gdv_dmp, y);
VSET(view, x, y, 0.0);
bu_vls_printf(gedp->ged_result_str, "%lf %lf %lf", V3ARGS(view));
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits