BRL-CAD
lookat.c
Go to the documentation of this file.
1 /* L O O K A T . 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/lookat.c
21  *
22  * The lookat 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_lookat(struct ged *gedp, int argc, const char *argv[])
37 {
38  point_t look;
39  point_t eye;
40  point_t tmp;
41  point_t new_center;
42  vect_t dir;
43  fastf_t new_az, new_el;
44  double scan[3];
45  static const char *usage = "x y z";
46 
49  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
50 
51  /* initialize result */
52  bu_vls_trunc(gedp->ged_result_str, 0);
53 
54  /* must be wanting help */
55  if (argc == 1) {
56  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
57  return GED_HELP;
58  }
59 
60  if (argc != 2 && argc != 4) {
61  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
62  return GED_ERROR;
63  }
64 
65  if (argc == 2) {
66  if (bn_decode_vect(look, argv[1]) != 3) {
67  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
68  return GED_ERROR;
69  }
70  } else {
71  if (sscanf(argv[1], "%lf", &scan[X]) != 1) {
72  bu_vls_printf(gedp->ged_result_str, "ged_lookat: bad X value - %s\n", argv[1]);
73  return GED_ERROR;
74  }
75 
76  if (sscanf(argv[2], "%lf", &scan[Y]) != 1) {
77  bu_vls_printf(gedp->ged_result_str, "ged_lookat: bad Y value - %s\n", argv[2]);
78  return GED_ERROR;
79  }
80 
81  if (sscanf(argv[3], "%lf", &scan[Z]) != 1) {
82  bu_vls_printf(gedp->ged_result_str, "ged_lookat: bad Z value - %s\n", argv[3]);
83  return GED_ERROR;
84  }
85 
86  /* convert from double to fastf_t */
87  VMOVE(look, scan);
88  }
89 
90  VSCALE(look, look, gedp->ged_wdbp->dbip->dbi_local2base);
91 
92  VSET(tmp, 0.0, 0.0, 1.0);
93  MAT4X3PNT(eye, gedp->ged_gvp->gv_view2model, tmp);
94 
95  VSUB2(dir, eye, look);
96  VUNITIZE(dir);
97  bn_ae_vec(&new_az, &new_el, dir);
98 
99  VSET(gedp->ged_gvp->gv_aet, new_az, new_el, gedp->ged_gvp->gv_aet[Z]);
100  _ged_mat_aet(gedp->ged_gvp);
101 
102  VJOIN1(new_center, eye, -gedp->ged_gvp->gv_scale, dir);
103  MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, new_center);
104 
105  ged_view_update(gedp->ged_gvp);
106 
107  return GED_OK;
108 }
109 
110 
111 /*
112  * Local Variables:
113  * tab-width: 8
114  * mode: C
115  * indent-tabs-mode: t
116  * c-file-style: "stroustrup"
117  * End:
118  * ex: shiftwidth=4 tabstop=8
119  */
void bn_ae_vec(fastf_t *azp, fastf_t *elp, const vect_t v)
Definition: mat.c:374
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
mat_t gv_center
Definition: bview.h:221
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.
int ged_lookat(struct ged *gedp, int argc, const char *argv[])
Definition: lookat.c:36
void ged_view_update(struct bview *gvp)
Definition: vutil.c:33
void _ged_mat_aet(struct bview *gvp)
Definition: vutil.c:82
#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
fastf_t gv_scale
Definition: bview.h:211
int bn_decode_vect(vect_t v, const char *str)
struct bu_vls * ged_result_str
Definition: ged.h:357
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define GED_HELP
Definition: ged.h:62
Definition: color.c:51
vect_t gv_aet
Definition: bview.h:215
double dbi_local2base
local2mm
Definition: raytrace.h:807
double fastf_t
Definition: defines.h:300
Definition: color.c:50