BRL-CAD
pov.c
Go to the documentation of this file.
1 /* P O V . 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/pov.c
21  *
22  * The pov 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_pov(struct ged *gedp, int argc, const char *argv[])
37 {
38  vect_t center;
39  quat_t quat;
40  vect_t eye_pos;
41 
42  /* intentionally double for scan */
43  double scale;
44  double perspective;
45 
46  static const char *usage = "center quat scale eye_pos perspective";
47 
50  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
51 
52  /* initialize result */
53  bu_vls_trunc(gedp->ged_result_str, 0);
54 
55  /* must be wanting help */
56  if (argc == 1) {
57  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
58  return GED_HELP;
59  }
60 
61  if (argc != 6) {
62  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
63  return GED_ERROR;
64  }
65 
66  /***************** Get the arguments *******************/
67 
68  if (bn_decode_vect(center, argv[1]) != 3) {
69  bu_vls_printf(gedp->ged_result_str, "ged_pov: bad center - %s\n", argv[1]);
70  return TCL_ERROR;
71  }
72 
73  if (bn_decode_quat(quat, argv[2]) != 4) {
74  bu_vls_printf(gedp->ged_result_str, "ged_pov: bad quat - %s\n", argv[2]);
75  return TCL_ERROR;
76  }
77 
78  if (sscanf(argv[3], "%lf", &scale) != 1) {
79  bu_vls_printf(gedp->ged_result_str, "ged_pov: bad scale - %s\n", argv[3]);
80  return TCL_ERROR;
81  }
82 
83  if (bn_decode_vect(eye_pos, argv[4]) != 3) {
84  bu_vls_printf(gedp->ged_result_str, "ged_pov: bad eye position - %s\n", argv[4]);
85  return TCL_ERROR;
86  }
87 
88  if (sscanf(argv[5], "%lf", &perspective) != 1) {
89  bu_vls_printf(gedp->ged_result_str, "ged_pov: bad perspective - %s\n", argv[5]);
90  return TCL_ERROR;
91  }
92 
93  /***************** Use the arguments *******************/
94 
95  VSCALE(center, center, gedp->ged_wdbp->dbip->dbi_local2base);
96  MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, center);
97  quat_quat2mat(gedp->ged_gvp->gv_rotation, quat);
98  gedp->ged_gvp->gv_scale = gedp->ged_wdbp->dbip->dbi_local2base * scale;
99  VSCALE(eye_pos, eye_pos, gedp->ged_wdbp->dbip->dbi_local2base);
100  VMOVE(gedp->ged_gvp->gv_eye_pos, eye_pos);
101  gedp->ged_gvp->gv_perspective = perspective;
102 
103  ged_view_update(gedp->ged_gvp);
104 
105  return GED_OK;
106 }
107 
108 
109 /*
110  * Local Variables:
111  * tab-width: 8
112  * mode: C
113  * indent-tabs-mode: t
114  * c-file-style: "stroustrup"
115  * End:
116  * ex: shiftwidth=4 tabstop=8
117  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
mat_t gv_center
Definition: bview.h:221
int bn_decode_quat(quat_t q, const char *str)
int ged_pov(struct ged *gedp, int argc, const char *argv[])
Definition: pov.c:36
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
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.
fastf_t gv_perspective
perspective angle
Definition: bview.h:214
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
#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
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
vect_t gv_eye_pos
eye position
Definition: bview.h:216
#define GED_HELP
Definition: ged.h:62
void quat_quat2mat(mat_t mat, const quat_t quat)
Convert Quaternion to Matrix.
double dbi_local2base
local2mm
Definition: raytrace.h:807