BRL-CAD
model2view.c
Go to the documentation of this file.
1 /* M O D E L 2 V I E W . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 
23 #include <stdlib.h>
24 #include <ctype.h>
25 #include <string.h>
26 
27 #include "./ged_private.h"
28 
29 
30 /**
31  * Given a point in model space coordinates (in mm) convert it to view
32  * (screen) coordinates which must be scaled to correspond to actual
33  * screen coordinates. If no input coordinates are supplied, the
34  * model2view matrix is displayed.
35  */
36 int
37 ged_model2view(struct ged *gedp, int argc, const char *argv[])
38 {
39  point_t view_pt;
40  double model_pt[3]; /* intentionally double for scan */
41  static const char *usage = "[x y z]";
42 
45  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
46 
47  /* initialize result */
48  bu_vls_trunc(gedp->ged_result_str, 0);
49 
50  /* get the model2view matrix */
51  if (argc == 1) {
53  return GED_OK;
54  }
55 
56  if (argc != 4
57  || sscanf(argv[1], "%lf", &model_pt[X]) != 1
58  || sscanf(argv[2], "%lf", &model_pt[Y]) != 1
59  || sscanf(argv[3], "%lf", &model_pt[Z]) != 1)
60  {
61  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
62  return GED_ERROR;
63  }
64 
65  MAT4X3PNT(view_pt, gedp->ged_gvp->gv_model2view, model_pt);
66  bn_encode_vect(gedp->ged_result_str, view_pt);
67 
68  return GED_OK;
69 }
70 
71 
72 /*
73  * Local Variables:
74  * tab-width: 8
75  * mode: C
76  * indent-tabs-mode: t
77  * c-file-style: "stroustrup"
78  * End:
79  * ex: shiftwidth=4 tabstop=8
80  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
void bn_encode_vect(struct bu_vls *vp, const vect_t v)
Definition: ged.h:338
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
Definition: color.c:49
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
struct bu_vls * ged_result_str
Definition: ged.h:357
mat_t gv_model2view
Definition: bview.h:222
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
int ged_model2view(struct ged *gedp, int argc, const char *argv[])
Definition: model2view.c:37
Definition: color.c:51
Definition: color.c:50
void bn_encode_mat(struct bu_vls *vp, const mat_t m)
Definition: tcl.c:108