g4tools  5.4.0
primitive_visitor
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_primitive_visitor
5 #define tools_sg_primitive_visitor
6 
7 #include "../glprims"
8 
9 #include "../vdata"
10 
11 // for texture :
12 #include "../lina/vec2f"
13 #include "../lina/vec3f"
14 #include "../img"
15 #include "../lina/geom2"
16 
17 namespace tools {
18 namespace sg {
19 
21 protected:
22  virtual bool project(float& a_x,float& a_y,float& a_z,float& a_w) = 0;
23 
24  virtual bool add_point(float,float,float,float) = 0; //xyzw
25  virtual bool add_point(float,float,float,float,
26  float,float,float,float) = 0; //xyzw & rgbas
27 
28  virtual bool add_line(float,float,float,float,
29  float,float,float,float) = 0; // 2 xyzw
30  virtual bool add_line(float,float,float,float, float,float,float,float,
31  float,float,float,float, float,float,float,float) = 0; // 2 (xyzw & rgba)
32 
33  virtual bool add_triangle(float,float,float,float,
34  float,float,float,float,
35  float,float,float,float) = 0; // 3 xyzw
36  virtual bool add_triangle(float,float,float,float, float,float,float,float,
37  float,float,float,float, float,float,float,float,
38  float,float,float,float, float,float,float,float) = 0; // 3 (xywz & rgba)
39 
40  virtual bool project_normal(float& a_x,float& a_y,float& a_z) = 0;
41  virtual bool add_point_normal(float,float,float,float,
42  float,float,float) = 0;
43  virtual bool add_point_normal(float,float,float,float,
44  float,float,float,
45  float,float,float,float) = 0;
46  virtual bool add_line_normal(float,float,float,float, float,float,float,
47  float,float,float,float, float,float,float) = 0;
48  virtual bool add_line_normal(float,float,float,float, float,float,float, float,float,float,float,
49  float,float,float,float, float,float,float, float,float,float,float) = 0;
50  virtual bool add_triangle_normal(float,float,float,float, float,float,float,
51  float,float,float,float, float,float,float,
52  float,float,float,float, float,float,float) = 0;
53  virtual bool add_triangle_normal(float,float,float,float, float,float,float, float,float,float,float,
54  float,float,float,float, float,float,float, float,float,float,float,
55  float,float,float,float, float,float,float, float,float,float,float) = 0;
56 public:
58  virtual ~primitive_visitor(){}
59 public:
62 public:
63  void add_one_point(float a_x,float a_y,float a_z) {
64  float w;
65  project(a_x,a_y,a_z,w);
66  add_point(a_x,a_y,a_z,w);
67  }
68  void add_one_point(float a_x,float a_y,float a_z,float a_r,float a_g,float a_b,float a_a) {
69  float w;
70  project(a_x,a_y,a_z,w);
71  add_point(a_x,a_y,a_z,w,a_r,a_g,a_b,a_a);
72  }
73 
74  bool add_triangle_fan(size_t a_floatn,const float* a_xyzs,bool a_stop = false){
75  size_t num = a_floatn/3;
76  if(num<3) return false;
77 
79 
80  float p1x,p1y,p1z,w1=1;
81  float p2x,p2y,p2z,w2=1;
82  float p3x,p3y,p3z,w3=1;
83 
84  const float* pos1 = a_xyzs+3*0;
85  p1x = *(pos1+0);
86  p1y = *(pos1+1);
87  p1z = *(pos1+2);
88  project(p1x,p1y,p1z,w1);
89 
90  const float* pos2 = a_xyzs+3*1;
91  p2x = *(pos2+0);
92  p2y = *(pos2+1);
93  p2z = *(pos2+2);
94  project(p2x,p2y,p2z,w2);
95 
96  for(size_t index=2;index<num;index++) {
97  const float* pos = a_xyzs+3*index;
98  p3x = *(pos+0);
99  p3y = *(pos+1);
100  p3z = *(pos+2);
101  project(p3x,p3y,p3z,w3);
102 
103  if(!add_triangle(p1x,p1y,p1z,w1,
104  p2x,p2y,p2z,w2,
105  p3x,p3y,p3z,w3)) {
106  if(a_stop) return false;
107  }
108 
109  p2x = p3x;
110  p2y = p3y;
111  p2z = p3z;
112  w2 = w3;
113  }
114  return true;
115  }
116 
117  bool add_triangle_fan_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false){
118  size_t num = a_floatn/3;
119  if(num<3) return false;
120 
122 
123  float p1x,p1y,p1z,w1=1;
124  float p2x,p2y,p2z,w2=1;
125  float p3x,p3y,p3z,w3=1;
126 
127  const float* pos1 = a_xyzs+3*0;
128  p1x = *(pos1+0);
129  p1y = *(pos1+1);
130  p1z = *(pos1+2);
131  project(p1x,p1y,p1z,w1);
132 
133  const float* pos2 = a_xyzs+3*1;
134  p2x = *(pos2+0);
135  p2y = *(pos2+1);
136  p2z = *(pos2+2);
137  project(p2x,p2y,p2z,w2);
138 
139  float n1x,n1y,n1z;
140  float n2x,n2y,n2z;
141  float n3x,n3y,n3z;
142 
143  const float* nos1 = a_nms+3*0;
144  n1x = *(nos1+0);
145  n1y = *(nos1+1);
146  n1z = *(nos1+2);
147  project_normal(n1x,n1y,n1z);
148 
149  const float* nos2 = a_nms+3*1;
150  n2x = *(nos2+0);
151  n2y = *(nos2+1);
152  n2z = *(nos2+2);
153  project_normal(n2x,n2y,n2z);
154 
155  for(size_t index=2;index<num;index++) {
156  const float* pos = a_xyzs+3*index;
157  p3x = *(pos+0);
158  p3y = *(pos+1);
159  p3z = *(pos+2);
160  project(p3x,p3y,p3z,w3);
161 
162  const float* nos = a_nms+3*index;
163  n3x = *(nos+0);
164  n3y = *(nos+1);
165  n3z = *(nos+2);
166  project_normal(n1x,n1y,n1z);
167 
168  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z,
169  p2x,p2y,p2z,w2, n2x,n2y,n2z,
170  p3x,p3y,p3z,w3, n3x,n3y,n3z)) {
171  if(a_stop) return false;
172  }
173 
174  p2x = p3x;
175  p2y = p3y;
176  p2z = p3z;
177  w2 = w3;
178 
179  n2x = n3x;
180  n2y = n3y;
181  n2z = n3z;
182  }
183  return true;
184  }
185 
186  bool add_triangle_fan_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false){
187  size_t num = a_floatn/3;
188  if(num<3) return false;
189 
191 
192  float p1x,p1y,p1z,w1=1;
193  float p2x,p2y,p2z,w2=1;
194  float p3x,p3y,p3z,w3=1;
195 
196  float r1,g1,b1,a1;
197  float r2,g2,b2,a2;
198  float r3,g3,b3,a3;
199 
200  const float* pos1 = a_xyzs+3*0;
201  p1x = *(pos1+0);
202  p1y = *(pos1+1);
203  p1z = *(pos1+2);
204  project(p1x,p1y,p1z,w1);
205 
206  const float* pos2 = a_xyzs+3*1;
207  p2x = *(pos2+0);
208  p2y = *(pos2+1);
209  p2z = *(pos2+2);
210  project(p2x,p2y,p2z,w2);
211 
212  float n1x,n1y,n1z;
213  float n2x,n2y,n2z;
214  float n3x,n3y,n3z;
215 
216  const float* nos1 = a_nms+3*0;
217  n1x = *(nos1+0);
218  n1y = *(nos1+1);
219  n1z = *(nos1+2);
220  project_normal(n1x,n1y,n1z);
221 
222  const float* nos2 = a_nms+3*1;
223  n2x = *(nos2+0);
224  n2y = *(nos2+1);
225  n2z = *(nos2+2);
226  project_normal(n2x,n2y,n2z);
227 
228  const float* ros1 = a_rgbas+4*0;
229  r1 = *ros1;ros1++;
230  g1 = *ros1;ros1++;
231  b1 = *ros1;ros1++;
232  a1 = *ros1;ros1++;
233 
234  const float* ros2 = a_rgbas+4*1;
235  r2 = *ros2;ros2++;
236  g2 = *ros2;ros2++;
237  b2 = *ros2;ros2++;
238  a2 = *ros2;ros2++;
239 
240  for(size_t index=2;index<num;index++) {
241  const float* pos = a_xyzs+3*index;
242  p3x = *(pos+0);
243  p3y = *(pos+1);
244  p3z = *(pos+2);
245  project(p3x,p3y,p3z,w3);
246 
247  const float* nos = a_nms+3*index;
248  n3x = *(nos+0);
249  n3y = *(nos+1);
250  n3z = *(nos+2);
251  project_normal(n1x,n1y,n1z);
252 
253  const float* ros = a_rgbas+4*index;
254  r3 = *ros;ros++;
255  g3 = *ros;ros++;
256  b3 = *ros;ros++;
257  a3 = *ros;ros++;
258 
259  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,b1,g1,a1,
260  p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,b2,g2,a2,
261  p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,b3,g3,a3)) {
262  if(a_stop) return false;
263  }
264 
265  p2x = p3x;
266  p2y = p3y;
267  p2z = p3z;
268  w2 = w3;
269 
270  n2x = n3x;
271  n2y = n3y;
272  n2z = n3z;
273 
274  r2 = r3;
275  g2 = g3;
276  b2 = b3;
277  a2 = a3;
278  }
279  return true;
280  }
281 
282  bool add_triangle_strip(size_t a_floatn,const float* a_xyzs,bool a_stop = false){
283  size_t num = a_floatn/3;
284  if(num<3) return false;
285 
287 
288  float p1x,p1y,p1z,w1=1;
289  float p2x,p2y,p2z,w2=1;
290  float p3x,p3y,p3z,w3=1;
291 
292  const float* pos1 = a_xyzs+3*0;
293  p1x = *(pos1+0);
294  p1y = *(pos1+1);
295  p1z = *(pos1+2);
296  project(p1x,p1y,p1z,w1);
297 
298  const float* pos2 = a_xyzs+3*1;
299  p2x = *(pos2+0);
300  p2y = *(pos2+1);
301  p2z = *(pos2+2);
302  project(p2x,p2y,p2z,w2);
303 
304  bool flip = false;
305  for(size_t index=2;index<num;index++) {
306  const float* pos = a_xyzs+3*index;
307  p3x = *(pos+0);
308  p3y = *(pos+1);
309  p3z = *(pos+2);
310  project(p3x,p3y,p3z,w3);
311 
312  if(flip){
313  if(!add_triangle(p1x,p1y,p1z,w1,
314  p3x,p3y,p3z,w3,
315  p2x,p2y,p2z,w2)) {
316  if(a_stop) return false;
317  }
318  } else {
319  if(!add_triangle(p1x,p1y,p1z,w1,
320  p2x,p2y,p2z,w2,
321  p3x,p3y,p3z,w3)) {
322  if(a_stop) return false;
323  }
324  }
325 
326  p1x = p2x;
327  p1y = p2y;
328  p1z = p2z;
329  w1 = w2;
330 
331  p2x = p3x;
332  p2y = p3y;
333  p2z = p3z;
334  w2 = w3;
335 
336  flip = flip?false:true;
337  }
338  return true;
339  }
340 
341  bool add_triangles(size_t a_floatn,const float* a_xyzs,bool a_stop = false){
342  size_t num = a_floatn/3;
343  if(num<3) return false;
344 
345  m_mode = gl::triangles();
346 
347  float p1x,p1y,p1z,w1=1;
348  float p2x,p2y,p2z,w2=1;
349  float p3x,p3y,p3z,w3=1;
350 
351  for(size_t index=0;index<num;index+=3) {
352 
353  const float* pos = a_xyzs+3*index;
354 
355  p1x = *pos;pos++;
356  p1y = *pos;pos++;
357  p1z = *pos;pos++;
358  project(p1x,p1y,p1z,w1);
359 
360  p2x = *pos;pos++;
361  p2y = *pos;pos++;
362  p2z = *pos;pos++;
363  project(p2x,p2y,p2z,w2);
364 
365  p3x = *pos;pos++;
366  p3y = *pos;pos++;
367  p3z = *pos;pos++;
368  project(p3x,p3y,p3z,w3);
369 
370  if(!add_triangle(p1x,p1y,p1z,w1,
371  p2x,p2y,p2z,w2,
372  p3x,p3y,p3z,w3)) {
373  if(a_stop) return false;
374  }
375  }
376  return true;
377  }
378 
379  bool add_triangle_strip_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false){
380  size_t num = a_floatn/3;
381  if(num<3) return false;
382 
384 
385  float p1x,p1y,p1z,w1=1;
386  float p2x,p2y,p2z,w2=1;
387  float p3x,p3y,p3z,w3=1;
388 
389  const float* pos1 = a_xyzs+3*0;
390  p1x = *(pos1+0);
391  p1y = *(pos1+1);
392  p1z = *(pos1+2);
393  project(p1x,p1y,p1z,w1);
394 
395  const float* pos2 = a_xyzs+3*1;
396  p2x = *(pos2+0);
397  p2y = *(pos2+1);
398  p2z = *(pos2+2);
399  project(p2x,p2y,p2z,w2);
400 
401  float n1x,n1y,n1z;
402  float n2x,n2y,n2z;
403  float n3x,n3y,n3z;
404 
405  const float* nos1 = a_nms+3*0;
406  n1x = *(nos1+0);
407  n1y = *(nos1+1);
408  n1z = *(nos1+2);
409  project_normal(n1x,n1y,n1z);
410 
411  const float* nos2 = a_nms+3*1;
412  n2x = *(nos2+0);
413  n2y = *(nos2+1);
414  n2z = *(nos2+2);
415  project_normal(n2x,n2y,n2z);
416 
417  bool flip = false;
418  for(size_t index=2;index<num;index++) {
419  const float* pos = a_xyzs+3*index;
420  p3x = *(pos+0);
421  p3y = *(pos+1);
422  p3z = *(pos+2);
423  project(p3x,p3y,p3z,w3);
424 
425  const float* nos = a_nms+3*index;
426  n3x = *(nos+0);
427  n3y = *(nos+1);
428  n3z = *(nos+2);
429  project_normal(n1x,n1y,n1z);
430 
431  if(flip){
432  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z,
433  p3x,p3y,p3z,w3, n3x,n3y,n3z,
434  p2x,p2y,p2z,w2, n2x,n2y,n2z)) {
435  if(a_stop) return false;
436  }
437  } else {
438  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z,
439  p2x,p2y,p2z,w2, n2x,n2y,n2z,
440  p3x,p3y,p3z,w3, n3x,n3y,n3z)) {
441  if(a_stop) return false;
442  }
443  }
444 
445  p1x = p2x;
446  p1y = p2y;
447  p1z = p2z;
448  w1 = w2;
449 
450  p2x = p3x;
451  p2y = p3y;
452  p2z = p3z;
453  w2 = w3;
454 
455  n1x = n2x;
456  n1y = n2y;
457  n1z = n2z;
458 
459  n2x = n3x;
460  n2y = n3y;
461  n2z = n3z;
462 
463  flip = flip?false:true;
464  }
465  return true;
466  }
467 
468  bool add_triangle_strip_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false){
469  size_t num = a_floatn/3;
470  if(num<3) return false;
471 
473 
474  float p1x,p1y,p1z,w1=1;
475  float p2x,p2y,p2z,w2=1;
476  float p3x,p3y,p3z,w3=1;
477 
478  float r1,g1,b1,a1;
479  float r2,g2,b2,a2;
480  float r3,g3,b3,a3;
481 
482  const float* pos1 = a_xyzs+3*0;
483  p1x = *(pos1+0);
484  p1y = *(pos1+1);
485  p1z = *(pos1+2);
486  project(p1x,p1y,p1z,w1);
487 
488  const float* pos2 = a_xyzs+3*1;
489  p2x = *(pos2+0);
490  p2y = *(pos2+1);
491  p2z = *(pos2+2);
492  project(p2x,p2y,p2z,w2);
493 
494  float n1x,n1y,n1z;
495  float n2x,n2y,n2z;
496  float n3x,n3y,n3z;
497 
498  const float* nos1 = a_nms+3*0;
499  n1x = *(nos1+0);
500  n1y = *(nos1+1);
501  n1z = *(nos1+2);
502  project_normal(n1x,n1y,n1z);
503 
504  const float* nos2 = a_nms+3*1;
505  n2x = *(nos2+0);
506  n2y = *(nos2+1);
507  n2z = *(nos2+2);
508  project_normal(n2x,n2y,n2z);
509 
510  const float* ros1 = a_rgbas+4*0;
511  r1 = *ros1;ros1++;
512  g1 = *ros1;ros1++;
513  b1 = *ros1;ros1++;
514  a1 = *ros1;ros1++;
515 
516  const float* ros2 = a_rgbas+4*1;
517  r2 = *ros2;ros2++;
518  g2 = *ros2;ros2++;
519  b2 = *ros2;ros2++;
520  a2 = *ros2;ros2++;
521 
522  bool flip = false;
523  for(size_t index=2;index<num;index++) {
524  const float* pos = a_xyzs+3*index;
525  p3x = *(pos+0);
526  p3y = *(pos+1);
527  p3z = *(pos+2);
528  project(p3x,p3y,p3z,w3);
529 
530  const float* nos = a_nms+3*index;
531  n3x = *(nos+0);
532  n3y = *(nos+1);
533  n3z = *(nos+2);
534  project_normal(n1x,n1y,n1z);
535 
536  const float* ros = a_rgbas+4*index;
537  r3 = *ros;ros++;
538  g3 = *ros;ros++;
539  b3 = *ros;ros++;
540  a3 = *ros;ros++;
541 
542  if(flip){
543  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,g1,b1,a1,
544  p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,g3,b3,a3,
545  p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,g2,b2,a2)) {
546  if(a_stop) return false;
547  }
548  } else {
549  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,g1,b1,a1,
550  p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,g2,b2,a2,
551  p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,g3,b3,a3)) {
552  if(a_stop) return false;
553  }
554  }
555 
556  p1x = p2x;
557  p1y = p2y;
558  p1z = p2z;
559  w1 = w2;
560 
561  p2x = p3x;
562  p2y = p3y;
563  p2z = p3z;
564  w2 = w3;
565 
566  n1x = n2x;
567  n1y = n2y;
568  n1z = n2z;
569 
570  n2x = n3x;
571  n2y = n3y;
572  n2z = n3z;
573 
574  r1 = r2;
575  g1 = g2;
576  b1 = b2;
577  a1 = a2;
578 
579  r2 = r3;
580  g2 = g3;
581  b2 = b3;
582  a2 = a3;
583 
584  flip = flip?false:true;
585  }
586  return true;
587  }
588 
589  bool add_triangles_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false){
590  size_t num = a_floatn/3;
591  if(num<3) return false;
592 
593  m_mode = gl::triangles();
594 
595  float p1x,p1y,p1z,w1=1;
596  float p2x,p2y,p2z,w2=1;
597  float p3x,p3y,p3z,w3=1;
598 
599  float n1x,n1y,n1z;
600  float n2x,n2y,n2z;
601  float n3x,n3y,n3z;
602 
603  for(size_t index=0;index<num;index+=3) {
604 
605  const float* pos = a_xyzs+3*index;
606 
607  p1x = *pos;pos++;
608  p1y = *pos;pos++;
609  p1z = *pos;pos++;
610  project(p1x,p1y,p1z,w1);
611 
612  p2x = *pos;pos++;
613  p2y = *pos;pos++;
614  p2z = *pos;pos++;
615  project(p2x,p2y,p2z,w2);
616 
617  p3x = *pos;pos++;
618  p3y = *pos;pos++;
619  p3z = *pos;pos++;
620  project(p3x,p3y,p3z,w3);
621 
622  const float* nos = a_nms+3*index;
623 
624  n1x = *nos;nos++;
625  n1y = *nos;nos++;
626  n1z = *nos;nos++;
627  project_normal(n1x,n1y,n1z);
628 
629  n2x = *nos;nos++;
630  n2y = *nos;nos++;
631  n2z = *nos;nos++;
632  project_normal(n2x,n2y,n2z);
633 
634  n3x = *nos;nos++;
635  n3y = *nos;nos++;
636  n3z = *nos;nos++;
637  project_normal(n3x,n3y,n3z);
638 
639  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z,
640  p2x,p2y,p2z,w2, n2x,n2y,n2z,
641  p3x,p3y,p3z,w3, n3x,n3y,n3z)) {
642  if(a_stop) return false;
643  }
644  }
645  return true;
646  }
647 
648  bool add_triangles_rgba(size_t a_floatn,const float* a_xyzs,const float* a_rgbas,bool a_stop = false){
649  size_t num = a_floatn/3;
650  if(num<3) return false;
651 
652  m_mode = gl::triangles();
653 
654  float p1x,p1y,p1z,w1=1;
655  float p2x,p2y,p2z,w2=1;
656  float p3x,p3y,p3z,w3=1;
657 
658  float r1,g1,b1,a1;
659  float r2,g2,b2,a2;
660  float r3,g3,b3,a3;
661 
662  for(size_t index=0;index<num;index+=3) {
663 
664  const float* pos = a_xyzs+3*index;
665 
666  p1x = *pos;pos++;
667  p1y = *pos;pos++;
668  p1z = *pos;pos++;
669  project(p1x,p1y,p1z,w1);
670 
671  p2x = *pos;pos++;
672  p2y = *pos;pos++;
673  p2z = *pos;pos++;
674  project(p2x,p2y,p2z,w2);
675 
676  p3x = *pos;pos++;
677  p3y = *pos;pos++;
678  p3z = *pos;pos++;
679  project(p3x,p3y,p3z,w3);
680 
681  const float* ros = a_rgbas+4*index;
682 
683  r1 = *ros;ros++;
684  g1 = *ros;ros++;
685  b1 = *ros;ros++;
686  a1 = *ros;ros++;
687 
688  r2 = *ros;ros++;
689  g2 = *ros;ros++;
690  b2 = *ros;ros++;
691  a2 = *ros;ros++;
692 
693  r3 = *ros;ros++;
694  g3 = *ros;ros++;
695  b3 = *ros;ros++;
696  a3 = *ros;ros++;
697 
698  if(!add_triangle(p1x,p1y,p1z,w1,r1,g1,b1,a1,
699  p2x,p2y,p2z,w2,r2,g2,b2,a2,
700  p3x,p3y,p3z,w3,r3,g3,b3,a3)) {
701  if(a_stop) return false;
702  }
703  }
704  return true;
705  }
706 
707  bool add_triangles_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false){
708  size_t num = a_floatn/3;
709  if(num<3) return false;
710 
711  m_mode = gl::triangles();
712 
713  float p1x,p1y,p1z,w1=1;
714  float p2x,p2y,p2z,w2=1;
715  float p3x,p3y,p3z,w3=1;
716 
717  float n1x,n1y,n1z;
718  float n2x,n2y,n2z;
719  float n3x,n3y,n3z;
720 
721  float r1,g1,b1,a1;
722  float r2,g2,b2,a2;
723  float r3,g3,b3,a3;
724 
725  for(size_t index=0;index<num;index+=3) {
726 
727  const float* pos = a_xyzs+3*index;
728 
729  p1x = *pos;pos++;
730  p1y = *pos;pos++;
731  p1z = *pos;pos++;
732  project(p1x,p1y,p1z,w1);
733 
734  p2x = *pos;pos++;
735  p2y = *pos;pos++;
736  p2z = *pos;pos++;
737  project(p2x,p2y,p2z,w2);
738 
739  p3x = *pos;pos++;
740  p3y = *pos;pos++;
741  p3z = *pos;pos++;
742  project(p3x,p3y,p3z,w3);
743 
744  const float* nos = a_nms+3*index;
745 
746  n1x = *nos;nos++;
747  n1y = *nos;nos++;
748  n1z = *nos;nos++;
749  project_normal(n1x,n1y,n1z);
750 
751  n2x = *nos;nos++;
752  n2y = *nos;nos++;
753  n2z = *nos;nos++;
754  project_normal(n2x,n2y,n2z);
755 
756  n3x = *nos;nos++;
757  n3y = *nos;nos++;
758  n3z = *nos;nos++;
759  project_normal(n3x,n3y,n3z);
760 
761  const float* ros = a_rgbas+4*index;
762 
763  r1 = *ros;ros++;
764  g1 = *ros;ros++;
765  b1 = *ros;ros++;
766  a1 = *ros;ros++;
767 
768  r2 = *ros;ros++;
769  g2 = *ros;ros++;
770  b2 = *ros;ros++;
771  a2 = *ros;ros++;
772 
773  r3 = *ros;ros++;
774  g3 = *ros;ros++;
775  b3 = *ros;ros++;
776  a3 = *ros;ros++;
777 
778  if(!add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,g1,b1,a1,
779  p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,g2,b2,a2,
780  p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,g3,b3,a3)) {
781  if(a_stop) return false;
782  }
783  }
784  return true;
785  }
786 
787  bool add_line_strip(size_t a_floatn,const float* a_xyzs,bool a_stop = false){
788  size_t num = a_floatn/3;
789  if(num<=1) return false;
790  size_t nseg = num-1;
791 
793 
794  float xb,yb,zb,wb,xe,ye,ze,we;
795  float* pos;
796  for(size_t iseg = 0;iseg<nseg;iseg++) {
797  pos = (float*)(a_xyzs+3*iseg);
798  xb = *pos;pos++;
799  yb = *pos;pos++;
800  zb = *pos;pos++;
801  project(xb,yb,zb,wb);
802 
803  xe = *pos;pos++;
804  ye = *pos;pos++;
805  ze = *pos;pos++;
806  project(xe,ye,ze,we);
807 
808  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)) {if(a_stop) return false;}
809  }
810  return true;
811  }
812 
813  bool add_line_strip_rgba(size_t a_floatn,const float* a_xyzs,const float* a_rgbas,bool a_stop = false){
814  size_t num = a_floatn/3;
815  if(num<=1) return false;
816  size_t nseg = num-1;
817 
819 
820  float xb,yb,zb,wb,xe,ye,ze,we;
821  float rb,gb,bb,ab,re,ge,be,ae;
822  float* pos;
823  float* ros;
824  for(size_t iseg = 0;iseg<nseg;iseg++) {
825  pos = (float*)(a_xyzs+3*iseg);
826  xb = *pos;pos++;
827  yb = *pos;pos++;
828  zb = *pos;pos++;
829  project(xb,yb,zb,wb);
830 
831  xe = *pos;pos++;
832  ye = *pos;pos++;
833  ze = *pos;pos++;
834  project(xe,ye,ze,we);
835 
836  ros = (float*)(a_rgbas+4*iseg);
837  rb = *ros;ros++;
838  gb = *ros;ros++;
839  bb = *ros;ros++;
840  ab = *ros;ros++;
841 
842  re = *ros;ros++;
843  ge = *ros;ros++;
844  be = *ros;ros++;
845  ae = *ros;ros++;
846 
847  if(!add_line(xb,yb,zb,wb,rb,gb,bb,ab,
848  xe,ye,ze,we,re,ge,be,ae)) {
849  if(a_stop) return false;
850  }
851  }
852  return true;
853  }
854 
855  bool add_line_strip_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false){
856  size_t num = a_floatn/3;
857  if(num<=1) return false;
858  size_t nseg = num-1;
859 
861 
862  float xb,yb,zb,wb,xe,ye,ze,we;
863  float nxb,nyb,nzb,nxe,nye,nze;
864  float* pos;
865  float* nos;
866  for(size_t iseg = 0;iseg<nseg;iseg++) {
867  pos = (float*)(a_xyzs+3*iseg);
868  xb = *pos;pos++;
869  yb = *pos;pos++;
870  zb = *pos;pos++;
871  project(xb,yb,zb,wb);
872 
873  xe = *pos;pos++;
874  ye = *pos;pos++;
875  ze = *pos;pos++;
876  project(xe,ye,ze,we);
877 
878  nos = (float*)(a_nms+3*iseg);
879  nxb = *nos;nos++;
880  nyb = *nos;nos++;
881  nzb = *nos;nos++;
882  project_normal(nxb,nyb,nzb);
883 
884  nxe = *nos;nos++;
885  nye = *nos;nos++;
886  nze = *nos;nos++;
887  project_normal(nxe,nye,nze);
888 
889  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb,
890  xe,ye,ze,we, nxe,nye,nze)) {if(a_stop) return false;}
891  }
892  return true;
893  }
894 
895  bool add_line_strip_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false){
896  size_t num = a_floatn/3;
897  if(num<=1) return false;
898  size_t nseg = num-1;
899 
901 
902  float xb,yb,zb,wb,xe,ye,ze,we;
903  float nxb,nyb,nzb,nxe,nye,nze;
904  float rb,gb,bb,ab,re,ge,be,ae;
905  float* pos;
906  float* nos;
907  float* ros;
908  for(size_t iseg = 0;iseg<nseg;iseg++) {
909  pos = (float*)(a_xyzs+3*iseg);
910  xb = *pos;pos++;
911  yb = *pos;pos++;
912  zb = *pos;pos++;
913  project(xb,yb,zb,wb);
914 
915  xe = *pos;pos++;
916  ye = *pos;pos++;
917  ze = *pos;pos++;
918  project(xe,ye,ze,we);
919 
920  nos = (float*)(a_nms+3*iseg);
921  nxb = *nos;nos++;
922  nyb = *nos;nos++;
923  nzb = *nos;nos++;
924  project_normal(nxb,nyb,nzb);
925 
926  nxe = *nos;nos++;
927  nye = *nos;nos++;
928  nze = *nos;nos++;
929  project_normal(nxe,nye,nze);
930 
931  ros = (float*)(a_rgbas+4*iseg);
932  rb = *ros;ros++;
933  gb = *ros;ros++;
934  bb = *ros;ros++;
935  ab = *ros;ros++;
936 
937  re = *ros;ros++;
938  ge = *ros;ros++;
939  be = *ros;ros++;
940  ae = *ros;ros++;
941 
942  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
943  xe,ye,ze,we, nxe,nye,nze, re,ge,be,ae)) {
944  if(a_stop) return false;
945  }
946  }
947  return true;
948  }
949 
950  bool add_line_loop(size_t a_floatn,const float* a_xyzs,bool a_stop = false) {
951  size_t num = a_floatn/3;
952  if(num<=1) return false;
953  size_t nseg = num-1;
954 
955  m_mode = gl::line_loop();
956 
957  float xb,yb,zb,wb,xe,ye,ze,we;
958  float* pos;
959  for(size_t iseg = 0;iseg<nseg;iseg++) {
960  pos = (float*)(a_xyzs+3*iseg);
961  xb = *pos;pos++;
962  yb = *pos;pos++;
963  zb = *pos;pos++;
964  project(xb,yb,zb,wb);
965 
966  xe = *pos;pos++;
967  ye = *pos;pos++;
968  ze = *pos;pos++;
969  project(xe,ye,ze,we);
970 
971  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)) {if(a_stop) return false;}
972  }
973 
974  //close the loop :
975  {pos = (float*)(a_xyzs+3*(nseg-1)+3);
976  xb = *pos;pos++;
977  yb = *pos;pos++;
978  zb = *pos;pos++;
979  project(xb,yb,zb,wb);
980 
981  pos = (float*)(a_xyzs); //first point.
982  xe = *pos;pos++;
983  ye = *pos;pos++;
984  ze = *pos;pos++;
985  project(xe,ye,ze,we);
986 
987  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)){if(a_stop) return false;}
988  }
989 
990  return true;
991  }
992 
993  bool add_line_loop_rgba(size_t a_floatn,const float* a_xyzs,const float* a_rgbas,bool a_stop = false) {
994  size_t num = a_floatn/3;
995  if(num<=1) return false;
996  size_t nseg = num-1;
997 
998  m_mode = gl::line_loop();
999 
1000  float xb,yb,zb,wb,xe,ye,ze,we;
1001  float rb,gb,bb,ab,re,ge,be,ae;
1002  float* pos;
1003  float* ros;
1004  for(size_t iseg = 0;iseg<nseg;iseg++) {
1005  pos = (float*)(a_xyzs+3*iseg);
1006  xb = *pos;pos++;
1007  yb = *pos;pos++;
1008  zb = *pos;pos++;
1009  project(xb,yb,zb,wb);
1010 
1011  xe = *pos;pos++;
1012  ye = *pos;pos++;
1013  ze = *pos;pos++;
1014  project(xe,ye,ze,we);
1015 
1016  ros = (float*)(a_rgbas+4*iseg);
1017  rb = *ros;ros++;
1018  gb = *ros;ros++;
1019  bb = *ros;ros++;
1020  ab = *ros;ros++;
1021 
1022  re = *ros;ros++;
1023  ge = *ros;ros++;
1024  be = *ros;ros++;
1025  ae = *ros;ros++;
1026 
1027  if(!add_line(xb,yb,zb,wb,rb,gb,bb,ab,
1028  xe,ye,ze,we,re,ge,be,ae)) {
1029  if(a_stop) return false;
1030  }
1031  }
1032 
1033  //close the loop :
1034  {pos = (float*)(a_xyzs+3*nseg);
1035  xb = *pos;pos++;
1036  yb = *pos;pos++;
1037  zb = *pos;pos++;
1038  project(xb,yb,zb,wb);
1039 
1040  pos = (float*)(a_xyzs); //first point.
1041  xe = *pos;pos++;
1042  ye = *pos;pos++;
1043  ze = *pos;pos++;
1044  project(xe,ye,ze,we);
1045 
1046  ros = (float*)(a_rgbas+4*nseg);
1047  rb = *ros;ros++;
1048  gb = *ros;ros++;
1049  bb = *ros;ros++;
1050  ab = *ros;ros++;
1051 
1052  ros = (float*)(a_rgbas);
1053  re = *ros;ros++;
1054  ge = *ros;ros++;
1055  be = *ros;ros++;
1056  ae = *ros;ros++;
1057 
1058  if(!add_line(xb,yb,zb,wb,rb,gb,bb,ab,
1059  xe,ye,ze,we,re,ge,be,ae)){if(a_stop) return false;}
1060  }
1061 
1062  return true;
1063  }
1064 
1065  bool add_line_loop_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false) {
1066  size_t num = a_floatn/3;
1067  if(num<=1) return false;
1068  size_t nseg = num-1;
1069 
1070  m_mode = gl::line_loop();
1071 
1072  float xb,yb,zb,wb,xe,ye,ze,we;
1073  float nxb,nyb,nzb,nxe,nye,nze;
1074  float* pos;
1075  float* nos;
1076  for(size_t iseg = 0;iseg<nseg;iseg++) {
1077  pos = (float*)(a_xyzs+3*iseg);
1078  xb = *pos;pos++;
1079  yb = *pos;pos++;
1080  zb = *pos;pos++;
1081  project(xb,yb,zb,wb);
1082 
1083  xe = *pos;pos++;
1084  ye = *pos;pos++;
1085  ze = *pos;pos++;
1086  project(xe,ye,ze,we);
1087 
1088  nos = (float*)(a_nms+3*iseg);
1089  nxb = *nos;nos++;
1090  nyb = *nos;nos++;
1091  nzb = *nos;nos++;
1092  project_normal(nxb,nyb,nzb);
1093 
1094  nxe = *nos;nos++;
1095  nye = *nos;nos++;
1096  nze = *nos;nos++;
1097  project_normal(nxe,nye,nze);
1098 
1099  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb,
1100  xe,ye,ze,we, nxe,nye,nze)) {if(a_stop) return false;}
1101  }
1102 
1103  //close the loop :
1104  {pos = (float*)(a_xyzs+3*(nseg-1)+3);
1105  xb = *pos;pos++;
1106  yb = *pos;pos++;
1107  zb = *pos;pos++;
1108  project(xb,yb,zb,wb);
1109 
1110  pos = (float*)(a_xyzs); //first point.
1111  xe = *pos;pos++;
1112  ye = *pos;pos++;
1113  ze = *pos;pos++;
1114  project(xe,ye,ze,we);
1115 
1116  nos = (float*)(a_nms+3*(nseg-1)+3);
1117  nxb = *nos;nos++;
1118  nyb = *nos;nos++;
1119  nzb = *nos;nos++;
1120  project_normal(nxb,nyb,nzb);
1121 
1122  nos = (float*)(a_nms);
1123  nxe = *nos;nos++;
1124  nye = *nos;nos++;
1125  nze = *nos;nos++;
1126  project_normal(nxe,nye,nze);
1127 
1128  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb,
1129  xe,ye,ze,we, nxe,nye,nze)) {if(a_stop) return false;}
1130 
1131  }
1132 
1133  return true;
1134  }
1135 
1136  bool add_line_loop_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false) {
1137  size_t num = a_floatn/3;
1138  if(num<=1) return false;
1139  size_t nseg = num-1;
1140 
1141  m_mode = gl::line_loop();
1142 
1143  float xb,yb,zb,wb,xe,ye,ze,we;
1144  float nxb,nyb,nzb,nxe,nye,nze;
1145  float rb,gb,bb,ab,re,ge,be,ae;
1146  float* pos;
1147  float* nos;
1148  float* ros;
1149  for(size_t iseg = 0;iseg<nseg;iseg++) {
1150  pos = (float*)(a_xyzs+3*iseg);
1151  xb = *pos;pos++;
1152  yb = *pos;pos++;
1153  zb = *pos;pos++;
1154  project(xb,yb,zb,wb);
1155 
1156  xe = *pos;pos++;
1157  ye = *pos;pos++;
1158  ze = *pos;pos++;
1159  project(xe,ye,ze,we);
1160 
1161  nos = (float*)(a_nms+3*iseg);
1162  nxb = *nos;nos++;
1163  nyb = *nos;nos++;
1164  nzb = *nos;nos++;
1165  project_normal(nxb,nyb,nzb);
1166 
1167  nxe = *nos;nos++;
1168  nye = *nos;nos++;
1169  nze = *nos;nos++;
1170  project_normal(nxe,nye,nze);
1171 
1172  ros = (float*)(a_rgbas+4*iseg);
1173  rb = *ros;ros++;
1174  gb = *ros;ros++;
1175  bb = *ros;ros++;
1176  ab = *ros;ros++;
1177 
1178  re = *ros;ros++;
1179  ge = *ros;ros++;
1180  be = *ros;ros++;
1181  ae = *ros;ros++;
1182 
1183  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
1184  xe,ye,ze,we, nxe,nye,nze, re,ge,be,ae)) {
1185  if(a_stop) return false;
1186  }
1187  }
1188 
1189  //close the loop :
1190  {pos = (float*)(a_xyzs+3*nseg);
1191  xb = *pos;pos++;
1192  yb = *pos;pos++;
1193  zb = *pos;pos++;
1194  project(xb,yb,zb,wb);
1195 
1196  pos = (float*)(a_xyzs); //first point.
1197  xe = *pos;pos++;
1198  ye = *pos;pos++;
1199  ze = *pos;pos++;
1200  project(xe,ye,ze,we);
1201 
1202  nos = (float*)(a_nms+3*nseg);
1203  nxb = *nos;nos++;
1204  nyb = *nos;nos++;
1205  nzb = *nos;nos++;
1206  project_normal(nxb,nyb,nzb);
1207 
1208  nos = (float*)(a_nms);
1209  nxe = *nos;nos++;
1210  nye = *nos;nos++;
1211  nze = *nos;nos++;
1212  project_normal(nxe,nye,nze);
1213 
1214  ros = (float*)(a_rgbas+4*nseg);
1215  rb = *ros;ros++;
1216  gb = *ros;ros++;
1217  bb = *ros;ros++;
1218  ab = *ros;ros++;
1219 
1220  ros = (float*)(a_rgbas);
1221  re = *ros;ros++;
1222  ge = *ros;ros++;
1223  be = *ros;ros++;
1224  ae = *ros;ros++;
1225 
1226  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
1227  xe,ye,ze,we, nxe,nye,nze, re,ge,be,ae)) {
1228  if(a_stop) return false;
1229  }
1230 
1231  }
1232 
1233  return true;
1234  }
1235 
1236  bool add_lines(size_t a_floatn,const float* a_xyzs,bool a_stop = false) {
1237  //lines = segments.
1238  size_t num = a_floatn/3;
1239 
1240  size_t nseg = num/2;
1241  if(!nseg) return false;
1242 
1243  m_mode = gl::lines();
1244 
1245  float xb,yb,zb,wb,xe,ye,ze,we;
1246  float* pos;
1247  for(size_t iseg = 0;iseg<nseg;iseg++) {
1248  pos = (float*)(a_xyzs+6*iseg);
1249  xb = *pos;pos++;
1250  yb = *pos;pos++;
1251  zb = *pos;pos++;
1252  project(xb,yb,zb,wb);
1253 
1254  xe = *pos;pos++;
1255  ye = *pos;pos++;
1256  ze = *pos;pos++;
1257  project(xe,ye,ze,we);
1258 
1259  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)) {if(a_stop) return false;}
1260  }
1261  return true;
1262  }
1263 
1264  bool add_lines_rgba(size_t a_floatn,const float* a_xyzs,const float* a_rgbas,bool a_stop = false) {
1265  //lines = segments.
1266  size_t num = a_floatn/3;
1267 
1268  size_t nseg = num/2;
1269  if(!nseg) return false;
1270 
1271  m_mode = gl::lines();
1272 
1273  float xb,yb,zb,wb,xe,ye,ze,we;
1274  float rb,gb,bb,ab,re,ge,be,ae;
1275  float* pos;
1276  float* ros;
1277  for(size_t iseg = 0;iseg<nseg;iseg++) {
1278  pos = (float*)(a_xyzs+6*iseg);
1279  xb = *pos;pos++;
1280  yb = *pos;pos++;
1281  zb = *pos;pos++;
1282  project(xb,yb,zb,wb);
1283 
1284  xe = *pos;pos++;
1285  ye = *pos;pos++;
1286  ze = *pos;pos++;
1287  project(xe,ye,ze,we);
1288 
1289  ros = (float*)(a_rgbas+8*iseg);
1290  rb = *ros;ros++;
1291  gb = *ros;ros++;
1292  bb = *ros;ros++;
1293  ab = *ros;ros++;
1294 
1295  re = *ros;ros++;
1296  ge = *ros;ros++;
1297  be = *ros;ros++;
1298  ae = *ros;ros++;
1299 
1300  if(!add_line(xb,yb,zb,wb,rb,gb,bb,ab, xe,ye,ze,we,re,ge,be,ae)) {if(a_stop) return false;}
1301  }
1302  return true;
1303  }
1304 
1305  bool add_lines_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false) {
1306  //lines = segments.
1307  size_t num = a_floatn/3;
1308 
1309  size_t nseg = num/2;
1310  if(!nseg) return false;
1311 
1312  m_mode = gl::lines();
1313 
1314  float xb,yb,zb,wb,xe,ye,ze,we;
1315  float nxb,nyb,nzb,nxe,nye,nze;
1316 
1317  float* pos;
1318  float* nos;
1319 
1320  for(size_t iseg = 0;iseg<nseg;iseg++) {
1321  pos = (float*)(a_xyzs+6*iseg);
1322  xb = *pos;pos++;
1323  yb = *pos;pos++;
1324  zb = *pos;pos++;
1325  project(xb,yb,zb,wb);
1326 
1327  xe = *pos;pos++;
1328  ye = *pos;pos++;
1329  ze = *pos;pos++;
1330  project(xe,ye,ze,we);
1331 
1332  nos = (float*)(a_nms+6*iseg);
1333  nxb = *nos;nos++;
1334  nyb = *nos;nos++;
1335  nzb = *nos;nos++;
1336  project_normal(nxb,nyb,nzb);
1337 
1338  nxe = *nos;nos++;
1339  nye = *nos;nos++;
1340  nze = *nos;nos++;
1341  project_normal(nxe,nye,nze);
1342 
1343  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb,
1344  xe,ye,ze,we, nxe,nye,nze)) {if(a_stop) return false;}
1345  }
1346  return true;
1347  }
1348 
1349  bool add_lines_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false) {
1350  //lines = segments.
1351  size_t num = a_floatn/3;
1352 
1353  size_t nseg = num/2;
1354  if(!nseg) return false;
1355 
1356  m_mode = gl::lines();
1357 
1358  float xb,yb,zb,wb,xe,ye,ze,we;
1359  float nxb,nyb,nzb,nxe,nye,nze;
1360  float rb,gb,bb,ab,re,ge,be,ae;
1361  float* pos;
1362  float* nos;
1363  float* ros;
1364 
1365  for(size_t iseg = 0;iseg<nseg;iseg++) {
1366  pos = (float*)(a_xyzs+6*iseg);
1367  xb = *pos;pos++;
1368  yb = *pos;pos++;
1369  zb = *pos;pos++;
1370  project(xb,yb,zb,wb);
1371 
1372  xe = *pos;pos++;
1373  ye = *pos;pos++;
1374  ze = *pos;pos++;
1375  project(xe,ye,ze,we);
1376 
1377  nos = (float*)(a_nms+6*iseg);
1378  nxb = *nos;nos++;
1379  nyb = *nos;nos++;
1380  nzb = *nos;nos++;
1381  project_normal(nxb,nyb,nzb);
1382 
1383  nxe = *nos;nos++;
1384  nye = *nos;nos++;
1385  nze = *nos;nos++;
1386  project_normal(nxe,nye,nze);
1387 
1388  ros = (float*)(a_rgbas+8*iseg);
1389  rb = *ros;ros++;
1390  gb = *ros;ros++;
1391  bb = *ros;ros++;
1392  ab = *ros;ros++;
1393 
1394  re = *ros;ros++;
1395  ge = *ros;ros++;
1396  be = *ros;ros++;
1397  ae = *ros;ros++;
1398 
1399  if(!add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
1400  xe,ye,ze,we, nxe,nye,nze, re,ge,be,ae)) {if(a_stop) return false;}
1401  }
1402  return true;
1403  }
1404 
1405  bool add_points(size_t a_floatn,const float* a_xyzs,bool a_stop = false){
1406  size_t num = a_floatn/3;
1407 
1408  m_mode = gl::points();
1409 
1410  float x,y,z,w;
1411  float* pos;
1412  for(size_t ipt=0;ipt<num;ipt++) {
1413  pos = (float*)(a_xyzs+3*ipt);
1414  x = *pos;pos++;
1415  y = *pos;pos++;
1416  z = *pos;pos++;
1417  project(x,y,z,w);
1418 
1419  if(!add_point(x,y,z,w)) {if(a_stop) return false;}
1420  }
1421  return true;
1422  }
1423 
1424  bool add_points_rgba(size_t a_floatn,const float* a_xyzs,const float* a_rgbas,bool a_stop = false){
1425  size_t num = a_floatn/3;
1426 
1427  m_mode = gl::points();
1428 
1429  float x,y,z,w;
1430  float r,g,b,a;
1431 
1432  float* pos;
1433  float* ros;
1434 
1435  for(size_t ipt=0;ipt<num;ipt++) {
1436  pos = (float*)(a_xyzs+3*ipt);
1437  x = *pos;pos++;
1438  y = *pos;pos++;
1439  z = *pos;pos++;
1440  project(x,y,z,w);
1441 
1442  ros = (float*)(a_rgbas+4*ipt);
1443  r = *ros;ros++;
1444  g = *ros;ros++;
1445  b = *ros;ros++;
1446  a = *ros;ros++;
1447 
1448  if(!add_point(x,y,z,w,r,g,b,a)) {if(a_stop) return false;}
1449  }
1450  return true;
1451  }
1452 
1453  bool add_points_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false){
1454  size_t num = a_floatn/3;
1455 
1456  m_mode = gl::points();
1457 
1458  float x,y,z,w;
1459  float nx,ny,nz;
1460  float* pos;
1461  float* nos;
1462 
1463  for(size_t ipt=0;ipt<num;ipt++) {
1464  pos = (float*)(a_xyzs+3*ipt);
1465  x = *pos;pos++;
1466  y = *pos;pos++;
1467  z = *pos;pos++;
1468  project(x,y,z,w);
1469 
1470  nos = (float*)(a_nms+3*ipt);
1471  nx = *nos;nos++;
1472  ny = *nos;nos++;
1473  nz = *nos;nos++;
1474  project_normal(nx,ny,nz);
1475 
1476  if(!add_point_normal(x,y,z,w,nx,ny,nz)) {if(a_stop) return false;}
1477  }
1478  return true;
1479  }
1480 
1481  bool add_points_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false){
1482  size_t num = a_floatn/3;
1483 
1484  m_mode = gl::points();
1485 
1486  float x,y,z,w;
1487  float nx,ny,nz;
1488  float r,g,b,a;
1489 
1490  float* pos;
1491  float* nos;
1492  float* ros;
1493 
1494  for(size_t ipt=0;ipt<num;ipt++) {
1495  pos = (float*)(a_xyzs+3*ipt);
1496  x = *pos;pos++;
1497  y = *pos;pos++;
1498  z = *pos;pos++;
1499  project(x,y,z,w);
1500 
1501  nos = (float*)(a_nms+3*ipt);
1502  nx = *nos;nos++;
1503  ny = *nos;nos++;
1504  nz = *nos;nos++;
1505  project_normal(nx,ny,nz);
1506 
1507  ros = (float*)(a_rgbas+4*ipt);
1508  r = *ros;ros++;
1509  g = *ros;ros++;
1510  b = *ros;ros++;
1511  a = *ros;ros++;
1512 
1513  if(!add_point_normal(x,y,z,w,nx,ny,nz,r,g,b,a)) {if(a_stop) return false;}
1514  }
1515  return true;
1516  }
1517 
1518  bool add_primitive(gl::mode_t a_mode,size_t a_floatn,const float* a_xyzs,bool a_stop = false) {
1519 
1520  if(a_mode==gl::points()) {
1521  return add_points(a_floatn,a_xyzs,a_stop);
1522 
1523  } else if(a_mode==gl::lines()) {
1524  return add_lines(a_floatn,a_xyzs,a_stop);
1525 
1526  } else if(a_mode==gl::line_loop()) {
1527  return add_line_loop(a_floatn,a_xyzs,a_stop);
1528 
1529  } else if(a_mode==gl::line_strip()) {
1530  return add_line_strip(a_floatn,a_xyzs,a_stop);
1531 
1532  } else if(a_mode==gl::triangles()) {
1533  return add_triangles(a_floatn,a_xyzs,a_stop);
1534 
1535  } else if(a_mode==gl::triangle_strip()) {
1536  return add_triangle_strip(a_floatn,a_xyzs,a_stop);
1537 
1538  } else if(a_mode==gl::triangle_fan()) {
1539  return add_triangle_fan(a_floatn,a_xyzs,a_stop);
1540 
1541  } else {
1542  return false;
1543  }
1544  }
1545 
1546  bool add_primitive_rgba(gl::mode_t a_mode,size_t a_floatn,const float* a_xyzs,const float* a_rgbas,bool a_stop = false){
1547 
1548  if(a_mode==gl::points()) {
1549  return add_points_rgba(a_floatn,a_xyzs,a_rgbas,a_stop);
1550 
1551  } else if(a_mode==gl::lines()) {
1552  return add_lines_rgba(a_floatn,a_xyzs,a_rgbas,a_stop);
1553 
1554  } else if(a_mode==gl::line_loop()) {
1555  return add_line_loop_rgba(a_floatn,a_xyzs,a_rgbas,a_stop);
1556 
1557  } else if(a_mode==gl::line_strip()) {
1558  return add_line_strip_rgba(a_floatn,a_xyzs,a_rgbas,a_stop);
1559 
1560  } else if(a_mode==gl::triangles()) {
1561  return add_triangles_rgba(a_floatn,a_xyzs,a_rgbas,a_stop);
1562 
1563  } else if(a_mode==gl::triangle_strip()) {
1564  //return add_triangle_strip_rgba(a_floatn,a_xyzs,a_rgbas,a_stop); //uuuuu
1565  return add_triangle_strip(a_floatn,a_xyzs,a_stop);
1566 
1567  } else if(a_mode==gl::triangle_fan()) {
1568  //return add_triangle_fan_rgba(a_floatn,a_xyzs,a_rgbas,a_stop); //uuuuu
1569  return add_triangle_fan(a_floatn,a_xyzs,a_stop);
1570 
1571  } else {
1572  return false;
1573  }
1574  }
1575 
1576  bool add_primitive_normal(gl::mode_t a_mode,size_t a_floatn,const float* a_xyzs,const float* a_nms,bool a_stop = false) {
1577 
1578  if(a_mode==gl::points()) {
1579  return add_points_normal(a_floatn,a_xyzs,a_nms,a_stop);
1580 
1581  } else if(a_mode==gl::lines()) {
1582  return add_lines_normal(a_floatn,a_xyzs,a_nms,a_stop);
1583 
1584  } else if(a_mode==gl::line_loop()) {
1585  return add_line_loop_normal(a_floatn,a_xyzs,a_nms,a_stop);
1586 
1587  } else if(a_mode==gl::line_strip()) {
1588  return add_line_strip_normal(a_floatn,a_xyzs,a_nms,a_stop);
1589 
1590  } else if(a_mode==gl::triangles()) {
1591  return add_triangles_normal(a_floatn,a_xyzs,a_nms,a_stop);
1592 
1593  } else if(a_mode==gl::triangle_strip()) {
1594  return add_triangle_strip_normal(a_floatn,a_xyzs,a_nms,a_stop);
1595 
1596  } else if(a_mode==gl::triangle_fan()) {
1597  return add_triangle_fan_normal(a_floatn,a_xyzs,a_nms,a_stop);
1598 
1599  } else {
1600  return false;
1601  }
1602  }
1603 
1604  bool add_primitive_normal_rgba(gl::mode_t a_mode,size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas,bool a_stop = false){
1605 
1606  if(a_mode==gl::points()) {
1607  return add_points_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,a_stop);
1608 
1609  } else if(a_mode==gl::lines()) {
1610  return add_lines_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,a_stop);
1611 
1612  } else if(a_mode==gl::line_loop()) {
1613  return add_line_loop_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,a_stop);
1614 
1615  } else if(a_mode==gl::line_strip()) {
1616  return add_line_strip_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,a_stop);
1617 
1618  } else if(a_mode==gl::triangles()) {
1619  return add_triangles_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,a_stop);
1620 
1621  } else if(a_mode==gl::triangle_strip()) {
1622  return add_triangle_strip_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,a_stop);
1623 
1624  } else if(a_mode==gl::triangle_fan()) {
1625  return add_triangle_fan_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,a_stop);
1626 
1627  } else {
1628  return false;
1629  }
1630  }
1631 
1635 
1636  bool add_points_xy(size_t a_floatn,const float* a_xys,bool a_stop = false) {
1637  size_t num = a_floatn/2;
1638 
1639  m_mode = gl::points();
1640 
1641  float x,y,z,w;
1642  float* pos;
1643  for(size_t ipt=0;ipt<num;ipt++) {
1644  pos = (float*)(a_xys+2*ipt);
1645  x = *pos;pos++;
1646  y = *pos;pos++;
1647  z = 0;
1648 
1649  project(x,y,z,w);
1650 
1651  if(!add_point(x,y,z,w)) {if(a_stop) return false;}
1652  }
1653  return true;
1654  }
1655 
1656  bool add_triangle_fan_xy(size_t a_floatn,const float* a_xys,
1657  bool a_stop = false,
1658  bool a_triangle_revert = false){
1659  size_t num = a_floatn/2;
1660  if(num<3) return false;
1661 
1663 
1664  float p1x,p1y,p1z,w1=1;
1665  float p2x,p2y,p2z,w2=1;
1666  float p3x,p3y,p3z,w3=1;
1667 
1668  const float* pos1 = a_xys+2*0;
1669  p1x = *(pos1+0);
1670  p1y = *(pos1+1);
1671  p1z = 0;
1672  project(p1x,p1y,p1z,w1);
1673 
1674  const float* pos2 = a_xys+2*1;
1675  p2x = *(pos2+0);
1676  p2y = *(pos2+1);
1677  p2z = 0;
1678  project(p2x,p2y,p2z,w2);
1679 
1680  for(size_t index=2;index<num;index++) {
1681  const float* pos = a_xys+2*index;
1682  p3x = *(pos+0);
1683  p3y = *(pos+1);
1684  p3z = 0;
1685  project(p3x,p3y,p3z,w3);
1686 
1687  if(a_triangle_revert) {
1688  if(!add_triangle(p3x,p3y,p3z,w3,
1689  p2x,p2y,p2z,w2,
1690  p1x,p1y,p1z,w1)) {
1691  if(a_stop) return false;
1692  }
1693  } else {
1694  if(!add_triangle(p1x,p1y,p1z,w1,
1695  p2x,p2y,p2z,w2,
1696  p3x,p3y,p3z,w3)) {
1697  if(a_stop) return false;
1698  }
1699  }
1700 
1701 
1702  p2x = p3x;
1703  p2y = p3y;
1704  p2z = p3z;
1705  w2 = w3;
1706  }
1707  return true;
1708  }
1709 
1710  bool add_triangle_strip_xy(size_t a_floatn,const float* a_xys,
1711  bool a_stop = false,
1712  bool a_triangle_revert = false){
1713  size_t num = a_floatn/2;
1714  if(num<3) return false;
1715 
1717 
1718  float p1x,p1y,p1z,w1=1;
1719  float p2x,p2y,p2z,w2=1;
1720  float p3x,p3y,p3z,w3=1;
1721 
1722  const float* pos1 = a_xys+2*0;
1723  p1x = *(pos1+0);
1724  p1y = *(pos1+1);
1725  p1z = 0;
1726  project(p1x,p1y,p1z,w1);
1727 
1728  const float* pos2 = a_xys+2*1;
1729  p2x = *(pos2+0);
1730  p2y = *(pos2+1);
1731  p2z = 0;
1732  project(p2x,p2y,p2z,w2);
1733 
1734  bool flip = false;
1735  for(size_t index=2;index<num;index++) {
1736  const float* pos = a_xys+2*index;
1737  p3x = *(pos+0);
1738  p3y = *(pos+1);
1739  p3z = 0;
1740  project(p3x,p3y,p3z,w3);
1741 
1742  if(a_triangle_revert) {
1743 
1744  if(flip){
1745  if(!add_triangle(p2x,p2y,p2z,w2,
1746  p3x,p3y,p3z,w3,
1747  p1x,p1y,p1z,w1)) {
1748  if(a_stop) return false;
1749  }
1750  } else {
1751  if(!add_triangle(p3x,p3y,p3z,w3,
1752  p2x,p2y,p2z,w2,
1753  p1x,p1y,p1z,w1)) {
1754  if(a_stop) return false;
1755  }
1756  }
1757 
1758  } else {
1759 
1760  if(flip){
1761  if(!add_triangle(p1x,p1y,p1z,w1,
1762  p3x,p3y,p3z,w3,
1763  p2x,p2y,p2z,w2)) {
1764  if(a_stop) return false;
1765  }
1766  } else {
1767  if(!add_triangle(p1x,p1y,p1z,w1,
1768  p2x,p2y,p2z,w2,
1769  p3x,p3y,p3z,w3)) {
1770  if(a_stop) return false;
1771  }
1772  }
1773 
1774  }
1775 
1776  p1x = p2x;
1777  p1y = p2y;
1778  p1z = p2z;
1779  w1 = w2;
1780 
1781  p2x = p3x;
1782  p2y = p3y;
1783  p2z = p3z;
1784  w2 = w3;
1785 
1786  flip = flip?false:true;
1787  }
1788  return true;
1789  }
1790 
1791  bool add_triangles_xy(size_t a_floatn,const float* a_xys,bool a_stop = false,bool a_triangle_revert = false){
1792  size_t num = a_floatn/2;
1793  if(num<3) return false;
1794 
1795  m_mode = gl::triangles();
1796 
1797  float p1x,p1y,p1z,w1=1;
1798  float p2x,p2y,p2z,w2=1;
1799  float p3x,p3y,p3z,w3=1;
1800 
1801  for(size_t index=0;index<num;index+=3) {
1802 
1803  const float* pos1 = a_xys+2*index;
1804  p1x = *(pos1+0);
1805  p1y = *(pos1+1);
1806  p1z = 0;
1807  project(p1x,p1y,p1z,w1);
1808 
1809  const float* pos2 = a_xys+2*(index+1);
1810  p2x = *(pos2+0);
1811  p2y = *(pos2+1);
1812  p2z = 0;
1813  project(p2x,p2y,p2z,w2);
1814 
1815  const float* pos3 = a_xys+2*(index+2);
1816  p3x = *(pos3+0);
1817  p3y = *(pos3+1);
1818  p3z = 0;
1819  project(p3x,p3y,p3z,w3);
1820 
1821  if(a_triangle_revert) {
1822  if(!add_triangle(p3x,p3y,p3z,w3,
1823  p2x,p2y,p2z,w2,
1824  p1x,p1y,p1z,w1)) {
1825  if(a_stop) return false;
1826  }
1827  } else {
1828  if(!add_triangle(p1x,p1y,p1z,w1,
1829  p2x,p2y,p2z,w2,
1830  p3x,p3y,p3z,w3)) {
1831  if(a_stop) return false;
1832  }
1833  }
1834  }
1835  return true;
1836  }
1837 
1838  bool add_line_loop_xy(size_t a_floatn,const float* a_xys,bool a_stop = false){
1839  size_t num = a_floatn/2;
1840  if(num<=1) return false;
1841  size_t nseg = num-1;
1842 
1843  m_mode = gl::line_loop();
1844 
1845  float xb,yb,zb,wb,xe,ye,ze,we;
1846  float* pos;
1847  for(size_t iseg = 0;iseg<nseg;iseg++) {
1848  pos = (float*)(a_xys+2*iseg);
1849  xb = *pos;pos++;
1850  yb = *pos;pos++;
1851  zb = 0;
1852  project(xb,yb,zb,wb);
1853 
1854  xe = *pos;pos++;
1855  ye = *pos;pos++;
1856  ze = 0;
1857  project(xe,ye,ze,we);
1858 
1859  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)) {if(a_stop) return false;}
1860  }
1861 
1862  //close the loop :
1863  {pos = (float*)(a_xys+2*(nseg-1)+2);
1864  xb = *pos;pos++;
1865  yb = *pos;pos++;
1866  zb = 0;
1867  project(xb,yb,zb,wb);
1868 
1869  pos = (float*)(a_xys); //first point.
1870  xe = *pos;pos++;
1871  ye = *pos;pos++;
1872  ze = 0;
1873  project(xe,ye,ze,we);
1874 
1875  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)){if(a_stop) return false;}
1876  }
1877 
1878  return true;
1879  }
1880 
1881  bool add_line_strip_xy(size_t a_floatn,const float* a_xys,bool a_stop = false){
1882  size_t num = a_floatn/2;
1883  if(num<=1) return false;
1884  size_t nseg = num-1;
1885 
1886  m_mode = gl::line_strip();
1887 
1888  float xb,yb,zb,wb,xe,ye,ze,we;
1889  float* pos;
1890  for(size_t iseg = 0;iseg<nseg;iseg++) {
1891  pos = (float*)(a_xys+2*iseg);
1892  xb = *pos;pos++;
1893  yb = *pos;pos++;
1894  zb = 0;
1895  project(xb,yb,zb,wb);
1896 
1897  xe = *pos;pos++;
1898  ye = *pos;pos++;
1899  ze = 0;
1900  project(xe,ye,ze,we);
1901 
1902  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)) {if(a_stop) return false;}
1903  }
1904  return true;
1905  }
1906 
1907  bool add_lines_xy(size_t a_floatn,const float* a_xys,bool a_stop = false){
1908  //lines = segments. Each point having only (x,y) (no z).
1909  //used in tools::sg::[text_freetype, text_hershey].
1910 
1911  size_t num = a_floatn/2;
1912 
1913  size_t nseg = num/2;
1914  if(!nseg) return false;
1915 
1916  m_mode = gl::lines();
1917 
1918  float xb,yb,zb,wb,xe,ye,ze,we;
1919  float* pos;
1920  for(size_t iseg = 0;iseg<nseg;iseg++) {
1921  pos = (float*)(a_xys+4*iseg);
1922  xb = *pos;pos++;
1923  yb = *pos;pos++;
1924  zb = 0;
1925  project(xb,yb,zb,wb);
1926 
1927  xe = *pos;pos++;
1928  ye = *pos;pos++;
1929  ze = 0;
1930  project(xe,ye,ze,we);
1931 
1932  if(!add_line(xb,yb,zb,wb, xe,ye,ze,we)) {if(a_stop) return false;}
1933  }
1934  return true;
1935  }
1936 
1937  bool add_primitive_xy(gl::mode_t a_mode,size_t a_floatn,const float* a_xys,bool a_stop = false,bool a_triangle_revert = false){
1938 
1939  if(a_mode==gl::points()) {
1940  return add_points_xy(a_floatn,a_xys,a_stop);
1941 
1942  } else if(a_mode==gl::lines()) {
1943  return add_lines_xy(a_floatn,a_xys,a_stop);
1944 
1945  } else if(a_mode==gl::line_loop()) {
1946  return add_line_loop_xy(a_floatn,a_xys,a_stop);
1947 
1948  } else if(a_mode==gl::line_strip()) {
1949  return add_line_strip_xy(a_floatn,a_xys,a_stop);
1950 
1951  } else if(a_mode==gl::triangles()) {
1952  return add_triangles_xy(a_floatn,a_xys,a_stop,a_triangle_revert);
1953 
1954  } else if(a_mode==gl::triangle_strip()) {
1955  return add_triangle_strip_xy(a_floatn,a_xys,a_stop,a_triangle_revert);
1956 
1957  } else if(a_mode==gl::triangle_fan()) {
1958  return add_triangle_fan_xy(a_floatn,a_xys,a_stop,a_triangle_revert);
1959 
1960  } else {
1961  return false;
1962  }
1963  }
1964 
1965 public:
1966  bool add_primitive(gl::mode_t a_mode,const std::vector<float>& a_xyzs,bool a_stop = false){
1967  const float* _xyzs = vec_data<float>(a_xyzs);
1968  return add_primitive(a_mode,a_xyzs.size(),_xyzs,a_stop);
1969  }
1970  bool add_primitive_xy(gl::mode_t a_mode,const std::vector<float>& a_xys,bool a_stop = false,bool a_triangle_revert = false){
1971  const float* _xys = vec_data<float>(a_xys);
1972  return add_primitive_xy(a_mode,a_xys.size(),_xys,a_stop,a_triangle_revert);
1973  }
1974  bool add_line_strip(const std::vector<float>& a_xyzs,bool a_stop = false){
1975  const float* _xyzs = vec_data<float>(a_xyzs);
1976  return add_line_strip(a_xyzs.size(),_xyzs,a_stop);
1977  }
1978  bool add_line_loop(const std::vector<float>& a_xyzs,bool a_stop = false){
1979  const float* _xyzs = vec_data<float>(a_xyzs);
1980  return add_line_loop(a_xyzs.size(),_xyzs,a_stop);
1981  }
1982  bool add_lines(const std::vector<float>& a_xyzs,bool a_stop = false){
1983  const float* _xyzs = vec_data<float>(a_xyzs);
1984  return add_lines(a_xyzs.size(),_xyzs,a_stop);
1985  }
1986  bool add_points(const std::vector<float>& a_xyzs,bool a_stop = false){
1987  const float* _xyzs = vec_data<float>(a_xyzs);
1988  return add_points(a_xyzs.size(),_xyzs,a_stop);
1989  }
1990 
1991  bool add_triangle_strip(const std::vector<float>& a_xyzs,bool a_stop = false){
1992  const float* _xyzs = vec_data<float>(a_xyzs);
1993  return add_triangle_strip(a_xyzs.size(),_xyzs,a_stop);
1994  }
1995 
1996  bool add_points_xy(const std::vector<float>& a_xys,bool a_stop = false){
1997  const float* _xys = vec_data<float>(a_xys);
1998  return add_points_xy(a_xys.size(),_xys,a_stop);
1999  }
2000  bool add_lines_xy(const std::vector<float>& a_xys,bool a_stop = false){
2001  const float* _xys = vec_data<float>(a_xys);
2002  return add_lines_xy(a_xys.size(),_xys,a_stop);
2003  }
2004  bool add_triangle_strip_xy(const std::vector<float>& a_xys,bool a_stop = false){
2005  const float* _xys = vec_data<float>(a_xys);
2006  return add_triangle_strip_xy(a_xys.size(),_xys,a_stop);
2007  }
2008 
2009 
2010 public:
2011  //for sg::[tex_]sphere::visit() template :
2012 // bool add_triangle_fan_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
2013 // return add_triangle_fan_normal(a_floatn,a_xyzs,a_nms,false);
2014 // }
2015 // bool add_triangle_fan_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas) {
2016 // return add_triangle_fan_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,false);
2017 // }
2018 /*
2019  bool add_triangles_texture(size_t a_floatn,const float* a_xyzs,unsigned int,const float*){
2020  return add_triangles(a_floatn,a_xyzs);
2021  }
2022  bool add_triangle_fan_texture(size_t a_floatn,const float* a_xyzs,unsigned int,const float*){
2023  return add_triangle_fan(a_floatn,a_xyzs);
2024  }
2025  bool add_triangle_strip_texture(size_t a_floatn,const float* a_xyzs,unsigned int,const float*){
2026  return add_triangle_strip(a_floatn,a_xyzs,false);
2027  }
2028 */
2029  bool add_triangle_fan_texture_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,unsigned int,const float*){
2030  return add_triangle_fan_normal(a_floatn,a_xyzs,a_nms,false);
2031  }
2032  bool add_triangle_strip_texture_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms,unsigned int,const float*){
2033  return add_triangle_strip_normal(a_floatn,a_xyzs,a_nms,false);
2034  }
2035 
2036 // bool add_triangle_strip_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
2037 // return add_triangle_strip_normal(a_floatn,a_xyzs,a_nms,false);
2038 // }
2039 // bool add_triangle_strip_normal_rgba(size_t a_floatn,const float* a_xyzs,const float* a_nms,const float* a_rgbas) {
2040 // return add_triangle_strip_normal_rgba(a_floatn,a_xyzs,a_nms,a_rgbas,false);
2041 // }
2042 
2043  bool add_triangle_strip_as_triangles(size_t a_floatn,const float* a_xyzs,const float* a_nms) { //used in sg::sphere, icosahedron_sphere.
2044  return add_triangle_strip_normal(a_floatn,a_xyzs,a_nms,false); //already do a per triangle treatement.
2045  }
2046 public:
2047  void add_texture(std::ostream& a_out,size_t a_xyzn,const float* a_xyzs,const img_byte& a_img,const float* a_tcs) {
2048  if(a_img.is_empty()) return;
2049 
2050  unsigned int imw = a_img.width();
2051  unsigned int imh = a_img.height();
2052  unsigned int imn = a_img.bpp();
2053  if((imn!=3)&&(imn!=4)) {
2054  a_out << "tools::sg::primitive_visitor::add_texture :"
2055  << " not a 3 or 4 bytes per pixel image."
2056  << std::endl;
2057  return;
2058  }
2059 
2060  if(a_xyzn!=12) {
2061  a_out << "tools::sg::primitive_visitor::add_texture :"
2062  << " primitive has not four points."
2063  << std::endl;
2064  return;
2065  }
2066 
2067  //::printf("debug : zb_action : tcs : %g %g, %g %g, %g %g, %g %g\n",
2068  // a_tcs[0],a_tcs[1],a_tcs[2],a_tcs[3],a_tcs[4],a_tcs[5],a_tcs[6],a_tcs[7]);
2069 
2070  vec3f p1(a_xyzs[0],a_xyzs[ 1],a_xyzs[ 2]);
2071  vec3f p2(a_xyzs[3],a_xyzs[ 4],a_xyzs[ 5]);
2072  //vec3f p3(a_xyzs[6],a_xyzs[ 7],a_xyzs[ 8]);
2073  vec3f p4(a_xyzs[9],a_xyzs[10],a_xyzs[11]);
2074 
2075  vec3f dx = p2-p1;
2076  vec3f dy = p4-p1;
2077 
2078  vec2f t1(a_tcs[0],a_tcs[1]);
2079  vec2f t2(a_tcs[2],a_tcs[3]);
2080  vec2f t3(a_tcs[4],a_tcs[5]);
2081  vec2f t4(a_tcs[6],a_tcs[7]);
2082  vec2f tdx = t2-t1;
2083  vec2f tdy = t4-t1;
2084  if(!tdx.length()) {
2085  a_out << "tools::sg::primitive_visitor::add_texture :"
2086  << " tdx is null."
2087  << std::endl;
2088  return;
2089  }
2090  if(!tdy.length()) {
2091  a_out << "tools::sg::primitive_visitor::add_texture :"
2092  << " tdy is null."
2093  << std::endl;
2094  return;
2095  }
2096  std::vector<vec2f> poly;
2097  poly.push_back(t1);
2098  poly.push_back(t2);
2099  poly.push_back(t3);
2100  poly.push_back(t4);
2101  poly.push_back(t1);
2102 
2103  {float r,g,b,a,tx,ty;
2104  vec3f p;
2105  vec2f t;
2106  unsigned char* pos = (unsigned char*)a_img.buffer();
2107  for(unsigned int row=0;row<imh;row++) {
2108  for(unsigned int col=0;col<imw;col++) {
2109  r = (*pos)/255.0f;pos++;
2110  g = (*pos)/255.0f;pos++;
2111  b = (*pos)/255.0f;pos++;
2112  a = 1;
2113  if(imn==4) {
2114  a = (*pos)/255.0f;pos++;
2115  }
2116 
2117  tx = float(col)/float(imw-1); //[0,1]
2118  ty = float(row)/float(imh-1); //[0,1]
2119 
2120  t.set_value(tx,ty);
2121 
2122  if(!is_inside(t,poly)) continue;
2123 
2124  t = t - t1;
2125 
2126  p = p1+dx*t.x()/tdx.length()+dy*t.y()/tdy.length();
2127 
2128  add_one_point(p.x(),p.y(),p.z(),r,g,b,a);
2129  }
2130  }}
2131 
2132  }
2133 protected:
2135 };
2136 
2137 }}
2138 
2139 #endif
tools::sg::primitive_visitor::add_primitive
bool add_primitive(gl::mode_t a_mode, const std::vector< float > &a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1966
tools::sg::primitive_visitor::add_triangle_fan_xy
bool add_triangle_fan_xy(size_t a_floatn, const float *a_xys, bool a_stop=false, bool a_triangle_revert=false)
Definition: primitive_visitor:1656
tools::sg::primitive_visitor::add_primitive_normal_rgba
bool add_primitive_normal_rgba(gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:1604
tools::vec2f
Definition: vec2f:13
tools::sg::primitive_visitor::add_triangle_fan_texture_normal
bool add_triangle_fan_texture_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, unsigned int, const float *)
Definition: primitive_visitor:2029
tools::sg::primitive_visitor::add_triangles_normal_rgba
bool add_triangles_normal_rgba(size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:707
tools::sg::primitive_visitor::add_lines_xy
bool add_lines_xy(size_t a_floatn, const float *a_xys, bool a_stop=false)
Definition: primitive_visitor:1907
tools::img< unsigned char >
tools::sg::primitive_visitor::add_triangles_xy
bool add_triangles_xy(size_t a_floatn, const float *a_xys, bool a_stop=false, bool a_triangle_revert=false)
Definition: primitive_visitor:1791
tools::sg::primitive_visitor::add_triangle_fan_normal
bool add_triangle_fan_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:117
tools::sg::primitive_visitor::add_triangles_normal
bool add_triangles_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:589
tools::sg::primitive_visitor::add_triangle
virtual bool add_triangle(float, float, float, float, float, float, float, float, float, float, float, float)=0
tools::sg::primitive_visitor::add_triangle_strip
bool add_triangle_strip(const std::vector< float > &a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1991
tools::gl::triangles
mode_t triangles()
Definition: glprims:20
tools::sg::primitive_visitor::add_triangle_normal
virtual bool add_triangle_normal(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)=0
tools::sg::primitive_visitor::primitive_visitor
primitive_visitor(const primitive_visitor &)
Definition: primitive_visitor:60
tools::sg::primitive_visitor::add_triangle_strip_xy
bool add_triangle_strip_xy(size_t a_floatn, const float *a_xys, bool a_stop=false, bool a_triangle_revert=false)
Definition: primitive_visitor:1710
tools::vec2::x
const T & x() const
Definition: vec2:73
tools::sg::primitive_visitor::add_triangle_strip_as_triangles
bool add_triangle_strip_as_triangles(size_t a_floatn, const float *a_xyzs, const float *a_nms)
Definition: primitive_visitor:2043
tools::sg::primitive_visitor::add_lines_xy
bool add_lines_xy(const std::vector< float > &a_xys, bool a_stop=false)
Definition: primitive_visitor:2000
tools::sg::primitive_visitor::add_points_rgba
bool add_points_rgba(size_t a_floatn, const float *a_xyzs, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:1424
tools::sg::primitive_visitor::project_normal
virtual bool project_normal(float &a_x, float &a_y, float &a_z)=0
tools::sg::primitive_visitor::add_primitive
bool add_primitive(gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1518
tools::gl::triangle_fan
mode_t triangle_fan()
Definition: glprims:22
tools::sg::primitive_visitor::add_primitive_normal
bool add_primitive_normal(gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:1576
tools::gl::lines
mode_t lines()
Definition: glprims:17
tools::sg::primitive_visitor::add_line_strip_normal
bool add_line_strip_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:855
tools::sg::primitive_visitor::add_one_point
void add_one_point(float a_x, float a_y, float a_z)
Definition: primitive_visitor:63
tools::sg::primitive_visitor::add_triangles_rgba
bool add_triangles_rgba(size_t a_floatn, const float *a_xyzs, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:648
tools::sg::primitive_visitor::add_lines
bool add_lines(const std::vector< float > &a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1982
tools::sg::primitive_visitor::add_triangle_fan_normal_rgba
bool add_triangle_fan_normal_rgba(size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:186
tools::sg::primitive_visitor::add_triangle_strip_xy
bool add_triangle_strip_xy(const std::vector< float > &a_xys, bool a_stop=false)
Definition: primitive_visitor:2004
tools::sg::primitive_visitor::add_line_strip
bool add_line_strip(const std::vector< float > &a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1974
tools::sg::primitive_visitor::add_lines_normal_rgba
bool add_lines_normal_rgba(size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:1349
tools::sg::primitive_visitor::add_triangle_strip
bool add_triangle_strip(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:282
tools::sg::primitive_visitor::add_primitive_rgba
bool add_primitive_rgba(gl::mode_t a_mode, size_t a_floatn, const float *a_xyzs, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:1546
tools::gl::line_strip
mode_t line_strip()
Definition: glprims:19
tools::ge
bool ge(std::ostream &a_out, const char *a_file, int a_line, const INTEGER &a_v, const INTEGER &a_expected)
Definition: test:80
tools::sg::primitive_visitor::add_texture
void add_texture(std::ostream &a_out, size_t a_xyzn, const float *a_xyzs, const img_byte &a_img, const float *a_tcs)
Definition: primitive_visitor:2047
tools::sg::primitive_visitor::add_line_loop_normal_rgba
bool add_line_loop_normal_rgba(size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:1136
tools::img::width
unsigned int width() const
Definition: img:214
tools::sg::primitive_visitor::add_line_strip_normal_rgba
bool add_line_strip_normal_rgba(size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:895
tools::vec2f::length
float length() const
Definition: vec2f:60
tools::vec3::y
const T & y() const
Definition: vec3:85
tools::sg::primitive_visitor::add_lines
bool add_lines(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1236
tools::sg::primitive_visitor::add_line_strip_xy
bool add_line_strip_xy(size_t a_floatn, const float *a_xys, bool a_stop=false)
Definition: primitive_visitor:1881
tools::sg::primitive_visitor::add_line
virtual bool add_line(float, float, float, float, float, float, float, float)=0
tools::vec3::x
const T & x() const
Definition: vec3:84
tools::sg::primitive_visitor::add_point_normal
virtual bool add_point_normal(float, float, float, float, float, float, float)=0
tools::sg::primitive_visitor::add_points_normal
bool add_points_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:1453
tools::gl::triangle_strip
mode_t triangle_strip()
Definition: glprims:21
tools::sg::primitive_visitor::operator=
primitive_visitor & operator=(const primitive_visitor &)
Definition: primitive_visitor:61
tools::sg::primitive_visitor::add_triangle_strip_normal
bool add_triangle_strip_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:379
tools::img::is_empty
bool is_empty() const
Definition: img:194
tools::sg::primitive_visitor::project
virtual bool project(float &a_x, float &a_y, float &a_z, float &a_w)=0
tools::sg::primitive_visitor::add_line
virtual bool add_line(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)=0
tools::gl::points
mode_t points()
Definition: glprims:16
tools::sg::primitive_visitor::m_mode
gl::mode_t m_mode
Definition: primitive_visitor:2134
tools::sg::primitive_visitor::add_points
bool add_points(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1405
tools::vec3f
Definition: vec3f:13
tools::sg::primitive_visitor::add_point
virtual bool add_point(float, float, float, float, float, float, float, float)=0
tools::gl::mode_t
unsigned char mode_t
Definition: glprims:14
tools::sg::primitive_visitor::add_line_strip_rgba
bool add_line_strip_rgba(size_t a_floatn, const float *a_xyzs, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:813
tools::sg::primitive_visitor::add_triangle_strip_normal_rgba
bool add_triangle_strip_normal_rgba(size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:468
tools::sg::primitive_visitor::add_line_loop_normal
bool add_line_loop_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:1065
tools::sg::primitive_visitor::add_line_loop
bool add_line_loop(const std::vector< float > &a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1978
tools::sg::primitive_visitor::add_triangle_fan
bool add_triangle_fan(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:74
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::primitive_visitor::add_line_loop_rgba
bool add_line_loop_rgba(size_t a_floatn, const float *a_xyzs, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:993
tools::sg::primitive_visitor::add_line_loop_xy
bool add_line_loop_xy(size_t a_floatn, const float *a_xys, bool a_stop=false)
Definition: primitive_visitor:1838
tools::sg::primitive_visitor::~primitive_visitor
virtual ~primitive_visitor()
Definition: primitive_visitor:58
tools::sg::primitive_visitor::add_points
bool add_points(const std::vector< float > &a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1986
tools::sg::primitive_visitor::add_line_strip
bool add_line_strip(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:787
tools::gl::line_loop
mode_t line_loop()
Definition: glprims:18
tools::sg::primitive_visitor::add_line_normal
virtual bool add_line_normal(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)=0
tools::vec2::y
const T & y() const
Definition: vec2:74
tools::sg::primitive_visitor::add_line_loop
bool add_line_loop(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:950
tools::sg::primitive_visitor::add_one_point
void add_one_point(float a_x, float a_y, float a_z, float a_r, float a_g, float a_b, float a_a)
Definition: primitive_visitor:68
tools::sg::primitive_visitor::add_triangle_normal
virtual bool add_triangle_normal(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)=0
tools::sg::primitive_visitor::add_lines_rgba
bool add_lines_rgba(size_t a_floatn, const float *a_xyzs, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:1264
tools::sg::primitive_visitor::add_lines_normal
bool add_lines_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, bool a_stop=false)
Definition: primitive_visitor:1305
tools::sg::primitive_visitor::add_point
virtual bool add_point(float, float, float, float)=0
tools::sg::primitive_visitor::add_points_xy
bool add_points_xy(size_t a_floatn, const float *a_xys, bool a_stop=false)
points with x,y only ///////////////////////////////
Definition: primitive_visitor:1636
tools::img::bpp
unsigned int bpp() const
Definition: img:217
tools::img::height
unsigned int height() const
Definition: img:215
tools::vec3::z
const T & z() const
Definition: vec3:86
tools::sg::primitive_visitor::add_triangle_strip_texture_normal
bool add_triangle_strip_texture_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms, unsigned int, const float *)
Definition: primitive_visitor:2032
tools::sg::primitive_visitor::add_line_normal
virtual bool add_line_normal(float, float, float, float, float, float, float, float, float, float, float, float, float, float)=0
tools::img::buffer
const T * buffer() const
Definition: img:218
tools::sg::primitive_visitor::add_points_normal_rgba
bool add_points_normal_rgba(size_t a_floatn, const float *a_xyzs, const float *a_nms, const float *a_rgbas, bool a_stop=false)
Definition: primitive_visitor:1481
tools::sg::primitive_visitor::add_triangle
virtual bool add_triangle(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)=0
tools::sg::primitive_visitor::add_points_xy
bool add_points_xy(const std::vector< float > &a_xys, bool a_stop=false)
Definition: primitive_visitor:1996
tools::is_inside
bool is_inside(const VEC2 &a_P, const std::vector< VEC2 > &a_V)
Definition: geom2:19
tools::vec2::set_value
void set_value(const T &a0, const T &a1)
Definition: vec2:78
tools::sg::primitive_visitor::add_point_normal
virtual bool add_point_normal(float, float, float, float, float, float, float, float, float, float, float)=0
tools::sg::primitive_visitor
Definition: primitive_visitor:20
tools::sg::primitive_visitor::add_triangles
bool add_triangles(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:341
tools::sg::primitive_visitor::add_primitive_xy
bool add_primitive_xy(gl::mode_t a_mode, size_t a_floatn, const float *a_xys, bool a_stop=false, bool a_triangle_revert=false)
Definition: primitive_visitor:1937
tools::sg::primitive_visitor::primitive_visitor
primitive_visitor()
Definition: primitive_visitor:57
tools::sg::primitive_visitor::add_primitive_xy
bool add_primitive_xy(gl::mode_t a_mode, const std::vector< float > &a_xys, bool a_stop=false, bool a_triangle_revert=false)
Definition: primitive_visitor:1970