BRL-CAD
viewdir.c
Go to the documentation of this file.
1 /* V I E W D I R . 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/viewdir.c
21  *
22  * The viewdir 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_viewdir(struct ged *gedp, int argc, const char *argv[])
37 {
38  vect_t view;
39  vect_t dir;
40  mat_t invRot;
41  int iflag;
42  static const char *usage = "[-i]";
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  if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'i' && argv[1][2] == '\0') {
52  iflag = 1;
53  --argc;
54  ++argv;
55  } else
56  iflag = 0;
57 
58  if (argc != 1) {
59  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
60  return GED_ERROR;
61  }
62 
63  if (iflag) {
64  VSET(view, 0.0, 0.0, -1.0);
65  } else {
66  VSET(view, 0.0, 0.0, 1.0);
67  }
68 
69  bn_mat_inv(invRot, gedp->ged_gvp->gv_rotation);
70  MAT4X3PNT(dir, invRot, view);
71  bn_encode_vect(gedp->ged_result_str, dir);
72 
73  return GED_OK;
74 }
75 
76 
77 /*
78  * Local Variables:
79  * tab-width: 8
80  * mode: C
81  * indent-tabs-mode: t
82  * c-file-style: "stroustrup"
83  * End:
84  * ex: shiftwidth=4 tabstop=8
85  */
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
#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
Header file for the BRL-CAD common definitions.
int ged_viewdir(struct ged *gedp, int argc, const char *argv[])
Definition: viewdir.c:36
#define GED_ERROR
Definition: ged.h:61
struct bview * ged_gvp
Definition: ged.h:361
#define GED_CHECK_VIEW(_gedp, _flags)
Definition: ged.h:140
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
void bn_mat_inv(mat_t output, const mat_t input)
struct bu_vls * ged_result_str
Definition: ged.h:357
mat_t gv_rotation
Definition: bview.h:220
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694