BRL-CAD
translate_extrude.c
Go to the documentation of this file.
1 /* T R A N S L A T E _ E X T R U D 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/translate_extrude.c
21  *
22  * The translate_extrude command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 #include "rtgeom.h"
32 #include "raytrace.h"
33 
34 #include "./ged_private.h"
35 
36 
37 int
38 _ged_translate_extrude(struct ged *gedp, struct rt_extrude_internal *extrude, const char *attribute, vect_t tvec, int rflag)
39 {
40  vect_t hvec;
41 
42  RT_EXTRUDE_CK_MAGIC(extrude);
43 
44  VSCALE(tvec, tvec, gedp->ged_wdbp->dbip->dbi_local2base);
45 
46  switch (attribute[0]) {
47  case 'h':
48  case 'H':
49  switch (attribute[1]) {
50  case '\0':
51  if (rflag) {
52  VADD2(hvec, extrude->h, tvec);
53  } else {
54  VSUB2(hvec, tvec, extrude->V);
55  }
56 
57  /* check for zero H vector */
58  if (MAGNITUDE(hvec) <= SQRT_SMALL_FASTF) {
59  bu_vls_printf(gedp->ged_result_str, "Zero H vector not allowed.");
60  return GED_ERROR;
61  }
62 
63  VMOVE(extrude->h, hvec);
64 
65  break;
66  case 'r':
67  case 'R':
68  if (attribute[2] != '\0') {
69  bu_vls_printf(gedp->ged_result_str, "bad extrude attribute - %s", attribute);
70  return GED_ERROR;
71  }
72 
73  if (rflag) {
74  VADD2(hvec, extrude->h, tvec);
75  } else {
76  VSUB2(hvec, tvec, extrude->V);
77  }
78 
79  /* check for zero H vector */
80  if (MAGNITUDE(hvec) <= SQRT_SMALL_FASTF) {
81  bu_vls_printf(gedp->ged_result_str, "Zero H vector not allowed.");
82  return GED_ERROR;
83  }
84 
85  VMOVE(extrude->h, hvec);
86 
87  /* Cross h with the existing u_vec to insure that the new v_vec is perpendicular to h */
88  VCROSS(extrude->v_vec, extrude->h, extrude->u_vec);
89 
90  /* Cross v_vec with h to insure that the new u_vec is perpendicular to h as well as v_vec */
91  VCROSS(extrude->u_vec, extrude->v_vec, extrude->h);
92 
93  VUNITIZE(extrude->v_vec);
94  VUNITIZE(extrude->u_vec);
95 
96  break;
97  default:
98  bu_vls_printf(gedp->ged_result_str, "bad extrude attribute - %s", attribute);
99  return GED_ERROR;
100  }
101 
102  break;
103  default:
104  bu_vls_printf(gedp->ged_result_str, "bad extrude attribute - %s", attribute);
105  return GED_ERROR;
106  }
107 
108  return GED_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  */
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
struct db_i * dbip
Definition: raytrace.h:1266
struct rt_wdb * ged_wdbp
Definition: ged.h:340
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
#define SQRT_SMALL_FASTF
Definition: defines.h:346
int _ged_translate_extrude(struct ged *gedp, struct rt_extrude_internal *extrude, const char *attribute, vect_t tvec, int rflag)
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
double dbi_local2base
local2mm
Definition: raytrace.h:807