BRL-CAD
eye.c
Go to the documentation of this file.
1 /* E Y E . 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 /** @file libged/eye.c
21  *
22  * The eye command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <string.h>
31 
32 #include "./ged_private.h"
33 
34 
35 int
36 ged_eye(struct ged *gedp, int argc, const char *argv[])
37 {
38  point_t eye_model;
39  double scan[3];
40  vect_t xlate;
41  vect_t new_cent;
42  static const char *usage = "x y z";
43 
46  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
47 
48  /* initialize result */
49  bu_vls_trunc(gedp->ged_result_str, 0);
50 
51  /* get eye */
52  if (argc == 1) {
53  point_t eye;
54 
55  /* calculate eye point */
56  VSET(xlate, 0.0, 0.0, 1.0);
57  MAT4X3PNT(eye, gedp->ged_gvp->gv_view2model, xlate);
58  VSCALE(eye, eye, gedp->ged_wdbp->dbip->dbi_base2local);
59 
60  bn_encode_vect(gedp->ged_result_str, eye);
61  return GED_OK;
62  }
63 
64  if (argc != 2 && argc != 4) {
65  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
66  return GED_ERROR;
67  }
68 
69  if (argc == 2) {
70  if (bn_decode_vect(eye_model, argv[1]) != 3) {
71  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
72  return GED_ERROR;
73  }
74  } else {
75  if (sscanf(argv[1], "%lf", &scan[X]) < 1) {
76  bu_vls_printf(gedp->ged_result_str, "ged_eye: bad X value %s\n", argv[1]);
77  return GED_ERROR;
78  }
79 
80  if (sscanf(argv[2], "%lf", &scan[Y]) < 1) {
81  bu_vls_printf(gedp->ged_result_str, "ged_eye: bad Y value %s\n", argv[2]);
82  return GED_ERROR;
83  }
84 
85  if (sscanf(argv[3], "%lf", &scan[Z]) < 1) {
86  bu_vls_printf(gedp->ged_result_str, "ged_eye: bad Z value %s\n", argv[3]);
87  return GED_ERROR;
88  }
89 
90  /* convert from double to fastf_t */
91  VMOVE(eye_model, scan);
92  }
93 
94  VSCALE(eye_model, eye_model, gedp->ged_wdbp->dbip->dbi_local2base);
95 
96  /* First step: put eye at view center (view 0, 0, 0) */
97  MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, eye_model);
98  ged_view_update(gedp->ged_gvp);
99 
100  /* Second step: put eye at view 0, 0, 1.
101  * For eye to be at 0, 0, 1, the old 0, 0, -1 needs to become 0, 0, 0.
102  */
103  VSET(xlate, 0.0, 0.0, -1.0); /* correction factor */
104  MAT4X3PNT(new_cent, gedp->ged_gvp->gv_view2model, xlate);
105  MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, new_cent);
106  ged_view_update(gedp->ged_gvp);
107 
108  return TCL_OK;
109 }
110 
111 
112 /*
113  * Local Variables:
114  * tab-width: 8
115  * mode: C
116  * indent-tabs-mode: t
117  * c-file-style: "stroustrup"
118  * End:
119  * ex: shiftwidth=4 tabstop=8
120  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
mat_t gv_center
Definition: bview.h:221
void bn_encode_vect(struct bu_vls *vp, const vect_t v)
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
#define VSET(a, b, c, d)
Definition: color.c:53
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
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
void ged_view_update(struct bview *gvp)
Definition: vutil.c:33
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
mat_t gv_view2model
Definition: bview.h:224
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
int ged_eye(struct ged *gedp, int argc, const char *argv[])
Definition: eye.c:36
int bn_decode_vect(vect_t v, const char *str)
struct bu_vls * ged_result_str
Definition: ged.h:357
double dbi_base2local
unit conversion factors
Definition: raytrace.h:808
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
Definition: color.c:51
double dbi_local2base
local2mm
Definition: raytrace.h:807
Definition: color.c:50