Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/sg/cube

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/sg/cube (Version 11.3.0) and /externals/g4tools/include/tools/sg/cube (Version 11.0.p1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_sg_cube                               4 #ifndef tools_sg_cube
  5 #define tools_sg_cube                               5 #define tools_sg_cube
  6                                                     6 
  7 #include "node"                                     7 #include "node"
  8 #include "render_gstos"                             8 #include "render_gstos"
  9                                                     9 
 10 #include "sf"                                      10 #include "sf"
 11 #include "pick_action"                             11 #include "pick_action"
 12 #include "bbox_action"                             12 #include "bbox_action"
 13                                                    13 
 14 namespace tools {                                  14 namespace tools {
 15 namespace sg {                                     15 namespace sg {
 16                                                    16 
 17 class cube : public node, public render_gstos      17 class cube : public node, public render_gstos {
 18   TOOLS_NODE(cube,tools::sg::cube,node)            18   TOOLS_NODE(cube,tools::sg::cube,node)
 19 public:                                            19 public:
 20   sf<float> width;                                 20   sf<float> width;
 21   sf<float> height;                                21   sf<float> height;
 22   sf<float> depth;                                 22   sf<float> depth;
 23 public:                                            23 public:
 24   virtual const desc_fields& node_desc_fields(     24   virtual const desc_fields& node_desc_fields() const {
 25     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::cub     25     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::cube)
 26     static const desc_fields s_v(parent::node_     26     static const desc_fields s_v(parent::node_desc_fields(),3, //WARNING : take care of count.
 27       TOOLS_ARG_FIELD_DESC(width),                 27       TOOLS_ARG_FIELD_DESC(width),
 28       TOOLS_ARG_FIELD_DESC(height),                28       TOOLS_ARG_FIELD_DESC(height),
 29       TOOLS_ARG_FIELD_DESC(depth)                  29       TOOLS_ARG_FIELD_DESC(depth)
 30     );                                             30     );
 31     return s_v;                                    31     return s_v;
 32   }                                                32   }
 33 private:                                           33 private:
 34   void add_fields(){                               34   void add_fields(){
 35     add_field(&width);                             35     add_field(&width);
 36     add_field(&height);                            36     add_field(&height);
 37     add_field(&depth);                             37     add_field(&depth);
 38   }                                                38   }
 39 protected: //render_gstos                          39 protected: //render_gstos
 40   virtual void visit(gstos_add& a_visitor,draw     40   virtual void visit(gstos_add& a_visitor,draw_type a_style) {
 41     visit<gstos_add>(a_visitor,a_style);           41     visit<gstos_add>(a_visitor,a_style);
 42   }                                                42   }
 43 public:                                            43 public:
 44   virtual void render(render_action& a_action)     44   virtual void render(render_action& a_action) {
 45     if(gstos_render(a_action)) return;             45     if(gstos_render(a_action)) return;
 46     // immediate rendering :                       46     // immediate rendering :
 47     const state& state = a_action.state();         47     const state& state = a_action.state();
 48     bool draw_edges = false;                       48     bool draw_edges = false;
 49     if(state.m_draw_type==draw_filled) draw_ed     49     if(state.m_draw_type==draw_filled) draw_edges = state.m_GL_LIGHTING?false:true;
 50                                                    50 
 51     if(draw_edges) {                               51     if(draw_edges) {
 52       a_action.color4f(0,0,0,1); //if lighten,     52       a_action.color4f(0,0,0,1); //if lighten, then rendered grey.
 53       a_action.line_width(1);                      53       a_action.line_width(1);
 54       visit(a_action,draw_lines);                  54       visit(a_action,draw_lines);
 55       a_action.set_polygon_offset(true);           55       a_action.set_polygon_offset(true);
 56       a_action.color4f(state.m_color);             56       a_action.color4f(state.m_color);
 57       a_action.line_width(state.m_line_width);     57       a_action.line_width(state.m_line_width);
 58     }                                              58     }
 59                                                    59 
 60     visit(a_action,state.m_draw_type);             60     visit(a_action,state.m_draw_type);
 61     if(draw_edges) a_action.set_polygon_offset     61     if(draw_edges) a_action.set_polygon_offset(state.m_GL_POLYGON_OFFSET_FILL);
 62   }                                                62   }
 63                                                    63 
 64   virtual void pick(pick_action& a_action) {       64   virtual void pick(pick_action& a_action) {
 65     const state& state = a_action.state();         65     const state& state = a_action.state();
 66     if(a_action.stop_at_first()){                  66     if(a_action.stop_at_first()){
 67       visit(a_action,state.m_draw_type);           67       visit(a_action,state.m_draw_type);
 68       if(a_action.done()) a_action.set_node(th     68       if(a_action.done()) a_action.set_node(this);
 69     } else {                                       69     } else {
 70       a_action.set_done(false);                    70       a_action.set_done(false);
 71       a_action.zs().clear();                       71       a_action.zs().clear();
 72       a_action.ws().clear();                       72       a_action.ws().clear();
 73       visit(a_action,state.m_draw_type);           73       visit(a_action,state.m_draw_type);
 74       if(a_action.done()) {                        74       if(a_action.done()) {
 75         a_action.add_pick(*this,a_action.zs(),     75         a_action.add_pick(*this,a_action.zs(),a_action.ws(),a_action.state());
 76         a_action.set_done(false);                  76         a_action.set_done(false);
 77       }                                            77       }
 78     }                                              78     }
 79   }                                                79   }
 80   virtual void bbox(bbox_action& a_action) {       80   virtual void bbox(bbox_action& a_action) {
 81     const state& state = a_action.state();         81     const state& state = a_action.state();
 82     visit(a_action,state.m_draw_type);             82     visit(a_action,state.m_draw_type);
 83   }                                                83   }
 84 public:                                            84 public:
 85   cube()                                           85   cube()
 86   :parent()                                        86   :parent()
 87   ,render_gstos()                                  87   ,render_gstos()
 88   ,width(1.0f)                                     88   ,width(1.0f)
 89   ,height(1.0f)                                    89   ,height(1.0f)
 90   ,depth(1.0f)                                     90   ,depth(1.0f)
 91   {                                                91   {
 92     add_fields();                                  92     add_fields();
 93   }                                                93   }
 94   virtual ~cube(){}                                94   virtual ~cube(){}
 95 public:                                            95 public:
 96   cube(const cube& a_from)                         96   cube(const cube& a_from)
 97   :parent(a_from)                                  97   :parent(a_from)
 98   ,render_gstos(a_from)                            98   ,render_gstos(a_from)
 99   ,width(a_from.width)                             99   ,width(a_from.width)
100   ,height(a_from.height)                          100   ,height(a_from.height)
101   ,depth(a_from.depth)                            101   ,depth(a_from.depth)
102   {                                               102   {
103     add_fields();                                 103     add_fields();
104   }                                               104   }
105   cube& operator=(const cube& a_from){            105   cube& operator=(const cube& a_from){
106     parent::operator=(a_from);                    106     parent::operator=(a_from);
107     render_gstos::operator=(a_from);              107     render_gstos::operator=(a_from);
108                                                   108 
109     width = a_from.width;                         109     width = a_from.width;
110     height = a_from.height;                       110     height = a_from.height;
111     depth = a_from.depth;                         111     depth = a_from.depth;
112                                                   112 
113     return *this;                                 113     return *this;
114   }                                               114   }
115 protected:                                        115 protected:
116   void _faces(float front[],float back[],   //    116   void _faces(float front[],float back[],   //[12]
117               float right[],float left[],         117               float right[],float left[],
118               float   top[],float bottom[]){      118               float   top[],float bottom[]){
119                                                   119 
120     float wh = width.value()*0.5f;                120     float wh = width.value()*0.5f;
121     float hh = height.value()*0.5f;               121     float hh = height.value()*0.5f;
122     float dh = depth.value()*0.5f;                122     float dh = depth.value()*0.5f;
123                                                   123 
124     front[0] =  wh;front[ 1] = -hh;front[ 2] =    124     front[0] =  wh;front[ 1] = -hh;front[ 2] = dh;
125     front[3] =  wh;front[ 4] =  hh;front[ 5] =    125     front[3] =  wh;front[ 4] =  hh;front[ 5] = dh;
126     front[6] = -wh;front[ 7] =  hh;front[ 8] =    126     front[6] = -wh;front[ 7] =  hh;front[ 8] = dh;
127     front[9] = -wh;front[10] = -hh;front[11] =    127     front[9] = -wh;front[10] = -hh;front[11] = dh;
128                                                   128 
129     back[0] =  wh;back[ 1] = -hh;back[ 2] = -d    129     back[0] =  wh;back[ 1] = -hh;back[ 2] = -dh;
130     back[3] = -wh;back[ 4] = -hh;back[ 5] = -d    130     back[3] = -wh;back[ 4] = -hh;back[ 5] = -dh;
131     back[6] = -wh;back[ 7] =  hh;back[ 8] = -d    131     back[6] = -wh;back[ 7] =  hh;back[ 8] = -dh;
132     back[9] =  wh;back[10] =  hh;back[11] = -d    132     back[9] =  wh;back[10] =  hh;back[11] = -dh;
133                                                   133 
134     right[0] = wh;right[ 1] = -hh;right[ 2] =     134     right[0] = wh;right[ 1] = -hh;right[ 2] =  dh;
135     right[3] = wh;right[ 4] = -hh;right[ 5] =     135     right[3] = wh;right[ 4] = -hh;right[ 5] = -dh;
136     right[6] = wh;right[ 7] =  hh;right[ 8] =     136     right[6] = wh;right[ 7] =  hh;right[ 8] = -dh;
137     right[9] = wh;right[10] =  hh;right[11] =     137     right[9] = wh;right[10] =  hh;right[11] =  dh;
138                                                   138 
139     left[0] = -wh;left[ 1] = -hh;left[ 2] =  d    139     left[0] = -wh;left[ 1] = -hh;left[ 2] =  dh;
140     left[3] = -wh;left[ 4] =  hh;left[ 5] =  d    140     left[3] = -wh;left[ 4] =  hh;left[ 5] =  dh;
141     left[6] = -wh;left[ 7] =  hh;left[ 8] = -d    141     left[6] = -wh;left[ 7] =  hh;left[ 8] = -dh;
142     left[9] = -wh;left[10] = -hh;left[11] = -d    142     left[9] = -wh;left[10] = -hh;left[11] = -dh;
143                                                   143 
144     top[0] =  wh;top[ 1] = hh;top[ 2] =  dh;      144     top[0] =  wh;top[ 1] = hh;top[ 2] =  dh;
145     top[3] =  wh;top[ 4] = hh;top[ 5] = -dh;      145     top[3] =  wh;top[ 4] = hh;top[ 5] = -dh;
146     top[6] = -wh;top[ 7] = hh;top[ 8] = -dh;      146     top[6] = -wh;top[ 7] = hh;top[ 8] = -dh;
147     top[9] = -wh;top[10] = hh;top[11] =  dh;      147     top[9] = -wh;top[10] = hh;top[11] =  dh;
148                                                   148 
149     bottom[0] =  wh;bottom[ 1] = -hh;bottom[ 2    149     bottom[0] =  wh;bottom[ 1] = -hh;bottom[ 2] =  dh;
150     bottom[3] = -wh;bottom[ 4] = -hh;bottom[ 5    150     bottom[3] = -wh;bottom[ 4] = -hh;bottom[ 5] =  dh;
151     bottom[6] = -wh;bottom[ 7] = -hh;bottom[ 8    151     bottom[6] = -wh;bottom[ 7] = -hh;bottom[ 8] = -dh;
152     bottom[9] =  wh;bottom[10] = -hh;bottom[11    152     bottom[9] =  wh;bottom[10] = -hh;bottom[11] = -dh;
153   }                                               153   }
154                                                   154 
155   void _tris(float tris[],float nms[]){ //[108    155   void _tris(float tris[],float nms[]){ //[108]
156     float front[12];                              156     float front[12];
157     float back[12];                               157     float back[12];
158     float right[12];                              158     float right[12];
159     float left[12];                               159     float left[12];
160     float top[12];                                160     float top[12];
161     float bottom[12];                             161     float bottom[12];
162                                                   162 
163     _faces(front,back,right,left,top,bottom);     163     _faces(front,back,right,left,top,bottom);
164                                                   164 
165     /////////////////////                         165     /////////////////////
166     tris[0] = front[0];                           166     tris[0] = front[0];
167     tris[1] = front[1];                           167     tris[1] = front[1];
168     tris[2] = front[2];                           168     tris[2] = front[2];
169                                                   169 
170     tris[3] = front[3];                           170     tris[3] = front[3];
171     tris[4] = front[4];                           171     tris[4] = front[4];
172     tris[5] = front[5];                           172     tris[5] = front[5];
173                                                   173 
174     tris[6] = front[6];                           174     tris[6] = front[6];
175     tris[7] = front[7];                           175     tris[7] = front[7];
176     tris[8] = front[8];                           176     tris[8] = front[8];
177     //                                            177     //
178     tris[9]  = front[6];                          178     tris[9]  = front[6];
179     tris[10] = front[7];                          179     tris[10] = front[7];
180     tris[11] = front[8];                          180     tris[11] = front[8];
181                                                   181 
182     tris[12] = front[9];                          182     tris[12] = front[9];
183     tris[13] = front[10];                         183     tris[13] = front[10];
184     tris[14] = front[11];                         184     tris[14] = front[11];
185                                                   185 
186     tris[15] = front[0];                          186     tris[15] = front[0];
187     tris[16] = front[1];                          187     tris[16] = front[1];
188     tris[17] = front[2];                          188     tris[17] = front[2];
189                                                   189 
190     /////////////////////                         190     /////////////////////
191     tris[18] = back[0];                           191     tris[18] = back[0];
192     tris[19] = back[1];                           192     tris[19] = back[1];
193     tris[20] = back[2];                           193     tris[20] = back[2];
194                                                   194 
195     tris[21] = back[3];                           195     tris[21] = back[3];
196     tris[22] = back[4];                           196     tris[22] = back[4];
197     tris[23] = back[5];                           197     tris[23] = back[5];
198                                                   198 
199     tris[24] = back[6];                           199     tris[24] = back[6];
200     tris[25] = back[7];                           200     tris[25] = back[7];
201     tris[26] = back[8];                           201     tris[26] = back[8];
202     //                                            202     //
203     tris[27] = back[6];                           203     tris[27] = back[6];
204     tris[28] = back[7];                           204     tris[28] = back[7];
205     tris[29] = back[8];                           205     tris[29] = back[8];
206                                                   206 
207     tris[30] = back[9];                           207     tris[30] = back[9];
208     tris[31] = back[10];                          208     tris[31] = back[10];
209     tris[32] = back[11];                          209     tris[32] = back[11];
210                                                   210 
211     tris[33] = back[0];                           211     tris[33] = back[0];
212     tris[34] = back[1];                           212     tris[34] = back[1];
213     tris[35] = back[2];                           213     tris[35] = back[2];
214                                                   214 
215     /////////////////////                         215     /////////////////////
216     tris[36] = right[0];                          216     tris[36] = right[0];
217     tris[37] = right[1];                          217     tris[37] = right[1];
218     tris[38] = right[2];                          218     tris[38] = right[2];
219                                                   219 
220     tris[39] = right[3];                          220     tris[39] = right[3];
221     tris[40] = right[4];                          221     tris[40] = right[4];
222     tris[41] = right[5];                          222     tris[41] = right[5];
223                                                   223 
224     tris[42] = right[6];                          224     tris[42] = right[6];
225     tris[43] = right[7];                          225     tris[43] = right[7];
226     tris[44] = right[8];                          226     tris[44] = right[8];
227     //                                            227     //
228     tris[45] = right[6];                          228     tris[45] = right[6];
229     tris[46] = right[7];                          229     tris[46] = right[7];
230     tris[47] = right[8];                          230     tris[47] = right[8];
231                                                   231 
232     tris[48] = right[9];                          232     tris[48] = right[9];
233     tris[49] = right[10];                         233     tris[49] = right[10];
234     tris[50] = right[11];                         234     tris[50] = right[11];
235                                                   235 
236     tris[51] = right[0];                          236     tris[51] = right[0];
237     tris[52] = right[1];                          237     tris[52] = right[1];
238     tris[53] = right[2];                          238     tris[53] = right[2];
239                                                   239 
240     /////////////////////                         240     /////////////////////
241     tris[54] = left[0];                           241     tris[54] = left[0];
242     tris[55] = left[1];                           242     tris[55] = left[1];
243     tris[56] = left[2];                           243     tris[56] = left[2];
244                                                   244 
245     tris[57] = left[3];                           245     tris[57] = left[3];
246     tris[58] = left[4];                           246     tris[58] = left[4];
247     tris[59] = left[5];                           247     tris[59] = left[5];
248                                                   248 
249     tris[60] = left[6];                           249     tris[60] = left[6];
250     tris[61] = left[7];                           250     tris[61] = left[7];
251     tris[62] = left[8];                           251     tris[62] = left[8];
252     //                                            252     //
253     tris[63] = left[6];                           253     tris[63] = left[6];
254     tris[64] = left[7];                           254     tris[64] = left[7];
255     tris[65] = left[8];                           255     tris[65] = left[8];
256                                                   256 
257     tris[66] = left[9];                           257     tris[66] = left[9];
258     tris[67] = left[10];                          258     tris[67] = left[10];
259     tris[68] = left[11];                          259     tris[68] = left[11];
260                                                   260 
261     tris[69] = left[0];                           261     tris[69] = left[0];
262     tris[70] = left[1];                           262     tris[70] = left[1];
263     tris[71] = left[2];                           263     tris[71] = left[2];
264                                                   264 
265     /////////////////////                         265     /////////////////////
266     tris[72] = top[0];                            266     tris[72] = top[0];
267     tris[73] = top[1];                            267     tris[73] = top[1];
268     tris[74] = top[2];                            268     tris[74] = top[2];
269                                                   269 
270     tris[75] = top[3];                            270     tris[75] = top[3];
271     tris[76] = top[4];                            271     tris[76] = top[4];
272     tris[77] = top[5];                            272     tris[77] = top[5];
273                                                   273 
274     tris[78] = top[6];                            274     tris[78] = top[6];
275     tris[79] = top[7];                            275     tris[79] = top[7];
276     tris[80] = top[8];                            276     tris[80] = top[8];
277     //                                            277     //
278     tris[81] = top[6];                            278     tris[81] = top[6];
279     tris[82] = top[7];                            279     tris[82] = top[7];
280     tris[83] = top[8];                            280     tris[83] = top[8];
281                                                   281 
282     tris[84] = top[9];                            282     tris[84] = top[9];
283     tris[85] = top[10];                           283     tris[85] = top[10];
284     tris[86] = top[11];                           284     tris[86] = top[11];
285                                                   285 
286     tris[87] = top[0];                            286     tris[87] = top[0];
287     tris[88] = top[1];                            287     tris[88] = top[1];
288     tris[89] = top[2];                            288     tris[89] = top[2];
289                                                   289 
290     /////////////////////                         290     /////////////////////
291     tris[90] = bottom[0];                         291     tris[90] = bottom[0];
292     tris[91] = bottom[1];                         292     tris[91] = bottom[1];
293     tris[92] = bottom[2];                         293     tris[92] = bottom[2];
294                                                   294 
295     tris[93] = bottom[3];                         295     tris[93] = bottom[3];
296     tris[94] = bottom[4];                         296     tris[94] = bottom[4];
297     tris[95] = bottom[5];                         297     tris[95] = bottom[5];
298                                                   298 
299     tris[96] = bottom[6];                         299     tris[96] = bottom[6];
300     tris[97] = bottom[7];                         300     tris[97] = bottom[7];
301     tris[98] = bottom[8];                         301     tris[98] = bottom[8];
302     //                                            302     //
303     tris[99] = bottom[6];                         303     tris[99] = bottom[6];
304     tris[100] = bottom[7];                        304     tris[100] = bottom[7];
305     tris[101] = bottom[8];                        305     tris[101] = bottom[8];
306                                                   306 
307     tris[102] = bottom[9];                        307     tris[102] = bottom[9];
308     tris[103] = bottom[10];                       308     tris[103] = bottom[10];
309     tris[104] = bottom[11];                       309     tris[104] = bottom[11];
310                                                   310 
311     tris[105] = bottom[0];                        311     tris[105] = bottom[0];
312     tris[106] = bottom[1];                        312     tris[106] = bottom[1];
313     tris[107] = bottom[2];                        313     tris[107] = bottom[2];
314     /////////////////////                         314     /////////////////////
315                                                   315 
316     ///////////////////// front                   316     ///////////////////// front
317     nms[0] = 0;                                   317     nms[0] = 0;
318     nms[1] = 0;                                   318     nms[1] = 0;
319     nms[2] = 1;                                   319     nms[2] = 1;
320                                                   320 
321     nms[3] = 0;                                   321     nms[3] = 0;
322     nms[4] = 0;                                   322     nms[4] = 0;
323     nms[5] = 1;                                   323     nms[5] = 1;
324                                                   324 
325     nms[6] = 0;                                   325     nms[6] = 0;
326     nms[7] = 0;                                   326     nms[7] = 0;
327     nms[8] = 1;                                   327     nms[8] = 1;
328     //                                            328     //
329     nms[9]  = 0;                                  329     nms[9]  = 0;
330     nms[10] = 0;                                  330     nms[10] = 0;
331     nms[11] = 1;                                  331     nms[11] = 1;
332                                                   332 
333     nms[12] = 0;                                  333     nms[12] = 0;
334     nms[13] = 0;                                  334     nms[13] = 0;
335     nms[14] = 1;                                  335     nms[14] = 1;
336                                                   336 
337     nms[15] = 0;                                  337     nms[15] = 0;
338     nms[16] = 0;                                  338     nms[16] = 0;
339     nms[17] = 1;                                  339     nms[17] = 1;
340                                                   340 
341     ///////////////////// back                    341     ///////////////////// back
342     nms[18] =  0;                                 342     nms[18] =  0;
343     nms[19] =  0;                                 343     nms[19] =  0;
344     nms[20] = -1;                                 344     nms[20] = -1;
345                                                   345 
346     nms[21] =  0;                                 346     nms[21] =  0;
347     nms[22] =  0;                                 347     nms[22] =  0;
348     nms[23] = -1;                                 348     nms[23] = -1;
349                                                   349 
350     nms[24] =  0;                                 350     nms[24] =  0;
351     nms[25] =  0;                                 351     nms[25] =  0;
352     nms[26] = -1;                                 352     nms[26] = -1;
353     //                                            353     //
354     nms[27] =  0;                                 354     nms[27] =  0;
355     nms[28] =  0;                                 355     nms[28] =  0;
356     nms[29] = -1;                                 356     nms[29] = -1;
357                                                   357 
358     nms[30] =  0;                                 358     nms[30] =  0;
359     nms[31] =  0;                                 359     nms[31] =  0;
360     nms[32] = -1;                                 360     nms[32] = -1;
361                                                   361 
362     nms[33] =  0;                                 362     nms[33] =  0;
363     nms[34] =  0;                                 363     nms[34] =  0;
364     nms[35] = -1;                                 364     nms[35] = -1;
365                                                   365 
366     ///////////////////// right                   366     ///////////////////// right
367     nms[36] = 1;                                  367     nms[36] = 1;
368     nms[37] = 0;                                  368     nms[37] = 0;
369     nms[38] = 0;                                  369     nms[38] = 0;
370                                                   370 
371     nms[39] = 1;                                  371     nms[39] = 1;
372     nms[40] = 0;                                  372     nms[40] = 0;
373     nms[41] = 0;                                  373     nms[41] = 0;
374                                                   374 
375     nms[42] = 1;                                  375     nms[42] = 1;
376     nms[43] = 0;                                  376     nms[43] = 0;
377     nms[44] = 0;                                  377     nms[44] = 0;
378     //                                            378     //
379     nms[45] = 1;                                  379     nms[45] = 1;
380     nms[46] = 0;                                  380     nms[46] = 0;
381     nms[47] = 0;                                  381     nms[47] = 0;
382                                                   382 
383     nms[48] = 1;                                  383     nms[48] = 1;
384     nms[49] = 0;                                  384     nms[49] = 0;
385     nms[50] = 0;                                  385     nms[50] = 0;
386                                                   386 
387     nms[51] = 1;                                  387     nms[51] = 1;
388     nms[52] = 0;                                  388     nms[52] = 0;
389     nms[53] = 0;                                  389     nms[53] = 0;
390                                                   390 
391     ///////////////////// left                    391     ///////////////////// left
392     nms[54] = -1;                                 392     nms[54] = -1;
393     nms[55] =  0;                                 393     nms[55] =  0;
394     nms[56] =  0;                                 394     nms[56] =  0;
395                                                   395 
396     nms[57] = -1;                                 396     nms[57] = -1;
397     nms[58] =  0;                                 397     nms[58] =  0;
398     nms[59] =  0;                                 398     nms[59] =  0;
399                                                   399 
400     nms[60] = -1;                                 400     nms[60] = -1;
401     nms[61] =  0;                                 401     nms[61] =  0;
402     nms[62] =  0;                                 402     nms[62] =  0;
403     //                                            403     //
404     nms[63] = -1;                                 404     nms[63] = -1;
405     nms[64] =  0;                                 405     nms[64] =  0;
406     nms[65] =  0;                                 406     nms[65] =  0;
407                                                   407 
408     nms[66] = -1;                                 408     nms[66] = -1;
409     nms[67] =  0;                                 409     nms[67] =  0;
410     nms[68] =  0;                                 410     nms[68] =  0;
411                                                   411 
412     nms[69] = -1;                                 412     nms[69] = -1;
413     nms[70] =  0;                                 413     nms[70] =  0;
414     nms[71] =  0;                                 414     nms[71] =  0;
415                                                   415 
416     ///////////////////// top                     416     ///////////////////// top
417     nms[72] = 0;                                  417     nms[72] = 0;
418     nms[73] = 1;                                  418     nms[73] = 1;
419     nms[74] = 0;                                  419     nms[74] = 0;
420                                                   420 
421     nms[75] = 0;                                  421     nms[75] = 0;
422     nms[76] = 1;                                  422     nms[76] = 1;
423     nms[77] = 0;                                  423     nms[77] = 0;
424                                                   424 
425     nms[78] = 0;                                  425     nms[78] = 0;
426     nms[79] = 1;                                  426     nms[79] = 1;
427     nms[80] = 0;                                  427     nms[80] = 0;
428     //                                            428     //
429     nms[81] = 0;                                  429     nms[81] = 0;
430     nms[82] = 1;                                  430     nms[82] = 1;
431     nms[83] = 0;                                  431     nms[83] = 0;
432                                                   432 
433     nms[84] = 0;                                  433     nms[84] = 0;
434     nms[85] = 1;                                  434     nms[85] = 1;
435     nms[86] = 0;                                  435     nms[86] = 0;
436                                                   436 
437     nms[87] = 0;                                  437     nms[87] = 0;
438     nms[88] = 1;                                  438     nms[88] = 1;
439     nms[89] = 0;                                  439     nms[89] = 0;
440                                                   440 
441     ///////////////////// bottom                  441     ///////////////////// bottom
442     nms[90] =  0;                                 442     nms[90] =  0;
443     nms[91] = -1;                                 443     nms[91] = -1;
444     nms[92] =  0;                                 444     nms[92] =  0;
445                                                   445 
446     nms[93] =  0;                                 446     nms[93] =  0;
447     nms[94] = -1;                                 447     nms[94] = -1;
448     nms[95] =  0;                                 448     nms[95] =  0;
449                                                   449 
450     nms[96] =  0;                                 450     nms[96] =  0;
451     nms[97] = -1;                                 451     nms[97] = -1;
452     nms[98] =  0;                                 452     nms[98] =  0;
453     //                                            453     //
454     nms[99]  =  0;                                454     nms[99]  =  0;
455     nms[100] = -1;                                455     nms[100] = -1;
456     nms[101] =  0;                                456     nms[101] =  0;
457                                                   457 
458     nms[102] =  0;                                458     nms[102] =  0;
459     nms[103] = -1;                                459     nms[103] = -1;
460     nms[104] =  0;                                460     nms[104] =  0;
461                                                   461 
462     nms[105] =  0;                                462     nms[105] =  0;
463     nms[106] = -1;                                463     nms[106] = -1;
464     nms[107] =  0;                                464     nms[107] =  0;
465     /////////////////////                         465     /////////////////////
466   }                                               466   }
467                                                   467 
468   void _lines(float lines[]) { //[144]            468   void _lines(float lines[]) { //[144]
469     float front[12];                              469     float front[12];
470     float back[12];                               470     float back[12];
471     float right[12];                              471     float right[12];
472     float left[12];                               472     float left[12];
473     float top[12];                                473     float top[12];
474     float bottom[12];                             474     float bottom[12];
475                                                   475 
476     _faces(front,back,right,left,top,bottom);     476     _faces(front,back,right,left,top,bottom);
477                                                   477 
478     //4 segs * 2 points * 3 coords * 6 faces.     478     //4 segs * 2 points * 3 coords * 6 faces.
479                                                   479 
480     //4*2*3*6 = 24*6 = 144                        480     //4*2*3*6 = 24*6 = 144
481                                                   481 
482     lines[0] = front[0];                          482     lines[0] = front[0];
483     lines[1] = front[1];                          483     lines[1] = front[1];
484     lines[2] = front[2];                          484     lines[2] = front[2];
485     lines[3] = front[3];                          485     lines[3] = front[3];
486     lines[4] = front[4];                          486     lines[4] = front[4];
487     lines[5] = front[5];                          487     lines[5] = front[5];
488                                                   488 
489     lines[6] = front[3];                          489     lines[6] = front[3];
490     lines[7] = front[4];                          490     lines[7] = front[4];
491     lines[8] = front[5];                          491     lines[8] = front[5];
492     lines[9] = front[6];                          492     lines[9] = front[6];
493     lines[10] = front[7];                         493     lines[10] = front[7];
494     lines[11] = front[8];                         494     lines[11] = front[8];
495                                                   495 
496     lines[12] = front[6];                         496     lines[12] = front[6];
497     lines[13] = front[7];                         497     lines[13] = front[7];
498     lines[14] = front[8];                         498     lines[14] = front[8];
499     lines[15] = front[9];                         499     lines[15] = front[9];
500     lines[16] = front[10];                        500     lines[16] = front[10];
501     lines[17] = front[11];                        501     lines[17] = front[11];
502                                                   502 
503     lines[18] = front[9];                         503     lines[18] = front[9];
504     lines[19] = front[10];                        504     lines[19] = front[10];
505     lines[20] = front[11];                        505     lines[20] = front[11];
506     lines[21] = front[0];                         506     lines[21] = front[0];
507     lines[22] = front[1];                         507     lines[22] = front[1];
508     lines[23] = front[2];                         508     lines[23] = front[2];
509                                                   509 
510     lines[24] = back[0];                          510     lines[24] = back[0];
511     lines[25] = back[1];                          511     lines[25] = back[1];
512     lines[26] = back[2];                          512     lines[26] = back[2];
513     lines[27] = back[3];                          513     lines[27] = back[3];
514     lines[28] = back[4];                          514     lines[28] = back[4];
515     lines[29] = back[5];                          515     lines[29] = back[5];
516                                                   516 
517     lines[30] = back[3];                          517     lines[30] = back[3];
518     lines[31] = back[4];                          518     lines[31] = back[4];
519     lines[32] = back[5];                          519     lines[32] = back[5];
520     lines[33] = back[6];                          520     lines[33] = back[6];
521     lines[34] = back[7];                          521     lines[34] = back[7];
522     lines[35] = back[8];                          522     lines[35] = back[8];
523                                                   523 
524     lines[36] = back[6];                          524     lines[36] = back[6];
525     lines[37] = back[7];                          525     lines[37] = back[7];
526     lines[38] = back[8];                          526     lines[38] = back[8];
527     lines[39] = back[9];                          527     lines[39] = back[9];
528     lines[40] = back[10];                         528     lines[40] = back[10];
529     lines[41] = back[11];                         529     lines[41] = back[11];
530                                                   530 
531     lines[42] = back[9];                          531     lines[42] = back[9];
532     lines[43] = back[10];                         532     lines[43] = back[10];
533     lines[44] = back[11];                         533     lines[44] = back[11];
534     lines[45] = back[0];                          534     lines[45] = back[0];
535     lines[46] = back[1];                          535     lines[46] = back[1];
536     lines[47] = back[2];                          536     lines[47] = back[2];
537                                                   537 
538     lines[48] = left[0];                          538     lines[48] = left[0];
539     lines[49] = left[1];                          539     lines[49] = left[1];
540     lines[50] = left[2];                          540     lines[50] = left[2];
541     lines[51] = left[3];                          541     lines[51] = left[3];
542     lines[52] = left[4];                          542     lines[52] = left[4];
543     lines[53] = left[5];                          543     lines[53] = left[5];
544                                                   544 
545     lines[54] = left[3];                          545     lines[54] = left[3];
546     lines[55] = left[4];                          546     lines[55] = left[4];
547     lines[56] = left[5];                          547     lines[56] = left[5];
548     lines[57] = left[6];                          548     lines[57] = left[6];
549     lines[58] = left[7];                          549     lines[58] = left[7];
550     lines[59] = left[8];                          550     lines[59] = left[8];
551                                                   551 
552     lines[60] = left[6];                          552     lines[60] = left[6];
553     lines[61] = left[7];                          553     lines[61] = left[7];
554     lines[62] = left[8];                          554     lines[62] = left[8];
555     lines[63] = left[9];                          555     lines[63] = left[9];
556     lines[64] = left[10];                         556     lines[64] = left[10];
557     lines[65] = left[11];                         557     lines[65] = left[11];
558                                                   558 
559     lines[66] = left[9];                          559     lines[66] = left[9];
560     lines[67] = left[10];                         560     lines[67] = left[10];
561     lines[68] = left[11];                         561     lines[68] = left[11];
562     lines[69] = left[0];                          562     lines[69] = left[0];
563     lines[70] = left[1];                          563     lines[70] = left[1];
564     lines[71] = left[2];                          564     lines[71] = left[2];
565                                                   565 
566     lines[72] = right[0];                         566     lines[72] = right[0];
567     lines[73] = right[1];                         567     lines[73] = right[1];
568     lines[74] = right[2];                         568     lines[74] = right[2];
569     lines[75] = right[3];                         569     lines[75] = right[3];
570     lines[76] = right[4];                         570     lines[76] = right[4];
571     lines[77] = right[5];                         571     lines[77] = right[5];
572                                                   572 
573     lines[78] = right[3];                         573     lines[78] = right[3];
574     lines[79] = right[4];                         574     lines[79] = right[4];
575     lines[80] = right[5];                         575     lines[80] = right[5];
576     lines[81] = right[6];                         576     lines[81] = right[6];
577     lines[82] = right[7];                         577     lines[82] = right[7];
578     lines[83] = right[8];                         578     lines[83] = right[8];
579                                                   579 
580     lines[84] = right[6];                         580     lines[84] = right[6];
581     lines[85] = right[7];                         581     lines[85] = right[7];
582     lines[86] = right[8];                         582     lines[86] = right[8];
583     lines[87] = right[9];                         583     lines[87] = right[9];
584     lines[88] = right[10];                        584     lines[88] = right[10];
585     lines[89] = right[11];                        585     lines[89] = right[11];
586                                                   586 
587     lines[90] = right[9];                         587     lines[90] = right[9];
588     lines[91] = right[10];                        588     lines[91] = right[10];
589     lines[92] = right[11];                        589     lines[92] = right[11];
590     lines[93] = right[0];                         590     lines[93] = right[0];
591     lines[94] = right[1];                         591     lines[94] = right[1];
592     lines[95] = right[2];                         592     lines[95] = right[2];
593                                                   593 
594     lines[96] = top[0];                           594     lines[96] = top[0];
595     lines[97] = top[1];                           595     lines[97] = top[1];
596     lines[98] = top[2];                           596     lines[98] = top[2];
597     lines[99] = top[3];                           597     lines[99] = top[3];
598     lines[100] = top[4];                          598     lines[100] = top[4];
599     lines[101] = top[5];                          599     lines[101] = top[5];
600                                                   600 
601     lines[102] = top[3];                          601     lines[102] = top[3];
602     lines[103] = top[4];                          602     lines[103] = top[4];
603     lines[104] = top[5];                          603     lines[104] = top[5];
604     lines[105] = top[6];                          604     lines[105] = top[6];
605     lines[106] = top[7];                          605     lines[106] = top[7];
606     lines[107] = top[8];                          606     lines[107] = top[8];
607                                                   607 
608     lines[108] = top[6];                          608     lines[108] = top[6];
609     lines[109] = top[7];                          609     lines[109] = top[7];
610     lines[110] = top[8];                          610     lines[110] = top[8];
611     lines[111] = top[9];                          611     lines[111] = top[9];
612     lines[112] = top[10];                         612     lines[112] = top[10];
613     lines[113] = top[11];                         613     lines[113] = top[11];
614                                                   614 
615     lines[114] = top[9];                          615     lines[114] = top[9];
616     lines[115] = top[10];                         616     lines[115] = top[10];
617     lines[116] = top[11];                         617     lines[116] = top[11];
618     lines[117] = top[0];                          618     lines[117] = top[0];
619     lines[118] = top[1];                          619     lines[118] = top[1];
620     lines[119] = top[2];                          620     lines[119] = top[2];
621                                                   621 
622     lines[120] = bottom[0];                       622     lines[120] = bottom[0];
623     lines[121] = bottom[1];                       623     lines[121] = bottom[1];
624     lines[122] = bottom[2];                       624     lines[122] = bottom[2];
625     lines[123] = bottom[3];                       625     lines[123] = bottom[3];
626     lines[124] = bottom[4];                       626     lines[124] = bottom[4];
627     lines[125] = bottom[5];                       627     lines[125] = bottom[5];
628                                                   628 
629     lines[126] = bottom[3];                       629     lines[126] = bottom[3];
630     lines[127] = bottom[4];                       630     lines[127] = bottom[4];
631     lines[128] = bottom[5];                       631     lines[128] = bottom[5];
632     lines[129] = bottom[6];                       632     lines[129] = bottom[6];
633     lines[130] = bottom[7];                       633     lines[130] = bottom[7];
634     lines[131] = bottom[8];                       634     lines[131] = bottom[8];
635                                                   635 
636     lines[132] = bottom[6];                       636     lines[132] = bottom[6];
637     lines[133] = bottom[7];                       637     lines[133] = bottom[7];
638     lines[134] = bottom[8];                       638     lines[134] = bottom[8];
639     lines[135] = bottom[9];                       639     lines[135] = bottom[9];
640     lines[136] = bottom[10];                      640     lines[136] = bottom[10];
641     lines[137] = bottom[11];                      641     lines[137] = bottom[11];
642                                                   642 
643     lines[138] = bottom[9];                       643     lines[138] = bottom[9];
644     lines[139] = bottom[10];                      644     lines[139] = bottom[10];
645     lines[140] = bottom[11];                      645     lines[140] = bottom[11];
646     lines[141] = bottom[0];                       646     lines[141] = bottom[0];
647     lines[142] = bottom[1];                       647     lines[142] = bottom[1];
648     lines[143] = bottom[2];                       648     lines[143] = bottom[2];
649   }                                               649   }
650                                                   650 
651   void _points(float points[]) { //[24]           651   void _points(float points[]) { //[24]
652     float wh = width.value()*0.5f;                652     float wh = width.value()*0.5f;
653     float hh = height.value()*0.5f;               653     float hh = height.value()*0.5f;
654     float dh = depth.value()*0.5f;                654     float dh = depth.value()*0.5f;
655                                                   655 
656     points[0] =  wh;points[ 1] = -hh;points[ 2    656     points[0] =  wh;points[ 1] = -hh;points[ 2] = dh;
657     points[3] =  wh;points[ 4] =  hh;points[ 5    657     points[3] =  wh;points[ 4] =  hh;points[ 5] = dh;
658     points[6] = -wh;points[ 7] =  hh;points[ 8    658     points[6] = -wh;points[ 7] =  hh;points[ 8] = dh;
659     points[9] = -wh;points[10] = -hh;points[11    659     points[9] = -wh;points[10] = -hh;points[11] = dh;
660                                                   660 
661     points[12+0] =  wh;points[12+ 1] = -hh;poi    661     points[12+0] =  wh;points[12+ 1] = -hh;points[12+ 2] = -dh;
662     points[12+3] = -wh;points[12+ 4] = -hh;poi    662     points[12+3] = -wh;points[12+ 4] = -hh;points[12+ 5] = -dh;
663     points[12+6] = -wh;points[12+ 7] =  hh;poi    663     points[12+6] = -wh;points[12+ 7] =  hh;points[12+ 8] = -dh;
664     points[12+9] =  wh;points[12+10] =  hh;poi    664     points[12+9] =  wh;points[12+10] =  hh;points[12+11] = -dh;
665   }                                               665   }
666                                                   666 
667   template <class T>                              667   template <class T>
668   void visit(T& a_visitor,draw_type a_style){     668   void visit(T& a_visitor,draw_type a_style){
669     if(a_style==draw_points) {                    669     if(a_style==draw_points) {
670       float points[24];                           670       float points[24];
671       _points(points);                            671       _points(points);
672       a_visitor.add_points(24,points);            672       a_visitor.add_points(24,points);
673                                                   673 
674     } else if(a_style==draw_lines) {              674     } else if(a_style==draw_lines) {
675       float lines[144]; //segments                675       float lines[144]; //segments
676       _lines(lines);                              676       _lines(lines);
677       a_visitor.add_lines(144,lines);             677       a_visitor.add_lines(144,lines);
678                                                   678 
679     } else if(a_style==draw_filled) {             679     } else if(a_style==draw_filled) {
680       float tris[108];float nms[108];             680       float tris[108];float nms[108];
681       _tris(tris,nms);                            681       _tris(tris,nms);
682       a_visitor.add_triangles_normal(108,tris,    682       a_visitor.add_triangles_normal(108,tris,nms);
683     }                                             683     }
684   }                                               684   }
685 };                                                685 };
686                                                   686 
687 }}                                                687 }}
688                                                   688 
689 #endif                                            689 #endif