glVertex  5.5.2
glvertex_nodes.h
Go to the documentation of this file.
1 // (c) by Stefan Roettger, licensed under MIT license
2 
5 #ifndef GLVERTEX_NODES_H
6 #define GLVERTEX_NODES_H
7 
8 #include "vector"
9 
10 #include "glvertex.h"
11 #include "glvertex_cam.h"
12 #include "glvertex_objformat.h"
13 
22 class lgl_Node
23 {
24 public:
25 
27  lgl_Node(const std::string &id = "")
28  : id_(id),
29  enabled_(true),
30  hidden_(false),
31  children_(),
32  refcount_(0),
33  init_(false),
34  updated_(false),
35  visited_(false)
36  {}
37 
39  lgl_Node(const lgl_Node &node)
40  : id_(""),
41  enabled_(true),
42  hidden_(false),
43  children_(node.children_),
44  refcount_(0),
45  init_(false),
46  updated_(false),
47  visited_(false)
48  {
49  for (unsigned int i=0; i<children_.size(); i++)
50  children_[i]->refcount_++;
51  }
52 
54  lgl_Node(lgl_Node *node, const std::string &id = "")
55  : id_(id),
56  enabled_(true),
57  hidden_(false),
58  children_(),
59  refcount_(0),
60  init_(false),
61  updated_(false),
62  visited_(false)
63  {
64  if (node)
65  node->add(this);
66  }
67 
69  virtual ~lgl_Node()
70  {
71  visited_ = true;
72 
73  for (unsigned int i=0; i<children_.size(); i++)
74  {
75  children_[i]->refcount_--;
76  if (children_[i]->refcount_ == 0)
77  if (!children_[i]->visited_) delete children_[i];
78  }
79 
80  if (refcount_ != 0)
81  lglError("deleting node with non-zero reference count");
82  }
83 
85  virtual std::string getClassId() const {return("");}
86 
88  std::string getId() const
89  {
90  return(id_);
91  }
92 
94  void setId(const std::string &id = "")
95  {
96  id_ = id;
97  }
98 
100  std::string getAltId() const
101  {
102  if (id_ != "") return(id_);
103  return(alt_);
104  }
105 
107  void setAltId(const std::string &id = "")
108  {
109  alt_ = id;
110  }
111 
113  unsigned int children() const
114  {
115  return(children_.size());
116  }
117 
119  bool leaf() const
120  {
121  return(children_.size()==0);
122  }
123 
125  unsigned int references() const
126  {
127  return(refcount_);
128  }
129 
131  bool shared() const
132  {
133  return(refcount_>1);
134  }
135 
137  lgl_Node *get(unsigned int i = 0) const
138  {
139  if (i < children_.size())
140  return(children_[i]);
141  else
142  return(NULL);
143  }
144 
145 protected:
146 
149  {
150  children_.push_back(node);
151  node->refcount_++;
152  return(node);
153  }
154 
155 public:
156 
158  template <class T>
159  T *add(T *node)
160  {
161  if (lgl_Node *child=dynamic_cast<lgl_Node*>(node))
162  {
163  add_node(child);
164  return(node);
165  }
166 
167  return(NULL);
168  }
169 
171  void remove(unsigned int i = 0)
172  {
173  unsigned int n = children_.size();
174 
175  if (i < n)
176  {
177  children_[i]->refcount_--;
178  if (children_[i]->refcount_ == 0) delete children_[i];
179 
180  if (n-- > 1)
181  children_[i] = children_[n];
182 
183  children_.resize(n);
184  }
185  }
186 
188  void replace(lgl_Node *node, unsigned int i = 0)
189  {
190  if (i < children_.size())
191  {
192  children_[i]->refcount_--;
193  if (children_[i]->refcount_ == 0) delete children_[i];
194 
195  children_[i] = node;
196  node->refcount_++;
197  }
198  }
199 
201  lgl_Node *take(unsigned int i = 0)
202  {
203  lgl_Node *node = NULL;
204  unsigned int n = children_.size();
205 
206  if (i < n)
207  {
208  children_[i]->refcount_--;
209  if (children_[i]->refcount_ == 0) node = children_[i];
210 
211  if (n-- > 1)
212  children_[i] = children_[n];
213 
214  children_.resize(n);
215  }
216 
217  return(node);
218  }
219 
221  void link(lgl_Node *node)
222  {
223  for (unsigned int i=0; i<node->children(); i++)
224  add(node->get(i));
225  }
226 
228  void unlink()
229  {
230  for (unsigned int i=0; i<children_.size(); i++)
231  {
232  children_[i]->refcount_--;
233  if (children_[i]->refcount_ == 0) delete children_[i];
234  }
235 
236  children_.clear();
237  }
238 
240  virtual bool checkForCycles()
241  {
242  if (visited_)
243  return(true);
244 
245  visited_ = true;
246 
247  for (unsigned int i=0; i<children_.size(); i++)
248  if (follow(i))
249  if (children_[i]->checkForCycles())
250  {
251  visited_ = false;
252  return(true);
253  }
254 
255  visited_ = false;
256 
257  return(false);
258  }
259 
261  bool enabled() const
262  {
263  return(enabled_);
264  }
265 
267  bool disabled() const
268  {
269  return(!enabled_);
270  }
271 
273  void enable(bool yes = true)
274  {
275  enabled_ = yes;
276  }
277 
279  void disable(bool yes = true)
280  {
281  enabled_ = !yes;
282  }
283 
285  void toggle()
286  {
287  enabled_ = !enabled_;
288  }
289 
291  bool shown() const
292  {
293  return(!hidden_);
294  }
295 
297  bool hidden() const
298  {
299  return(hidden_);
300  }
301 
303  void show(bool yes = true)
304  {
305  hidden_ = !yes;
306  }
307 
309  void hide(bool yes = true)
310  {
311  hidden_ = yes;
312  }
313 
315  virtual lgl_Node *find(const std::string &id)
316  {
317  if (id == id_)
318  return(this);
319 
320  for (unsigned int i=0; i<children_.size(); i++)
321  if (follow(i))
322  if (lgl_Node *node=children_[i]->find(id))
323  return(node);
324 
325  return(NULL);
326  }
327 
329  template <class T>
330  T *find()
331  {
332  if (T *node=dynamic_cast<T*>(this))
333  return(node);
334 
335  for (unsigned int i=0; i<children_.size(); i++)
336  if (follow(i))
337  if (T *node=children_[i]->find<T>())
338  return(node);
339 
340  return(NULL);
341  }
342 
344  template <class T>
345  T *find(const std::string &id)
346  {
347  return(dynamic_cast<T*>(find(id)));
348  }
349 
351  void renderSceneGraph(double dt = 0)
352  {
354  drawSceneGraph();
355  updateSceneGraph(dt);
356  }
357 
359  void drawSceneGraph(vec4 color = vec4(1))
360  {
361  lglDepthTest(true);
362  lglBackFaceCulling(false);
363  lglColor(color);
364 
365  lglMatrixMode(LGL_TEXTURE);
366  lglPushMatrix();
367  lglMatrixMode(LGL_MODELVIEW);
368  lglPushMatrix();
369 
370  pre_render();
371  render();
372  post_render();
373 
374  lglMatrixMode(LGL_TEXTURE);
375  lglPopMatrix();
376  lglMatrixMode(LGL_MODELVIEW);
377  lglPopMatrix();
378  }
379 
381  void drawSceneGraph(const mat4 &m)
382  {
383  lglDepthTest(true);
384  lglBackFaceCulling(false);
385  lglColor(1);
386 
387  lglMatrixMode(LGL_TEXTURE);
388  lglPushMatrix();
389  lglMatrixMode(LGL_MODELVIEW);
390  lglPushMatrix();
391 
392  pre_render();
393  lglMultMatrix(m);
394  render();
395  post_render();
396 
397  lglMatrixMode(LGL_TEXTURE);
398  lglPopMatrix();
399  lglMatrixMode(LGL_MODELVIEW);
400  lglPopMatrix();
401  }
402 
404  void preupdateSceneGraph(double dt)
405  {
406  pre_update(dt);
407  }
408 
410  void updateSceneGraph(double dt)
411  {
412  update(dt);
413  }
414 
417  virtual void getBoundingBox(vec3 &bboxmin, vec3 &bboxmax)
418  {
419  pre_init();
420 
421  vec3 bbmin(DBL_MAX), bbmax(-DBL_MAX);
422 
423  if (!hidden_)
424  {
425  for (unsigned int i=0; i<children_.size(); i++)
426  if (follow(i))
427  {
428  vec3 bmin, bmax;
429  children_[i]->getBoundingBox(bmin, bmax);
430 
431  if (bmin.x <= bmax.x &&
432  bmin.y <= bmax.y &&
433  bmin.z <= bmax.z)
434  {
435  growBoundingBox(bbmin, bbmax, bmin);
436  growBoundingBox(bbmin, bbmax, bmax);
437  }
438  }
439 
440  updateBoundingBox(bbmin, bbmax);
441  }
442 
443  bboxmin = bbmin;
444  bboxmax = bbmax;
445  }
446 
447 protected:
448 
449  static void growBoundingBox(vec3 &bboxmin, vec3 &bboxmax, const vec3 &p)
450  {
451  if (p.x < bboxmin.x) bboxmin.x = p.x;
452  if (p.x > bboxmax.x) bboxmax.x = p.x;
453  if (p.y < bboxmin.y) bboxmin.y = p.y;
454  if (p.y > bboxmax.y) bboxmax.y = p.y;
455  if (p.z < bboxmin.z) bboxmin.z = p.z;
456  if (p.z > bboxmax.z) bboxmax.z = p.z;
457  }
458 
459  virtual void updateBoundingBox(vec3 &bboxmin, vec3 &bboxmax) const {}
460 
461 public:
462 
466  double getBoundingSphere(vec3 &center)
467  {
468  vec3 bbmin, bbmax;
469  getBoundingBox(bbmin, bbmax);
470 
471  if (bbmin.x <= bbmax.x &&
472  bbmin.y <= bbmax.y &&
473  bbmin.z <= bbmax.z)
474  {
475  center = 0.5*(bbmax+bbmin);
476  return((0.5*(bbmax-bbmin)).length());
477  }
478 
479  return(0);
480  }
481 
484  {
485  vec3 bbmin, bbmax;
486  getBoundingBox(bbmin, bbmax);
487 
488  if (bbmin.x <= bbmax.x &&
489  bbmin.y <= bbmax.y &&
490  bbmin.z <= bbmax.z)
491  return(0.5*(bbmax+bbmin));
492 
493  return(0);
494  }
495 
498  {
499  vec3 bbmin, bbmax;
500  getBoundingBox(bbmin, bbmax);
501 
502  if (bbmin.x <= bbmax.x &&
503  bbmin.y <= bbmax.y &&
504  bbmin.z <= bbmax.z)
505  return(bbmax-bbmin);
506 
507  return(vec3(0,0,0));
508  }
509 
512  double getRadius()
513  {
514  vec3 bbmin, bbmax;
515  getBoundingBox(bbmin, bbmax);
516 
517  if (bbmin.x <= bbmax.x &&
518  bbmin.y <= bbmax.y &&
519  bbmin.z <= bbmax.z)
520  return((0.5*(bbmax-bbmin)).length());
521 
522  return(0);
523  }
524 
527  double getNorm()
528  {
529  vec3 bbmin, bbmax;
530  getBoundingBox(bbmin, bbmax);
531 
532  if (bbmin.x <= bbmax.x &&
533  bbmin.y <= bbmax.y &&
534  bbmin.z <= bbmax.z)
535  return((0.5*(bbmax-bbmin)).norm());
536 
537  return(0);
538  }
539 
540  // return a copy of the transformed vertex coordinates of the entire subgraph
542  virtual std::vector<vec4> getVertexCoordinates(mat4 trans = mat4())
543  {
544  pre_init();
545 
546  std::vector<vec4> geometry = get_vertices();
547 
548  trans = update_transform(trans);
549 
550  for (unsigned int i=0; i<geometry.size(); i++)
551  geometry[i] = trans * geometry[i];
552 
553  for (unsigned int i=0; i<children_.size(); i++)
554  if (follow(i))
555  {
556  std::vector<vec4> geo = children_[i]->getVertexCoordinates(trans);
557  geometry.insert(geometry.end(), geo.begin(), geo.end());
558  }
559 
560  return(geometry);
561  }
562 
565  void getExactBoundingBox(vec3 &bboxmin, vec3 &bboxmax)
566  {
567  vec3 bbmin(DBL_MAX), bbmax(-DBL_MAX);
568 
569  std::vector<vec4> geometry = getVertexCoordinates();
570 
571  for (unsigned int i=0; i<geometry.size(); i++)
572  growBoundingBox(bbmin, bbmax, geometry[i]);
573 
574  bboxmin = bbmin;
575  bboxmax = bbmax;
576  }
577 
578  // save the colored and transformed vbos of the entire subgraph
579  virtual bool saveSceneGraph(vec4 color, mat4 trans, FILE *file, int &index, int &nindex, int &tindex)
580  {
581  pre_init();
582 
583  bool ok = true;
584 
585  lglVBO *vbo = get_vbo();
586 
587  color = update_color(color);
588  trans = update_transform(trans);
589 
590  if (vbo)
591  {
592  lglVBO copy;
593  vbo->lglAppendVerticesTo(&copy);
594  if (!vbo->lglAppliedColoring()) copy.lglApplyColor(color);
595  copy.lglModel(trans);
596  copy.lglApplyModelMatrix();
597 
598  fprintf(file, "#");
599  if (vbo->getName() != "") fprintf(file, " name=%s", vbo->getName().c_str());
600  fprintf(file, " vertices=%d", vbo->lglGetVertexCount());
601  fprintf(file, " primitives=%d\n", vbo->lglGetPrimitiveCount());
602 
603  if (!lglSaveObjInto(&copy, file, index, nindex, tindex)) ok = false;
604  }
605 
606  for (unsigned int i=0; i<children_.size(); i++)
607  if (follow(i))
608  if (!children_[i]->saveSceneGraph(color, trans, file, index, nindex, tindex)) ok = false;
609 
610  return(ok);
611  }
612 
614  lglVBO *pickSceneGraph(vec3 origin, vec3 direction, double mindist = 0)
615  {
616  pre_init();
617 
618  lglBeginRayCast(origin, direction, mindist);
619  pre_pick();
620  pick();
621  post_pick();
622  lglVBO *vbo = dynamic_cast<lglVBO*>(lglEndRayCast());
623 
624  return(vbo);
625  }
626 
629  {
630  if (transparency()) return(true);
631 
632  for (unsigned int i=0; i<children_.size(); i++)
633  if (follow(i))
634  if (children_[i]->hasTransparency())
635  return(true);
636 
637  return(false);
638  }
639 
641  virtual unsigned int countAll()
642  {
643  unsigned int count = 1;
644 
645  for (unsigned int i=0; i<children_.size(); i++)
646  if (follow(i))
647  count += children_[i]->countAll();
648 
649  return(count);
650  }
651 
653  virtual unsigned int countAllOnce()
654  {
655  unsigned int count;
656 
657  count = countOnce();
658  cleanAll();
659 
660  return(count);
661  }
662 
664  virtual unsigned int countAllPrimitives()
665  {
666  pre_init();
667 
668  unsigned int count = 0;
669 
670  if (lglVBO *vbo = get_vbo())
671  count += vbo->lglGetPrimitiveCount();
672 
673  for (unsigned int i=0; i<children_.size(); i++)
674  if (follow(i))
675  count += children_[i]->countAllPrimitives();
676 
677  return(count);
678  }
679 
681  unsigned int countAllVertices()
682  {
683  pre_init();
684 
685  unsigned int count = 0;
686 
687  if (lglVBO *vbo = get_vbo())
688  count += vbo->lglGetVertexCount();
689 
690  for (unsigned int i=0; i<children_.size(); i++)
691  if (follow(i))
692  count += children_[i]->countAllVertices();
693 
694  return(count);
695  }
696 
697 protected:
698 
699  virtual void cleanAll()
700  {
701  visited_ = false;
702 
703  for (unsigned int i=0; i<children_.size(); i++)
704  if (follow(i))
705  children_[i]->cleanAll();
706  }
707 
708  virtual unsigned int countOnce()
709  {
710  if (visited_)
711  return(0);
712 
713  visited_ = true;
714 
715  unsigned int count = 1;
716 
717  for (unsigned int i=0; i<children_.size(); i++)
718  if (follow(i))
719  count += children_[i]->countOnce();
720 
721  return(count);
722  }
723 
724 public:
725 
727  virtual bool stateless() const
728  {
729  return(true);
730  }
731 
733  virtual bool ordered() const
734  {
735  return(false);
736  }
737 
739  bool convertable() const
740  {
741  return(!shared());
742  }
743 
745  bool cloneable() const
746  {
747  return(leaf() && getId()=="");
748  }
749 
751  bool optimizable() const
752  {
753  return(!shared() && getId()=="");
754  }
755 
757  virtual void optimizeAll();
758 
759 protected:
760 
761  virtual lgl_Node *convert() {return(NULL);}
762  virtual lgl_Node *clone() {return(NULL);}
763  virtual bool optimize() {return(false);}
764  virtual bool swappable() {return(false);}
765 
766 public:
767 
769  virtual void restartAll(double animation = 0)
770  {
771  for (unsigned int i=0; i<children_.size(); i++)
772  if (follow(i))
773  children_[i]->restartAll(animation);
774  }
775 
777  virtual void pauseAll(bool yes = true)
778  {
779  for (unsigned int i=0; i<children_.size(); i++)
780  if (follow(i))
781  children_[i]->pauseAll(yes);
782  }
783 
785  virtual void speedupAll(double speedup = 1)
786  {
787  for (unsigned int i=0; i<children_.size(); i++)
788  if (follow(i))
789  children_[i]->speedupAll(speedup);
790  }
791 
793  virtual void finishAll()
794  {
795  finish();
796 
797  for (unsigned int i=0; i<children_.size(); i++)
798  if (follow(i))
799  children_[i]->finishAll();
800  }
801 
803  static GL *getGL()
804  {
805  static GL gl;
806  return(&gl);
807  }
808 
811  {
812  LGL_EXPORT_NODES,
813  LGL_EXPORT_COMMANDS,
814  LGL_EXPORT_GRAPH
815  };
816 
818  std::string exportAll(lgl_export_enum mode = LGL_EXPORT_NODES, int indentation = 0, int increment = 3);
819 
821  void exportNodes(std::string filename);
822 
824  void exportGraph(std::string filename);
825 
827  void exportCommands(std::string filename);
828 
830  bool saveObj(std::string filename)
831  {
832  bool ok = false;
833 
834  FILE *file = fopen(filename.c_str(), "wb");
835 
836  if (file)
837  {
838  fprintf(file, "# glVertex OBJ File\n\n");
839 
840  int index = 1;
841  int nindex = 1;
842  int tindex = 1;
843 
844  if (saveSceneGraph(vec4(1,1,1), mat4(), file, index, nindex, tindex)) ok = true;
845 
846  fclose(file);
847  }
848 
849  return(ok);
850  }
851 
852 protected:
853 
854  std::string id_, alt_;
855  bool enabled_, hidden_;
856 
857  std::vector<lgl_Node*> children_;
858  unsigned int refcount_;
859  bool init_, updated_;
860 
861  virtual bool follow(unsigned int i) const
862  {
863  return(i < children_.size());
864  }
865 
866  virtual void init() {}
867 
868  virtual void pre_init()
869  {
870  if (!init_)
871  {
872  init();
873  init_ = true;
874  }
875  }
876 
877  virtual void pre_update(double dt)
878  {
879  if (!init_)
880  {
881  init();
882  init_ = true;
883  }
884 
885  for (unsigned int i=0; i<children_.size(); i++)
886  if (follow(i))
887  children_[i]->pre_update(dt);
888 
889  updated_ = false;
890  }
891 
892  virtual void pre_render()
893  {
894  if (!init_)
895  {
896  init();
897  init_ = true;
898  }
899 
900  for (unsigned int i=0; i<children_.size(); i++)
901  if (follow(i))
902  children_[i]->pre_render();
903  }
904 
906  virtual void render()
907  {
908  if (hidden_) return;
909 
910  for (unsigned int i=0; i<children_.size(); i++)
911  if (follow(i))
912  children_[i]->render();
913  }
914 
915  virtual void render(unsigned int i)
916  {
917  if (hidden_) return;
918 
919  if (follow(i))
920  children_[i]->render();
921  }
922 
923  virtual void post_render()
924  {
925  for (unsigned int i=0; i<children_.size(); i++)
926  if (follow(i))
927  children_[i]->post_render();
928  }
929 
931  virtual void update(double dt)
932  {
933  for (unsigned int i=0; i<children_.size(); i++)
934  if (follow(i))
935  if (!children_[i]->updated_)
936  children_[i]->update(dt);
937 
938  updated_ = true;
939  }
940 
941  virtual void update(unsigned int i, double dt)
942  {
943  if (follow(i))
944  if (!children_[i]->updated_)
945  children_[i]->update(dt);
946 
947  updated_ = true;
948  }
949 
950  virtual void finish() {}
951 
952  virtual std::vector<vec4> get_vertices()
953  {
954  return(std::vector<vec4>());
955  }
956 
957  virtual lglVBO *get_vbo() {return(NULL);}
958  virtual vec4 update_color(vec4 c) {return(c);}
959  virtual mat4 update_transform(mat4 m) {return(m);}
960 
961  virtual void pre_pick()
962  {
963  if (!init_)
964  {
965  init();
966  init_ = true;
967  }
968 
969  for (unsigned int i=0; i<children_.size(); i++)
970  if (follow(i))
971  children_[i]->pre_pick();
972  }
973 
975  virtual void pick()
976  {
977  if (hidden_) return;
978 
979  for (unsigned int i=0; i<children_.size(); i++)
980  if (follow(i))
981  children_[i]->pick();
982  }
983 
984  virtual void pick(unsigned int i)
985  {
986  if (hidden_) return;
987 
988  if (follow(i))
989  children_[i]->pick();
990  }
991 
992  virtual void post_pick()
993  {
994  for (unsigned int i=0; i<children_.size(); i++)
995  if (follow(i))
996  children_[i]->post_pick();
997  }
998 
999  virtual bool transparency()
1000  {
1001  return(false);
1002  }
1003 
1004 public:
1005 
1006  virtual std::string to_id(const std::string &classid, bool classname = true) const
1007  {
1008  std::stringstream s;
1009 
1010  if (classname)
1011  s << "lgl_" << classid << "Node";
1012  else
1013  s << lgl_string(classid).toLower();
1014 
1015  if (classname)
1016  if (getId()!="" || disabled() || hidden())
1017  {
1018  s << "(";
1019 
1020  if (getId() != "")
1021  s << "\"" << getId() << "\"";
1022 
1023  if (disabled())
1024  {
1025  if (getId() != "")
1026  s << ", ";
1027 
1028  s << "disabled";
1029  }
1030 
1031  if (hidden())
1032  {
1033  if (getId() != "" || disabled())
1034  s << ", ";
1035 
1036  s << "hidden";
1037  }
1038 
1039  s << ")";
1040  }
1041 
1042  return(s.str());
1043  }
1044 
1045  virtual std::string to_string(bool classname = true) const
1046  {
1047  return(to_id(getClassId(), classname));
1048  }
1049 
1050  virtual std::string to_label() const
1051  {
1052  return(getId());
1053  }
1054 
1055 protected:
1056 
1057  bool visited_;
1058 
1059  void init_export(lgl_export_enum mode);
1060  void scan_export(unsigned int &id, lgl_export_enum mode);
1061  std::string pre_export(lgl_export_enum mode);
1062  std::string export_to_string(int indentation, int increment, lgl_export_enum mode);
1063  std::string post_export(lgl_export_enum mode);
1064  void clean_export(lgl_export_enum mode);
1065 
1066  friend class lgl_SubgraphNode;
1067 };
1068 
1070 {
1071 #ifndef LGL_DO_NOT_OPTIMIZE
1072 
1073  // recursively optimize children
1074  for (unsigned int i=0; i<children_.size(); i++)
1075  if (follow(i))
1076  children_[i]->optimizeAll();
1077 
1078  // replace children by converting or cloning them
1079  for (unsigned int i=0; i<children_.size(); i++)
1080  if (follow(i))
1081  {
1082  lgl_Node *node = get(i);
1083 
1084  if (node->convertable())
1085  {
1086  if (lgl_Node *converted = node->convert())
1087  {
1088  converted->setId(node->getId());
1089 
1090  link(node);
1091  replace(converted, i);
1092  }
1093  }
1094  else if (node->cloneable())
1095  {
1096  if (lgl_Node *cloned = node->clone())
1097  replace(cloned, i);
1098  }
1099  }
1100 
1101  // optimize children by removing them
1102  for (unsigned int i=0; i<children_.size(); i++)
1103  if (follow(i))
1104  {
1105  lgl_Node *node = get(i);
1106 
1107  if (node->optimizable())
1108  {
1109  if (node->optimize())
1110  {
1111  link(node);
1112  remove(i);
1113  }
1114  }
1115  }
1116 
1117  // optimize children by swapping them
1118  for (unsigned int i=0; i<children_.size(); i++)
1119  if (follow(i))
1120  {
1121  lgl_Node *node = get(i);
1122 
1123  if (node->swappable())
1124  if (node->children() == 1)
1125  if (!node->shared() && !node->get()->shared())
1126  {
1127  lgl_Node *node1 = take(i);
1128  lgl_Node *node2 = node1->take();
1129  node1->link(node2);
1130  node2->unlink();
1131  node2->add(node1);
1132  add(node2);
1133  }
1134  }
1135 
1136  // optimize unordered children by merging stateless unshared leaf nodes
1137  if (!ordered())
1138  {
1139  int mergeable = 0;
1140 
1141  for (unsigned int i=0; i<children_.size(); i++)
1142  if (follow(i))
1143  {
1144  lgl_Node *node = get(i);
1145 
1146  if (node->stateless() && node->leaf() && !node->shared())
1147  mergeable++;
1148  }
1149 
1150  if (mergeable > 1)
1151  {
1152  std::vector<lgl_Node*> trail;
1153 
1154  unsigned int i=0;
1155  while (i < children_.size())
1156  {
1157  if (follow(i))
1158  {
1159  lgl_Node *node = get(i);
1160 
1161  if (node->stateless() && node->leaf() && !node->shared())
1162  {
1163  trail.push_back(take(i));
1164  continue;
1165  }
1166 
1167  i++;
1168  }
1169  }
1170 
1171  if (trail.size() > 0)
1172  {
1173  lgl_Node *link = this;
1174  while (trail.size() > 0)
1175  {
1176  lgl_Node *node = trail.back();
1177  trail.pop_back();
1178 
1179  link->add(node);
1180  link = node;
1181  }
1182 
1183  optimizeAll();
1184  }
1185  }
1186  }
1187 
1188 #endif
1189 }
1190 
1192 inline std::ostream& operator << (std::ostream &out, const lgl_Node &node)
1193  {return(out << node.to_string());}
1194 
1205 {
1206 public:
1207 
1210  {
1211  LGL_CONTROL_NONE,
1212  LGL_CONTROL_ON,
1213  LGL_CONTROL_OFF,
1214  LGL_CONTROL_ENABLE,
1215  LGL_CONTROL_DISABLE,
1216  LGL_CONTROL_INVERT,
1217  LGL_CONTROL_HIDE,
1218  LGL_CONTROL_SHOW,
1219  LGL_CONTROL_TOGGLE,
1220  LGL_CONTROL_RESTART_ALL,
1221  LGL_CONTROL_PAUSE_ALL
1222  };
1223 
1225  lgl_ControllableNode(const std::string &id = "",
1226  lgl_Node *node = NULL)
1227  : lgl_Node(node, id),
1228  control_mode_(LGL_CONTROL_NONE),
1229  delayed_signal_(false),
1230  delayed_override_(false)
1231  {}
1232 
1233  virtual ~lgl_ControllableNode() {}
1234 
1235  virtual std::string getClassId() const {return("Controllable");}
1236 
1238  virtual void control(bool override = true)
1239  {
1240  switch (getControlMode())
1241  {
1242  case LGL_CONTROL_NONE: break;
1243  case LGL_CONTROL_ON: enable(); break;
1244  case LGL_CONTROL_OFF: disable(); break;
1245  case LGL_CONTROL_ENABLE: enable(override); break;
1246  case LGL_CONTROL_DISABLE: disable(override); break;
1247  case LGL_CONTROL_INVERT: if (override) disable(enabled()); break;
1248  case LGL_CONTROL_HIDE: hide(override); break;
1249  case LGL_CONTROL_SHOW: show(override); break;
1250  case LGL_CONTROL_TOGGLE: if (override) hide(shown()); break;
1251  case LGL_CONTROL_RESTART_ALL: if (override) restartAll(); break;
1252  case LGL_CONTROL_PAUSE_ALL: pauseAll(override); break;
1253  }
1254  }
1255 
1258  {
1259  return(control_mode_);
1260  }
1261 
1264  {
1265  control_mode_ = mode;
1266  }
1267 
1268  virtual bool stateless() const
1269  {
1270  return(false);
1271  }
1272 
1273 protected:
1274 
1275  lgl_control_mode_enum control_mode_;
1276 
1277  bool delayed_signal_;
1278  bool delayed_override_;
1279 
1280  virtual void pre_update(double dt)
1281  {
1282  if (dt != 0)
1283  if (delayed_signal_)
1284  {
1285  signal(delayed_override_);
1286  delayed_signal_ = false;
1287  }
1288 
1289  lgl_Node::pre_update(dt);
1290  }
1291 
1292  virtual void signal(bool override = true);
1293 
1294  void signal_delayed(bool override = true)
1295  {
1296  delayed_signal_ = true;
1297  delayed_override_ = override;
1298  }
1299 
1300 public:
1301 
1302  virtual std::string to_id(const std::string &classid, bool classname = true) const
1303  {
1304  std::stringstream s;
1305 
1306  if (classname)
1307  s << lgl_Node::to_id(classid, classname);
1308  else
1309  {
1310  if (classid != lgl_ControllableNode::getClassId())
1311  s << lgl_Node::to_id(classid, classname);
1312  }
1313 
1314  if (classname)
1315  if (getControlMode() != LGL_CONTROL_NONE)
1316  {
1317  s << "(";
1318 
1319  switch (getControlMode())
1320  {
1321  case LGL_CONTROL_NONE: s << "none"; break;
1322  case LGL_CONTROL_ON: s << "on"; break;
1323  case LGL_CONTROL_OFF: s << "off"; break;
1324  case LGL_CONTROL_ENABLE: s << "enable"; break;
1325  case LGL_CONTROL_DISABLE: s << "disable"; break;
1326  case LGL_CONTROL_INVERT: s << "invert"; break;
1327  case LGL_CONTROL_HIDE: s << "hide"; break;
1328  case LGL_CONTROL_SHOW: s << "show"; break;
1329  case LGL_CONTROL_TOGGLE: s << "toggle"; break;
1330  case LGL_CONTROL_RESTART_ALL: s << "restart-all"; break;
1331  case LGL_CONTROL_PAUSE_ALL: s << "pause-all"; break;
1332  }
1333 
1334  s << ")";
1335  }
1336 
1337  return(s.str());
1338  }
1339 
1340  virtual std::string to_label() const
1341  {
1342  lgl_string label = lgl_Node::to_label();
1343 
1344  switch (getControlMode())
1345  {
1346  case LGL_CONTROL_ON: label += "\\non"; break;
1347  case LGL_CONTROL_OFF: label += "\\noff"; break;
1348  case LGL_CONTROL_ENABLE: label += "\\nenable"; break;
1349  case LGL_CONTROL_DISABLE: label += "\\ndisable"; break;
1350  case LGL_CONTROL_INVERT: label += "\\ninvert"; break;
1351  case LGL_CONTROL_HIDE: label += "\\nhide"; break;
1352  case LGL_CONTROL_SHOW: label += "\\nshow"; break;
1353  case LGL_CONTROL_TOGGLE: label += "\\ntoggle"; break;
1354  case LGL_CONTROL_RESTART_ALL: label += "\\nrestart-all"; break;
1355  case LGL_CONTROL_PAUSE_ALL: label += "\\npause-all"; break;
1356  default: break;
1357  }
1358 
1359  return(label.strip("\\n"));
1360  }
1361 
1362 };
1363 
1371 {
1372 public:
1373 
1376  {
1377  LGL_ACTION_NONE,
1378  LGL_ACTION_ON,
1379  LGL_ACTION_OFF,
1380  LGL_ACTION_ENABLE,
1381  LGL_ACTION_DISABLE,
1382  LGL_ACTION_HIDE,
1383  LGL_ACTION_SHOW,
1384  LGL_ACTION_PAUSE,
1385  LGL_ACTION_RESUME,
1386  LGL_ACTION_DIRECTION
1387  };
1388 
1390  lgl_ActionNode(const std::string &id = "",
1391  lgl_Node *node = NULL)
1392  : lgl_ControllableNode(id, node)
1393  {}
1394 
1395  virtual ~lgl_ActionNode() {}
1396 
1397  virtual std::string getClassId() const {return("Action");}
1398 
1400  virtual void control(bool override = true)
1401  {
1402  trigger_children(override);
1403  }
1404 
1407  {
1408  return(action_mode_);
1409  }
1410 
1413  {
1414  action_mode_ = mode;
1415  }
1416 
1417 protected:
1418 
1419  lgl_action_mode_enum action_mode_;
1420 
1421  virtual bool follow(unsigned int i) const
1422  {
1423  return(false);
1424  }
1425 
1426  virtual void trigger_children(bool override = true);
1427 
1428 public:
1429 
1430  virtual std::string to_string(bool classname = true) const
1431  {
1432  std::stringstream s;
1433 
1434  s << lgl_ControllableNode::to_string(classname);
1435 
1436  if (classname)
1437  if (getActionMode() != LGL_ACTION_NONE)
1438  {
1439  s << "(";
1440 
1441  switch (getActionMode())
1442  {
1443  case LGL_ACTION_NONE: s << "none"; break;
1444  case LGL_ACTION_ON: s << "on"; break;
1445  case LGL_ACTION_OFF: s << "off"; break;
1446  case LGL_ACTION_ENABLE: s << "enable"; break;
1447  case LGL_ACTION_DISABLE: s << "disable"; break;
1448  case LGL_ACTION_HIDE: s << "hide"; break;
1449  case LGL_ACTION_SHOW: s << "show"; break;
1450  case LGL_ACTION_PAUSE: s << "pause"; break;
1451  case LGL_ACTION_RESUME: s << "resume"; break;
1452  case LGL_ACTION_DIRECTION: s << "direction"; break;
1453  }
1454 
1455  s << ")";
1456  }
1457 
1458  return(s.str());
1459  }
1460 
1461  virtual std::string to_label() const
1462  {
1463  lgl_string label = lgl_ControllableNode::to_label();
1464 
1465  switch (getActionMode())
1466  {
1467  case LGL_ACTION_ON: label += "\\non"; break;
1468  case LGL_ACTION_OFF: label += "\\noff"; break;
1469  case LGL_ACTION_ENABLE: label += "\\nenable"; break;
1470  case LGL_ACTION_DISABLE: label += "\\ndisable"; break;
1471  case LGL_ACTION_HIDE: label += "\\nhide"; break;
1472  case LGL_ACTION_SHOW: label += "\\nshow"; break;
1473  case LGL_ACTION_PAUSE: label += "\\npause"; break;
1474  case LGL_ACTION_RESUME: label += "\\nresume"; break;
1475  case LGL_ACTION_DIRECTION: label += "\\ndirection"; break;
1476  default: break;
1477  }
1478 
1479  return(label.strip("\\n"));
1480  }
1481 
1482 };
1483 
1496 {
1497 public:
1498 
1500  lgl_ControlNode(const std::string &id = "",
1501  lgl_Node *node = NULL)
1502  : lgl_ControllableNode(id, node),
1503  delay_(0), countdown_(0),
1504  override_(true)
1505  {}
1506 
1507  virtual ~lgl_ControlNode() {}
1508 
1509  virtual std::string getClassId() const {return("Control");}
1510 
1512  virtual void control(bool override = true)
1513  {
1514  if (delay_ > 0)
1515  {
1516  countdown_ = delay_;
1517  override_ = override;
1518  }
1519  else
1520  control_children(override);
1521  }
1522 
1524  void setControlDelay(double delay)
1525  {
1526  delay_ = delay;
1527  }
1528 
1530  double getControlDelay() const
1531  {
1532  return(delay_);
1533  }
1534 
1536  virtual void finish()
1537  {
1538  if (countdown_ > 0)
1539  {
1540  countdown_ = 0;
1541  control_children(override_);
1542  }
1543  }
1544 
1545 protected:
1546 
1547  double delay_;
1548  double countdown_;
1549  bool override_;
1550 
1551  virtual bool follow(unsigned int i) const
1552  {
1553  if (i >= children_.size()) return(false);
1554  if (dynamic_cast<const lgl_ControlNode *>(get(i))) return(true);
1555  if (dynamic_cast<const lgl_ActionNode *>(get(i))) return(true);
1556  return(false);
1557  }
1558 
1559  virtual void control_children(bool override = true)
1560  {
1561  if (enabled_)
1562  {
1563  switch (getControlMode())
1564  {
1565  case LGL_CONTROL_NONE: break;
1566  case LGL_CONTROL_ON: override = true; break;
1567  case LGL_CONTROL_OFF: override = false; break;
1568  case LGL_CONTROL_ENABLE: override = true; break;
1569  case LGL_CONTROL_DISABLE: override = false; break;
1570  case LGL_CONTROL_INVERT: override = !override; break;
1571  default: return;
1572  }
1573 
1574  for (unsigned int i=0; i<children_.size(); i++)
1575  {
1576  if (lgl_ControlNode *ctrl=dynamic_cast<lgl_ControlNode*>(children_[i]))
1577  ctrl->control(override);
1578  else if (lgl_ControllableNode *ctrl=dynamic_cast<lgl_ControllableNode*>(children_[i]))
1579  control(ctrl, override);
1580  }
1581  }
1582  }
1583 
1585  virtual void control(lgl_ControllableNode *ctrl, bool override)
1586  {
1587  ctrl->control(override);
1588  }
1589 
1590  virtual void pre_update(double dt)
1591  {
1592  if (dt == 0)
1593  finish();
1594 
1595  lgl_Node::pre_update(dt);
1596  }
1597 
1598  virtual void update(double dt)
1599  {
1600  if (countdown_ > 0)
1601  {
1602  countdown_ -= dt;
1603 
1604  if (countdown_ <= 0)
1605  control_children(override_);
1606  }
1607 
1608  lgl_Node::update(dt);
1609  }
1610 
1611 public:
1612 
1613  virtual std::string to_string(bool classname = true) const
1614  {
1615  std::stringstream s;
1616 
1617  s << lgl_ControllableNode::to_string(classname);
1618 
1619  if (classname)
1620  if (getControlDelay() != 0)
1621  s << "(" << getControlDelay() << ")";
1622 
1623  return(s.str());
1624  }
1625 
1626  virtual std::string to_label() const
1627  {
1628  lgl_string label = lgl_ControllableNode::to_label();
1629 
1630  if (getControlDelay() != 0)
1631  label += "\\ndelay=" + glslmath::to_string(getControlDelay());
1632 
1633  return(label.strip("\\n"));
1634  }
1635 
1636 };
1637 
1638 inline void lgl_ControllableNode::signal(bool override)
1639 {
1640  for (unsigned int i=0; i<children_.size(); i++)
1641  if (lgl_ControlNode *ctrl=dynamic_cast<lgl_ControlNode*>(children_[i]))
1642  ctrl->control(override);
1643 }
1644 
1650 {
1651 public:
1652 
1654  lgl_BarrierNode(const std::string &id = "",
1655  lgl_Node *node = NULL)
1656  : lgl_ControllableNode(id, node),
1657  restart_all_barrier_(false),
1658  pause_all_barrier_(false),
1659  resume_all_barrier_(false),
1660  speedup_all_barrier_(false)
1661  {}
1662 
1663  virtual ~lgl_BarrierNode() {}
1664 
1665  virtual std::string getClassId() const {return("Barrier");}
1666 
1668  bool getRestartBarrier() const
1669  {
1670  return(restart_all_barrier_);
1671  }
1672 
1674  void setRestartBarrier(bool yes = false)
1675  {
1676  restart_all_barrier_ = yes;
1677  }
1678 
1680  bool getPauseBarrier() const
1681  {
1682  return(pause_all_barrier_);
1683  }
1684 
1686  void setPauseBarrier(bool yes = false)
1687  {
1688  pause_all_barrier_ = yes;
1689  }
1690 
1692  bool getResumeBarrier() const
1693  {
1694  return(resume_all_barrier_);
1695  }
1696 
1698  void setResumeBarrier(bool yes = false)
1699  {
1700  resume_all_barrier_ = yes;
1701  }
1702 
1704  bool getSpeedupBarrier() const
1705  {
1706  return(speedup_all_barrier_);
1707  }
1708 
1710  void setSpeedupBarrier(bool yes = false)
1711  {
1712  speedup_all_barrier_ = yes;
1713  }
1714 
1715  virtual void restartAll(double animation = 0)
1716  {
1717  if (!enabled_ || !restart_all_barrier_)
1718  lgl_Node::restartAll(animation);
1719  }
1720 
1721  virtual void pauseAll(bool yes = true)
1722  {
1723  if (yes)
1724  {
1725  if (!enabled_ || !pause_all_barrier_)
1726  lgl_Node::pauseAll(true);
1727  }
1728  else
1729  {
1730  if (!enabled_ || !resume_all_barrier_)
1731  lgl_Node::pauseAll(false);
1732  }
1733  }
1734 
1735  virtual void speedupAll(double speedup = 1)
1736  {
1737  if (!enabled_ || !speedup_all_barrier_)
1738  lgl_Node::speedupAll(speedup);
1739  }
1740 
1741 protected:
1742 
1743  bool restart_all_barrier_;
1744  bool pause_all_barrier_;
1745  bool resume_all_barrier_;
1746  bool speedup_all_barrier_;
1747 
1748 public:
1749 
1750  virtual std::string to_string(bool classname = true) const
1751  {
1752  std::stringstream s;
1753 
1754  if (classname)
1755  {
1756  s << lgl_ControllableNode::to_string(classname);
1757 
1758  s << "(";
1759  s << (getRestartBarrier()?"on":"off") << ", ";
1760  s << (getPauseBarrier()?"on":"off") << ", ";
1761  s << (getResumeBarrier()?"on":"off") << ", ";
1762  s << (getSpeedupBarrier()?"on":"off");
1763  s << ")";
1764  }
1765  else
1766  {
1768  s << lgl_ControllableNode::to_string(classname);
1769  }
1770 
1771  return(s.str());
1772  }
1773 
1774  virtual std::string to_label() const
1775  {
1776  lgl_string label = lgl_ControllableNode::to_label();
1777 
1778  if (getRestartBarrier() ||
1779  getPauseBarrier() ||
1780  getResumeBarrier() ||
1782  {
1783  std::string barrier = "\\nblock:";
1784  if (getRestartBarrier()) barrier += " restart";
1785  if (getPauseBarrier()) barrier += " pause";
1786  if (getResumeBarrier()) barrier += " resume";
1787  if (getSpeedupBarrier()) barrier += " speedup";
1788  label += barrier;
1789  }
1790 
1791  return(label.strip("\\n"));
1792  }
1793 
1794 };
1795 
1801 {
1802 public:
1803 
1805  lgl_SteerableNode(const std::string &id = "",
1806  lgl_Node *node = NULL)
1807  : lgl_ControllableNode(id, node)
1808  {}
1809 
1810  virtual ~lgl_SteerableNode() {}
1811 
1812  virtual std::string getClassId() const {return("Steerable");}
1813 
1815  virtual void steer(double level, bool override = true) {}
1816 
1817  virtual std::string to_id(const std::string &classid, bool classname = true) const
1818  {
1819  std::stringstream s;
1820 
1821  if (classname)
1822  s << lgl_ControllableNode::to_id(classid, classname);
1823  else
1824  {
1825  if (classid != lgl_SteerableNode::getClassId())
1826  s << lgl_ControllableNode::to_id(classid, classname);
1827  }
1828 
1829  return(s.str());
1830  }
1831 
1832 };
1833 
1840 {
1841 public:
1842 
1844  lgl_SteerNode(const std::string &id = "",
1845  lgl_Node *node = NULL)
1846  : lgl_ControlNode(id, node),
1847  level_(0)
1848  {}
1849 
1850  virtual ~lgl_SteerNode() {}
1851 
1852  virtual std::string getClassId() const {return("Steer");}
1853 
1855  double getSteerLevel() const
1856  {
1857  return(level_);
1858  }
1859 
1861  void setSteerLevel(double level)
1862  {
1863  level_ = level;
1864  }
1865 
1866 protected:
1867 
1868  double level_;
1869 
1870  virtual void control(lgl_ControllableNode *ctrl, bool override)
1871  {
1872  lgl_ControlNode::control(ctrl, override);
1873 
1874  lgl_SteerableNode *node = dynamic_cast<lgl_SteerableNode*>(ctrl);
1875  if (node) node->steer(level_, override);
1876  }
1877 
1878 public:
1879 
1880  virtual std::string to_string(bool classname = true) const
1881  {
1882  std::stringstream s;
1883 
1884  s << lgl_ControlNode::to_string(classname);
1885 
1886  if (classname)
1887  if (getSteerLevel() != 0)
1888  s << "(" << getSteerLevel() << ")";
1889 
1890  return(s.str());
1891  }
1892 
1893  virtual std::string to_label() const
1894  {
1895  lgl_string label = lgl_ControlNode::to_label();
1896 
1897  if (getSteerLevel() != 0)
1898  label += "\\nlevel=" + glslmath::to_string(getSteerLevel());
1899 
1900  return(label.strip("\\n"));
1901  }
1902 
1903 };
1904 
1915 {
1916 public:
1917 
1918  lgl_CameraNode(const std::string &id = "",
1919  lgl_Node *node = NULL)
1920  : lgl_ControllableNode(id, node),
1921  lgl_Cam()
1922  {}
1923 
1924  virtual ~lgl_CameraNode() {}
1925 
1926  virtual std::string getClassId() const {return("Camera");}
1927 
1928 protected:
1929 
1930  virtual void pre_render()
1931  {
1932  lgl_Node::pre_render();
1933  if (enabled_) begin();
1934  }
1935 
1936  virtual void post_render()
1937  {
1938  if (enabled_) end();
1939  lgl_Node::post_render();
1940  }
1941 
1942  virtual void pre_pick()
1943  {
1944  lgl_Node::pre_pick();
1945  if (enabled_) begin();
1946  }
1947 
1948  virtual void post_pick()
1949  {
1950  if (enabled_) end();
1951  lgl_Node::post_pick();
1952  }
1953 
1954 public:
1955 
1956  virtual std::string to_string(bool classname = true) const
1957  {
1958  mat4 p = getProjectionMatrix();
1959  mat4 m = getViewMatrix();
1960 
1961  if (lglIsManipApplied())
1962  m <<= lglGetManip();
1963 
1964  std::stringstream s;
1965 
1966  s << lgl_ControllableNode::to_string(classname);
1967  s << "(mat4" << p << ", mat4" << m << ")";
1968 
1969  return(s.str());
1970  }
1971 
1972 };
1973 
1979 {
1980 public:
1981 
1984  const std::string &id = "",
1985  lgl_Node *node = NULL)
1986  : lgl_ControllableNode(id, node),
1987  vbo_(vbo), managed_(false)
1988  {}
1989 
1990  virtual ~lgl_GeometryNode()
1991  {
1992  if (managed_)
1993  if (vbo_) delete vbo_;
1994  }
1995 
1996  virtual std::string getClassId() const {return("Geometry");}
1997 
1999  lglVBO *getVBO() const
2000  {
2001  return(vbo_);
2002  }
2003 
2005  void setVBO(lglVBO *vbo)
2006  {
2007  if (managed_)
2008  if (vbo_) delete vbo_;
2009 
2010  vbo_ = vbo;
2011  }
2012 
2014  bool managed()
2015  {
2016  return(managed_);
2017  }
2018 
2020  void manage(bool yes = true)
2021  {
2022  managed_ = yes;
2023  }
2024 
2026  std::string getName() const
2027  {
2028  std::string name;
2029 
2030  if (vbo_)
2031  name = vbo_->getName();
2032 
2033  return(name);
2034  }
2035 
2036  virtual bool stateless() const
2037  {
2038  return(true);
2039  }
2040 
2041 protected:
2042 
2043  lglVBO *vbo_;
2044  bool managed_;
2045 
2046  virtual void render()
2047  {
2048  if (hidden_) return;
2049 
2050  if (vbo_ && enabled_)
2051  {
2052  GL *gl = getGL();
2053 
2054  vbo_->lglRender(gl);
2055  }
2056 
2057  lgl_Node::render();
2058  }
2059 
2060  virtual void updateBoundingBox(vec3 &bboxmin, vec3 &bboxmax) const
2061  {
2062  if (vbo_ && enabled_)
2063  {
2064  vec3 bmin, bmax;
2065  vbo_->lglGetBoundingBox(bmin, bmax);
2066 
2067  growBoundingBox(bboxmin, bboxmax, bmin);
2068  growBoundingBox(bboxmin, bboxmax, bmax);
2069  }
2070  }
2071 
2072  virtual std::vector<vec4> get_vertices()
2073  {
2074  if (vbo_ && enabled_)
2075  return(vbo_->lglGetVertexCoordinates());
2076 
2077  return(std::vector<vec4>());
2078  }
2079 
2080  virtual lglVBO *get_vbo()
2081  {
2082  if (vbo_ && enabled_) return(vbo_);
2083  else return(NULL);
2084  }
2085 
2086  virtual void pick()
2087  {
2088  if (hidden_) return;
2089 
2090  if (vbo_ && enabled_)
2091  lglRayCast(vbo_);
2092 
2093  lgl_Node::pick();
2094  }
2095 
2096  virtual lgl_Node *convert();
2097  virtual lgl_Node *clone();
2098 
2099 public:
2100 
2101  virtual std::string to_string(bool classname = true) const
2102  {
2103  std::stringstream s;
2104 
2105  s << lgl_ControllableNode::to_string(classname);
2106 
2107  if (getName() != "")
2108  s << "(\"" << getName() << "\")";
2109 
2110  return(s.str());
2111  }
2112 
2113  virtual std::string to_label() const
2114  {
2115  lgl_string label = lgl_ControllableNode::to_label();
2116 
2117  if (getId() == "")
2118  {
2119  lgl_string name = getName();
2120 
2121  if (name != "")
2122  {
2123  name.remove("(", ")");
2124  label += "\\n" + name;
2125  }
2126  }
2127 
2128  if (vbo_)
2129  {
2130  label += "\\n[";
2131  label += glslmath::to_string(vbo_->lglGetVertexCount());
2132  label += "/";
2133  label += glslmath::to_string(vbo_->lglGetPrimitiveCount());
2134  label += "]";
2135  }
2136 
2137  return(label.strip("\\n"));
2138  }
2139 
2140 };
2141 
2147 {
2148 public:
2149 
2152  const std::string &id = "",
2153  lgl_Node *node = NULL)
2154  : lgl_GeometryNode(vbo, id, node)
2155  {
2156  manage();
2157  }
2158 
2159  virtual std::string getClassId() const {return("Container");}
2160 };
2161 
2166 {
2167 public:
2168 
2169  lgl_VBONode(const std::string &id = "",
2170  lgl_Node *node = NULL)
2171  : lgl_ControllableNode(id, node),
2172  lglVBO()
2173  {}
2174 
2175  virtual ~lgl_VBONode() {}
2176 
2177  virtual std::string getClassId() const {return("VBO");}
2178 
2179  virtual bool stateless() const
2180  {
2181  return(true);
2182  }
2183 
2184  virtual bool optimize();
2185 
2186 protected:
2187 
2188  virtual void render()
2189  {
2190  if (hidden_) return;
2191 
2192  if (enabled_)
2193  {
2194  GL *gl = getGL();
2195 
2196  lglRender(gl);
2197  }
2198 
2199  lgl_Node::render();
2200  }
2201 
2202  virtual void updateBoundingBox(vec3 &bboxmin, vec3 &bboxmax) const
2203  {
2204  if (enabled_)
2205  {
2206  vec3 bmin, bmax;
2207  lglGetBoundingBox(bmin, bmax);
2208 
2209  growBoundingBox(bboxmin, bboxmax, bmin);
2210  growBoundingBox(bboxmin, bboxmax, bmax);
2211  }
2212  }
2213 
2214  virtual std::vector<vec4> get_vertices()
2215  {
2216  if (enabled_)
2217  return(lglGetVertexCoordinates());
2218 
2219  return(std::vector<vec4>());
2220  }
2221 
2222  virtual lglVBO *get_vbo()
2223  {
2224  if (enabled_) return(this);
2225  else return(NULL);
2226  }
2227 
2228  virtual void pick()
2229  {
2230  if (hidden_) return;
2231 
2232  if (enabled_)
2233  lglRayCast(this);
2234 
2235  lgl_Node::pick();
2236  }
2237 
2238 public:
2239 
2240  virtual std::string to_string(bool classname = true) const
2241  {
2242  std::stringstream s;
2243 
2244  s << lgl_ControllableNode::to_string(classname);
2245 
2246  if (getName() != "")
2247  s << "(\"" << getName() << "\")";
2248 
2249  return(s.str());
2250  }
2251 
2252  virtual std::string to_label() const
2253  {
2254  lgl_string label = lgl_ControllableNode::to_label();
2255 
2256  if (getId() == "")
2257  {
2258  lgl_string name = getName();
2259 
2260  if (name != "")
2261  {
2262  name.remove("(", ")");
2263  label += "\\n" + name;
2264  }
2265  }
2266 
2267  label += "\\n[";
2268  label += glslmath::to_string(lglGetVertexCount());
2269  label += "/";
2270  label += glslmath::to_string(lglGetPrimitiveCount());
2271  label += "]";
2272 
2273  return(label.strip("\\n"));
2274  }
2275 
2276 };
2277 
2278 inline lgl_Node *lgl_GeometryNode::convert()
2279 {
2280  return(clone());
2281 }
2282 
2283 inline lgl_Node *lgl_GeometryNode::clone()
2284 {
2285  lgl_VBONode *vbo = new lgl_VBONode();
2286 
2287  if (vbo_)
2288  {
2289  vbo_->lglAppendVerticesTo(vbo);
2290  vbo->setName(vbo_->getName());
2291  }
2292 
2293  return(vbo);
2294 }
2295 
2296 inline bool lgl_VBONode::optimize()
2297 {
2298  int optimizable = 0;
2299 
2300  for (unsigned int i=0; i<children_.size(); i++)
2301  if (follow(i))
2302  {
2303  lgl_Node *node = get(i);
2304 
2305  if (lgl_VBONode *vbo = dynamic_cast<lgl_VBONode*>(node))
2306  if (vbo->lglGetVertexMode() == lglGetVertexMode())
2307  optimizable++;
2308  }
2309 
2310  if (optimizable == 1)
2311  for (unsigned int i=0; i<children_.size(); i++)
2312  if (follow(i))
2313  {
2314  lgl_Node *node = get(i);
2315 
2316  if (lgl_VBONode *vbo = dynamic_cast<lgl_VBONode*>(node))
2317  if (vbo->lglGetVertexMode() == lglGetVertexMode())
2318  lglAppendVerticesTo(vbo);
2319  }
2320 
2321  return(optimizable==1);
2322 }
2323 
2329 {
2330 public:
2331 
2333  lgl_ColorNode(double r, double g, double b, double a=1,
2334  const std::string &id = "",
2335  lgl_Node *node = NULL)
2336  : lgl_ControllableNode(id, node),
2337  color_(vec4(r,g,b,a))
2338  {}
2339 
2341  lgl_ColorNode(double color,
2342  const std::string &id = "",
2343  lgl_Node *node = NULL)
2344  : lgl_ControllableNode(id, node),
2345  color_(vec4(color))
2346  {}
2347 
2349  lgl_ColorNode(const vec4 &color = vec4(1,1,1),
2350  const std::string &id = "",
2351  lgl_Node *node = NULL)
2352  : lgl_ControllableNode(id, node),
2353  color_(color)
2354  {}
2355 
2356  virtual ~lgl_ColorNode() {}
2357 
2358  virtual std::string getClassId() const {return("Color");}
2359 
2361  vec4 getColor() const
2362  {
2363  return(color_);
2364  }
2365 
2367  void setColor(const vec4 &c)
2368  {
2369  color_ = c;
2370  }
2371 
2373  virtual bool hasTransparency()
2374  {
2375  if (!enabled_) return(false);
2376  return(color_.a < 1);
2377  }
2378 
2379 protected:
2380 
2381  vec4 color_;
2382 
2383  virtual void render()
2384  {
2385  if (hidden_) return;
2386 
2387  vec4 color(0);
2388 
2389  if (enabled_)
2390  {
2391  color = lglGetColor();
2392  lglColor(color_);
2393  }
2394 
2395  lgl_Node::render();
2396 
2397  if (enabled_)
2398  {
2399  lglColor(color);
2400  }
2401  }
2402 
2403  virtual vec4 update_color(vec4 c)
2404  {
2405  if (enabled_) return(color_);
2406  else return(c);
2407  }
2408 
2409  virtual bool optimize();
2410  virtual bool swappable();
2411 
2412 public:
2413 
2414  virtual std::string to_string(bool classname = true) const
2415  {
2416  std::stringstream s;
2417 
2418  s << lgl_ControllableNode::to_string(classname);
2419  s << "(vec4" << getColor() << ")";
2420 
2421  return(s.str());
2422  }
2423 
2424 };
2425 
2426 inline bool lgl_ColorNode::optimize()
2427 {
2428  bool optimizable = true;
2429 
2430  for (unsigned int i=0; i<children_.size(); i++)
2431  if (follow(i))
2432  {
2433  lgl_Node *node = get(i);
2434  lgl_VBONode *vbo = dynamic_cast<lgl_VBONode*>(node);
2435 
2436  if (!node->leaf())
2437  optimizable = false;
2438 
2439  if (!vbo)
2440  optimizable = false;
2441  }
2442 
2443  if (optimizable)
2444  for (unsigned int i=0; i<children_.size(); i++)
2445  if (follow(i))
2446  {
2447  lgl_Node *node = get(i);
2448 
2449  if (lgl_VBONode *vbo = dynamic_cast<lgl_VBONode*>(node))
2450  if (!vbo->lglAppliedColoring())
2451  {
2452  vec4 c = getColor();
2453  vbo->lglApplyColor(c);
2454  }
2455  }
2456 
2457  return(optimizable);
2458 }
2459 
2465 {
2466 public:
2467 
2469  lgl_TransformationNode(const std::string &id = "",
2470  lgl_Node *node = NULL)
2471  : lgl_SteerableNode(id, node),
2472  transformation_(1),
2473  identity_(true)
2474  {}
2475 
2478  const std::string &id = "",
2479  lgl_Node *node = NULL)
2480  : lgl_SteerableNode(id, node),
2481  transformation_(m),
2482  identity_(false)
2483  {}
2484 
2487  const std::string &id = "",
2488  lgl_Node *node = NULL)
2489  : lgl_SteerableNode(id, node),
2490  transformation_(mat4::translate(v)),
2491  identity_(v==vec3(0))
2492  {}
2493 
2495  lgl_TransformationNode(double angle, const vec3 &v,
2496  const std::string &id = "",
2497  lgl_Node *node = NULL)
2498  : lgl_SteerableNode(id, node),
2499  transformation_(mat4::rotate(angle, v)),
2500  identity_(angle==0)
2501  {}
2502 
2505  const std::string &id = "",
2506  lgl_Node *node = NULL)
2507  : lgl_SteerableNode(id, node),
2508  transformation_(mat4::scale(scale)),
2509  identity_(scale==1)
2510  {}
2511 
2512  virtual ~lgl_TransformationNode() {}
2513 
2514  virtual std::string getClassId() const {return("Transformation");}
2515 
2517  vec3 transform(const vec3 &p) const
2518  {
2519  if (identity_) return(p);
2520  return(transformation_ * vec4(p));
2521  }
2522 
2524  vec4 transform(const vec4 &p) const
2525  {
2526  if (identity_) return(p);
2527  return(transformation_ * p);
2528  }
2529 
2532  {
2533  return(transformation_);
2534  }
2535 
2537  void setTransformation(const mat4 &m)
2538  {
2539  transformation_ = m;
2540  identity_ = m==mat4(1);
2541  }
2542 
2544  void translate(const vec3 &v)
2545  {
2546  transformation_ <<= mat4::translate(v);
2547  identity_ = v==vec3(0);
2548  }
2549 
2551  void translate(double x, double y, double z)
2552  {
2553  vec3 v(x,y,z);
2554  transformation_ <<= mat4::translate(v);
2555  identity_ = v==vec3(0);
2556  }
2557 
2559  void rotate(double angle, const vec3 &v)
2560  {
2561  transformation_ <<= mat4::rotate(angle, v);
2562  identity_ = angle==0;
2563  }
2564 
2566  void rotate(double angle,
2567  double x, double y, double z)
2568  {
2569  vec3 v(x,y,z);
2570  transformation_ <<= mat4::rotate(angle, v);
2571  identity_ = angle==0;
2572  }
2573 
2575  void scale(double c)
2576  {
2577  transformation_ <<= mat4::scale(c);
2578  identity_ = c==1;
2579  }
2580 
2582  void scale(double x, double y, double z, double w=1)
2583  {
2584  vec4 c(x,y,z,w);
2585  transformation_ <<= mat4::scale(c);
2586  identity_ = c==vec4(1);
2587  }
2588 
2590  void scale(const vec4 &c)
2591  {
2592  transformation_ <<= mat4::scale(c);
2593  identity_ = c==vec4(1);
2594  }
2595 
2596 protected:
2597 
2598  mat4 transformation_;
2599  bool identity_;
2600 
2601  virtual void render()
2602  {
2603  if (hidden_) return;
2604 
2605  if (!identity_ && enabled_)
2606  {
2607  lglPushMatrix();
2608  lglMultMatrix(transformation_);
2609  }
2610 
2611  lgl_Node::render();
2612 
2613  if (!identity_ && enabled_)
2614  {
2615  lglPopMatrix();
2616  }
2617  }
2618 
2619  virtual void updateBoundingBox(vec3 &bboxmin, vec3 &bboxmax) const
2620  {
2621  if (enabled_)
2622  {
2623  if (bboxmin.x <= bboxmax.x &&
2624  bboxmin.y <= bboxmax.y &&
2625  bboxmin.z <= bboxmax.z)
2626  {
2627  vec3 p1(bboxmin.x, bboxmin.y, bboxmin.z);
2628  vec3 p2(bboxmax.x, bboxmin.y, bboxmin.z);
2629  vec3 p3(bboxmin.x, bboxmax.y, bboxmin.z);
2630  vec3 p4(bboxmax.x, bboxmax.y, bboxmin.z);
2631  vec3 p5(bboxmin.x, bboxmin.y, bboxmax.z);
2632  vec3 p6(bboxmax.x, bboxmin.y, bboxmax.z);
2633  vec3 p7(bboxmin.x, bboxmax.y, bboxmax.z);
2634  vec3 p8(bboxmax.x, bboxmax.y, bboxmax.z);
2635 
2636  bboxmin = vec3(DBL_MAX);
2637  bboxmax = vec3(-DBL_MAX);
2638 
2639  growBoundingBox(bboxmin, bboxmax, transform(p1));
2640  growBoundingBox(bboxmin, bboxmax, transform(p2));
2641  growBoundingBox(bboxmin, bboxmax, transform(p3));
2642  growBoundingBox(bboxmin, bboxmax, transform(p4));
2643  growBoundingBox(bboxmin, bboxmax, transform(p5));
2644  growBoundingBox(bboxmin, bboxmax, transform(p6));
2645  growBoundingBox(bboxmin, bboxmax, transform(p7));
2646  growBoundingBox(bboxmin, bboxmax, transform(p8));
2647  }
2648  }
2649  }
2650 
2651  virtual mat4 update_transform(mat4 m)
2652  {
2653  if (!identity_ && enabled_) return(m * getTransformation());
2654  else return(m);
2655  }
2656 
2657  virtual void pick()
2658  {
2659  if (hidden_) return;
2660 
2661  if (!identity_ && enabled_)
2662  {
2663  lglPushMatrix();
2664  lglMultMatrix(transformation_);
2665  }
2666 
2667  lgl_Node::pick();
2668 
2669  if (!identity_ && enabled_)
2670  {
2671  lglPopMatrix();
2672  }
2673  }
2674 
2675  virtual bool optimize();
2676  virtual bool swappable();
2677 
2678 public:
2679 
2680  virtual std::string to_string(bool classname = true) const
2681  {
2682  std::stringstream s;
2683 
2684  s << lgl_SteerableNode::to_string(classname);
2685  s << "(mat4" << getTransformation() << ")";
2686 
2687  return(s.str());
2688  }
2689 
2690 };
2691 
2697 {
2698 public:
2699 
2702  const std::string &id = "",
2703  lgl_Node *node = NULL)
2704  : lgl_TransformationNode(id, node),
2705  translation_(v)
2706  {
2707  translate(v);
2708  }
2709 
2711  lgl_TranslationNode(double x, double y, double z,
2712  const std::string &id = "",
2713  lgl_Node *node = NULL)
2714  : lgl_TransformationNode(id, node),
2715  translation_(vec3(x,y,z))
2716  {
2717  translate(x,y,z);
2718  }
2719 
2720  virtual std::string getClassId() const {return("Translation");}
2721 
2724  {
2725  return(translation_);
2726  }
2727 
2728 protected:
2729 
2730  vec3 translation_;
2731 
2732 public:
2733 
2734  virtual std::string to_string(bool classname = true) const
2735  {
2736  std::stringstream s;
2737 
2738  s << lgl_SteerableNode::to_string(classname);
2739  s << "(vec3" << getTranslation() << ")";
2740 
2741  return(s.str());
2742  }
2743 
2744  virtual std::string to_label() const
2745  {
2746  return(lgl_string(lgl_TransformationNode::to_label() + "\\nT").strip("\\n"));
2747  }
2748 
2749 };
2750 
2756 {
2757 public:
2758 
2760  lgl_RotationNode(double angle, const vec3 &axis,
2761  const std::string &id = "",
2762  lgl_Node *node = NULL)
2763  : lgl_TransformationNode(id, node),
2764  rotation_angle_(angle),
2765  rotation_axis_(axis)
2766  {
2767  rotate(angle, axis);
2768  }
2769 
2771  lgl_RotationNode(double angle,
2772  double x, double y, double z,
2773  const std::string &id = "",
2774  lgl_Node *node = NULL)
2775  : lgl_TransformationNode(id, node),
2776  rotation_angle_(angle),
2777  rotation_axis_(vec3(x,y,z))
2778  {
2779  rotate(angle, x,y,z);
2780  }
2781 
2782  virtual std::string getClassId() const {return("Rotation");}
2783 
2785  double getRotationAngle() const
2786  {
2787  return(rotation_angle_);
2788  }
2789 
2792  {
2793  return(rotation_axis_);
2794  }
2795 
2796 protected:
2797 
2798  double rotation_angle_;
2799  vec3 rotation_axis_;
2800 
2801 public:
2802 
2803  virtual std::string to_string(bool classname = true) const
2804  {
2805  std::stringstream s;
2806 
2807  s << lgl_SteerableNode::to_string(classname);
2808  s << "(" << getRotationAngle() << ", vec3" << getRotationAxis() << ")";
2809 
2810  return(s.str());
2811  }
2812 
2813  virtual std::string to_label() const
2814  {
2815  return(lgl_string(lgl_TransformationNode::to_label() + "\\nR").strip("\\n"));
2816  }
2817 
2818 };
2819 
2825 {
2826 public:
2827 
2829  lgl_ScaleNode(double c,
2830  const std::string &id = "",
2831  lgl_Node *node = NULL)
2832  : lgl_TransformationNode(id, node),
2833  scale_(vec4(c))
2834  {
2835  scale(c);
2836  }
2837 
2839  lgl_ScaleNode(double x, double y, double z, double w=1,
2840  const std::string &id = "",
2841  lgl_Node *node = NULL)
2842  : lgl_TransformationNode(id, node),
2843  scale_(vec4(x,y,z,w))
2844  {
2845  scale(x,y,z,w);
2846  }
2847 
2850  const std::string &id = "",
2851  lgl_Node *node = NULL)
2852  : lgl_TransformationNode(id, node),
2853  scale_(c)
2854  {
2855  scale(c);
2856  }
2857 
2858  virtual std::string getClassId() const {return("Scale");}
2859 
2861  vec4 getScale() const
2862  {
2863  return(scale_);
2864  }
2865 
2866 protected:
2867 
2868  vec4 scale_;
2869 
2870 public:
2871 
2872  virtual std::string to_string(bool classname = true) const
2873  {
2874  std::stringstream s;
2875 
2876  s << lgl_SteerableNode::to_string(classname);
2877  s << "(vec4" << getScale() << ")";
2878 
2879  return(s.str());
2880  }
2881 
2882  virtual std::string to_label() const
2883  {
2884  return(lgl_string(lgl_TransformationNode::to_label() + "\\nS").strip("\\n"));
2885  }
2886 
2887 };
2888 
2894 {
2895 public:
2896 
2898  lgl_TextureTransformationNode(const std::string &id = "",
2899  lgl_Node *node = NULL)
2900  : lgl_TransformationNode(id, node)
2901  {}
2902 
2905  const std::string &id = "",
2906  lgl_Node *node = NULL)
2907  : lgl_TransformationNode(m, id, node)
2908  {}
2909 
2912  const std::string &id = "",
2913  lgl_Node *node = NULL)
2914  : lgl_TransformationNode(v, id, node)
2915  {}
2916 
2918  lgl_TextureTransformationNode(double angle, const vec3 &v,
2919  const std::string &id = "",
2920  lgl_Node *node = NULL)
2921  : lgl_TransformationNode(angle, v, id, node)
2922  {}
2923 
2926  const std::string &id = "",
2927  lgl_Node *node = NULL)
2928  : lgl_TransformationNode(scale, id, node)
2929  {}
2930 
2931  virtual std::string getClassId() const {return("TextureTransformation");}
2932 
2933 protected:
2934 
2935  virtual void render()
2936  {
2937  if (hidden_) return;
2938 
2939  if (!identity_ && enabled_)
2940  {
2941  lglMatrixMode(LGL_TEXTURE);
2942  lglPushMatrix();
2943  lglMultMatrix(transformation_);
2944  lglMatrixMode(LGL_MODELVIEW);
2945  }
2946 
2947  lgl_Node::render();
2948 
2949  if (!identity_ && enabled_)
2950  {
2951  lglMatrixMode(LGL_TEXTURE);
2952  lglPopMatrix();
2953  lglMatrixMode(LGL_MODELVIEW);
2954  }
2955  }
2956 
2957  virtual mat4 update_transform(mat4 m) {return(m);}
2958 
2959  virtual void pick()
2960  {
2961  lgl_Node::pick();
2962  }
2963 
2964  virtual std::string to_label() const
2965  {
2966  return(lgl_string(lgl_TransformationNode::to_label() + "\\nTM").strip("\\n"));
2967  }
2968 
2969 };
2970 
2977 {
2978 public:
2979 
2982  {
2983  LGL_STEER_NONE,
2984  LGL_STEER_PAUSE,
2985  LGL_STEER_RESUME,
2986  LGL_STEER_SPEEDUP,
2987  LGL_STEER_RESTART,
2988  LGL_STEER_RESTART_RESUME,
2989  LGL_STEER_REWIND,
2990  LGL_STEER_REWIND_RESUME,
2991  LGL_STEER_REVERSE,
2992  LGL_STEER_DIRECTION,
2993  LGL_STEER_REWIND_REVERSE,
2994  LGL_STEER_REWIND_REVERSE_RESUME,
2995  LGL_STEER_REWIND_DIRECTION,
2996  LGL_STEER_REWIND_DIRECTION_RESUME,
2997  LGL_STEER_FORWARD,
2998  LGL_STEER_BACKWARD,
2999  LGL_STEER_RESTART_ALL,
3000  LGL_STEER_PAUSE_ALL,
3001  LGL_STEER_SPEEDUP_ALL
3002  };
3003 
3005  lgl_AnimationNode(double delta = 0, vec3 vector = vec3(0), double limit = 0, double accel = 0, double reverse = 0,
3006  const std::string &id = "",
3007  lgl_Node *node = NULL)
3008  : lgl_TransformationNode(id, node),
3009  animation_(0),
3010  velocity_(delta),
3011  acceleration_(accel),
3012  delta_(delta),
3013  accel_(accel),
3014  reverse_(reverse),
3015  vector_(vector),
3016  limit_(fabs(limit)),
3017  stop_(false),
3018  signal_(false),
3019  sync_(false),
3020  paused_(false),
3021  speedup_(1)
3022  {}
3023 
3024  virtual std::string getClassId() const {return("Animation");}
3025 
3027  double getDelta() const
3028  {
3029  return(delta_);
3030  }
3031 
3033  vec3 getVector() const
3034  {
3035  return(vector_);
3036  }
3037 
3039  double getVelocity() const
3040  {
3041  return(velocity_);
3042  }
3043 
3045  double getLimit() const
3046  {
3047  return(limit_);
3048  }
3049 
3052  {
3053  stop_ = true;
3054  }
3055 
3057  bool getStopOnLimit() const
3058  {
3059  return(stop_);
3060  }
3061 
3064  {
3065  signal_ = true;
3066  }
3067 
3069  bool getSignalOnStop() const
3070  {
3071  return(signal_);
3072  }
3073 
3075  double getAcceleration() const
3076  {
3077  return(accel_);
3078  }
3079 
3081  double getReverse() const
3082  {
3083  return(reverse_);
3084  }
3085 
3087  double animation() const
3088  {
3089  return(animation_);
3090  }
3091 
3093  void restart(double animation = 0)
3094  {
3095  animation_ = animation;
3096  velocity_ = delta_;
3097  acceleration_ = accel_;
3098 
3099  if (limit_ != 0)
3100  if (fabs(animation_) >= limit_)
3101  {
3102  if (animation_ >= 0)
3103  {
3104  animation_ = limit_;
3105  velocity_ = -fabs(delta_);
3106  }
3107  else
3108  {
3109  animation_ = -limit_;
3110  velocity_ = fabs(delta_);
3111  }
3112  }
3113 
3114  transformation_ = animate(animation_, vector_);
3115  identity_ = false;
3116  }
3117 
3119  void rewind(double animation = 0)
3120  {
3121  animation_ = animation;
3122 
3123  transformation_ = animate(animation_, vector_);
3124  identity_ = false;
3125  }
3126 
3128  void direction(bool forward)
3129  {
3130  if (forward && velocity_<0) reverse();
3131  if (!forward && velocity_>0) reverse();
3132  }
3133 
3135  void reverse()
3136  {
3137  velocity_ = -velocity_;
3138  }
3139 
3141  void forward(double delta)
3142  {
3143  if (velocity_ >= 0)
3144  animation_ += delta;
3145  else
3146  animation_ -= delta;
3147 
3148  transformation_ = animate(animation_, vector_);
3149  identity_ = false;
3150  }
3151 
3153  void backward(double delta)
3154  {
3155  if (velocity_ >= 0)
3156  animation_ -= delta;
3157  else
3158  animation_ += delta;
3159 
3160  transformation_ = animate(animation_, vector_);
3161  identity_ = false;
3162  }
3163 
3165  virtual bool paused() const
3166  {
3167  return(paused_);
3168  }
3169 
3171  virtual void pause(bool yes = true)
3172  {
3173  paused_ = yes;
3174  }
3175 
3177  virtual void resume(bool yes = true)
3178  {
3179  paused_ = !yes;
3180  }
3181 
3183  virtual double speedup()
3184  {
3185  return(speedup_);
3186  }
3187 
3189  virtual void setSpeedup(double speedup = 1)
3190  {
3191  speedup_ = speedup;
3192  }
3193 
3196  {
3197  return(steer_mode_);
3198  }
3199 
3202  {
3203  steer_mode_ = mode;
3204  }
3205 
3207  virtual void steer(double level, bool override = true)
3208  {
3209  switch (getSteerMode())
3210  {
3211  case LGL_STEER_NONE: break;
3212  case LGL_STEER_PAUSE: pause(override); break;
3213  case LGL_STEER_RESUME: resume(override); break;
3214  case LGL_STEER_SPEEDUP: if (override) setSpeedup(level); break;
3215  case LGL_STEER_RESTART: if (override) restart(level); break;
3216  case LGL_STEER_RESTART_RESUME: restart(level); resume(override); break;
3217  case LGL_STEER_REWIND: if (override) rewind(level); break;
3218  case LGL_STEER_REWIND_RESUME: rewind(level); resume(override); break;
3219  case LGL_STEER_REVERSE: if (override) reverse(); break;
3220  case LGL_STEER_DIRECTION: direction(override); break;
3221  case LGL_STEER_REWIND_REVERSE: if (override) {rewind(level); reverse();} break;
3222  case LGL_STEER_REWIND_REVERSE_RESUME: rewind(level); reverse(); resume(override); break;
3223  case LGL_STEER_REWIND_DIRECTION: rewind(level); direction(override); break;
3224  case LGL_STEER_REWIND_DIRECTION_RESUME: rewind(level); direction(override); resume(); break;
3225  case LGL_STEER_FORWARD: if (override) forward(level); break;
3226  case LGL_STEER_BACKWARD: if (override) backward(level); break;
3227  case LGL_STEER_RESTART_ALL: if (override) restartAll(level); break;
3228  case LGL_STEER_PAUSE_ALL: pauseAll(override); break;
3229  case LGL_STEER_SPEEDUP_ALL: if (override) speedupAll(level); break;
3230  }
3231  }
3232 
3233 protected:
3234 
3235  double animation_;
3236  double velocity_;
3237  double acceleration_;
3238 
3239  double delta_;
3240  double accel_;
3241  double reverse_;
3242  vec3 vector_;
3243  double limit_;
3244  bool stop_;
3245  bool signal_;
3246  bool sync_;
3247 
3248  bool paused_;
3249  double speedup_;
3250 
3251  lgl_animation_steer_mode_enum steer_mode_;
3252 
3253  virtual void update(double dt)
3254  {
3255  if (!paused_)
3256  {
3257  if (velocity_!=0 || acceleration_!=0)
3258  {
3259  velocity_ += acceleration_*dt;
3260  animation_ += velocity_*speedup_*dt;
3261 
3262  if (limit_ != 0)
3263  {
3264  if (stop_)
3265  {
3266  if (fabs(animation_) > limit_)
3267  {
3268  if (animation_ >= 0)
3269  animation_ = limit_;
3270  else
3271  animation_ = -limit_;
3272 
3273  paused_ = true;
3274 
3275  if (signal_)
3276  signal();
3277  }
3278  }
3279 
3280  if (reverse_ == 0)
3281  {
3282  if (fabs(animation_) > limit_)
3283  {
3284  if (animation_ >= 0) animation_ -= animation_ - limit_;
3285  else animation_ += -animation_ - limit_;
3286  velocity_ = -velocity_;
3287  }
3288  }
3289  else
3290  {
3291  if (fabs(animation_) > limit_)
3292  {
3293  double reverse;
3294 
3295  if (animation_ <= 0)
3296  reverse = fabs(reverse_);
3297  else
3298  reverse = -fabs(reverse_);
3299 
3300  acceleration_ = reverse;
3301  sync_ = true;
3302  }
3303  else
3304  {
3305  if (sync_)
3306  {
3307  if (acceleration_ >= 0)
3308  velocity_ = fabs(delta_);
3309  else
3310  velocity_ = -fabs(delta_);
3311 
3312  acceleration_ = 0;
3313  sync_ = false;
3314  }
3315  }
3316  }
3317  }
3318 
3319  transformation_ = animate(animation_, vector_);
3320  identity_ = false;
3321  }
3322  }
3323 
3324  lgl_Node::update(dt);
3325  }
3326 
3328  virtual mat4 animate(double animation, const vec3 &vector) = 0;
3329 
3330 public:
3331 
3332  virtual void restartAll(double animation = 0)
3333  {
3334  restart(animation);
3336  }
3337 
3338  virtual void pauseAll(bool yes = true)
3339  {
3340  pause(yes);
3341  lgl_Node::pauseAll(yes);
3342  }
3343 
3344  virtual void speedupAll(double speedup = 1)
3345  {
3348  }
3349 
3350  virtual std::string to_string(bool classname = true) const
3351  {
3352  std::stringstream s;
3353 
3354  if (classname)
3355  {
3356  s << lgl_SteerableNode::to_string(classname);
3357 
3358  s << "(";
3359 
3360  s << getDelta();
3361  s << ", vec3" << getVector();
3362 
3363  if (getLimit()!=0 || getAcceleration()!=0)
3364  {
3365  s << ", " << getLimit();
3366  s << ", " << getStopOnLimit();
3367  s << ", " << getSignalOnStop();
3368  s << ", " << getAcceleration();
3369  s << ", " << getReverse();
3370  }
3371 
3372  s << ")";
3373 
3374  if (getSteerMode() != LGL_STEER_NONE)
3375  {
3376  s << "(";
3377 
3378  switch (getSteerMode())
3379  {
3380  case LGL_STEER_NONE: s << "none"; break;
3381  case LGL_STEER_PAUSE: s << "pause"; break;
3382  case LGL_STEER_RESUME: s << "resume"; break;
3383  case LGL_STEER_SPEEDUP: s << "speedup"; break;
3384  case LGL_STEER_RESTART: s << "restart"; break;
3385  case LGL_STEER_RESTART_RESUME: s << "restart-resume"; break;
3386  case LGL_STEER_REWIND: s << "rewind"; break;
3387  case LGL_STEER_REWIND_RESUME: s << "rewind-resume"; break;
3388  case LGL_STEER_REVERSE: s << "reverse"; break;
3389  case LGL_STEER_DIRECTION: s << "direction"; break;
3390  case LGL_STEER_REWIND_REVERSE: s << "rewind-reverse"; break;
3391  case LGL_STEER_REWIND_REVERSE_RESUME: s << "rewind-reverse-resume"; break;
3392  case LGL_STEER_REWIND_DIRECTION: s << "rewind-direction"; break;
3393  case LGL_STEER_REWIND_DIRECTION_RESUME: s << "rewind-direction-resume"; break;
3394  case LGL_STEER_FORWARD: s << "forward"; break;
3395  case LGL_STEER_BACKWARD: s << "backward"; break;
3396  case LGL_STEER_RESTART_ALL: s << "restart-all"; break;
3397  case LGL_STEER_PAUSE_ALL: s << "pause-all"; break;
3398  case LGL_STEER_SPEEDUP_ALL: s << "speedup-all"; break;
3399  }
3400 
3401  s << ")";
3402  }
3403  }
3404  else
3405  {
3406  s << lgl_SteerableNode::to_id("Transformation", classname);
3407  s << "(mat4" << getTransformation() << ")";
3408  }
3409 
3410  return(s.str());
3411  }
3412 
3413  virtual std::string to_label() const
3414  {
3415  lgl_string label = lgl_SteerableNode::to_label();
3416 
3417  switch (getSteerMode())
3418  {
3419  case LGL_STEER_PAUSE: label += "\\npause"; break;
3420  case LGL_STEER_RESUME: label += "\\nresume"; break;
3421  case LGL_STEER_SPEEDUP: label += "\\nspeedup"; break;
3422  case LGL_STEER_RESTART: label += "\\nrestart"; break;
3423  case LGL_STEER_RESTART_RESUME: label += "\\nrestart-resume"; break;
3424  case LGL_STEER_REWIND: label += "\\nrewind"; break;
3425  case LGL_STEER_REWIND_RESUME: label += "\\nrewind-resume"; break;
3426  case LGL_STEER_REVERSE: label += "\\nreverse"; break;
3427  case LGL_STEER_DIRECTION: label += "\\ndirection"; break;
3428  case LGL_STEER_REWIND_REVERSE: label += "\\nrewind-reverse"; break;
3429  case LGL_STEER_REWIND_REVERSE_RESUME: label += "\\nrewind-reverse-resume"; break;
3430  case LGL_STEER_REWIND_DIRECTION: label += "\\nrewind-direction"; break;
3431  case LGL_STEER_REWIND_DIRECTION_RESUME: label += "\\nrewind-direction-resume"; break;
3432  case LGL_STEER_FORWARD: label += "\\nforward"; break;
3433  case LGL_STEER_BACKWARD: label += "\\nbackward"; break;
3434  case LGL_STEER_RESTART_ALL: label += "\\nrestart-all"; break;
3435  case LGL_STEER_PAUSE_ALL: label += "\\npause-all"; break;
3436  case LGL_STEER_SPEEDUP_ALL: label += "\\nspeedup-all"; break;
3437  default: break;
3438  }
3439 
3440  return(label.strip("\\n"));
3441  }
3442 
3443 };
3444 
3449 {
3450 public:
3451 
3453  lgl_TranslationAnimationNode(double delta, const vec3 &vector, double limit = 0, double accel = 0, double reverse = 0,
3454  const std::string &id = "",
3455  lgl_Node *node = NULL)
3456  : lgl_AnimationNode(delta, vector, limit, accel, reverse, id, node)
3457  {}
3458 
3459  virtual std::string getClassId() const {return("TranslationAnimation");}
3460 
3461 protected:
3462 
3463  virtual mat4 animate(double animation, const vec3 &vector)
3464  {
3465  return(mat4::translate(animation * vector));
3466  }
3467 
3468  virtual std::string to_label() const
3469  {
3470  return(lgl_string(lgl_AnimationNode::to_label() + "\\nT").strip("\\n"));
3471  }
3472 
3473 };
3474 
3479 {
3480 public:
3481 
3483  lgl_RotationAnimationNode(double omega, const vec3 &axis, double limit = 0, double accel = 0, double reverse = 0,
3484  const std::string &id = "",
3485  lgl_Node *node = NULL)
3486  : lgl_AnimationNode(omega, axis, limit, accel, reverse, id, node)
3487  {}
3488 
3489  virtual std::string getClassId() const {return("RotationAnimation");}
3490 
3491 protected:
3492 
3493  virtual mat4 animate(double animation, const vec3 &axis)
3494  {
3495  return(mat4::rotate(animation, axis));
3496  }
3497 
3498  virtual std::string to_label() const
3499  {
3500  return(lgl_string(lgl_AnimationNode::to_label() + "\\nR").strip("\\n"));
3501  }
3502 
3503 };
3504 
3510 {
3511 public:
3512 
3515  {
3516  LGL_TRANSITION_NEAREST,
3517  LGL_TRANSITION_LINEAR,
3518  LGL_TRANSITION_COS,
3519  LGL_TRANSITION_ATAN
3520  };
3521 
3523  lgl_TransitionNode(double delta, const vec3 &vector,
3524  const std::string &id = "",
3525  lgl_Node *node = NULL)
3526  : lgl_AnimationNode(delta, vector, 0.5, 0, 0, id, node),
3527  style_(LGL_TRANSITION_LINEAR)
3528  {
3529  assert(delta != 0);
3530 
3531  stopOnLimit();
3532  signalOnStop();
3533 
3534  animation_ = -0.5;
3535  velocity_ = delta;
3537  }
3538 
3539  virtual std::string getClassId() const {return("Transition");}
3540 
3542  bool enabled() const
3543  {
3544  return(animation() >= 0);
3545  }
3546 
3548  bool disabled() const
3549  {
3550  return(animation() < 0);
3551  }
3552 
3554  void enable(bool yes = true)
3555  {
3556  if (enabled() != yes)
3557  {
3558  lgl_AnimationNode::restart(yes?0.5:-0.5);
3560  }
3561  }
3562 
3564  void disable(bool yes = true)
3565  {
3566  if (disabled() != yes)
3567  {
3568  lgl_AnimationNode::restart(yes?-0.5:0.5);
3570  }
3571  }
3572 
3574  void toggle()
3575  {
3576  enable(disabled());
3577  }
3578 
3579  void restart(double animation = 0)
3580  {}
3581 
3582  virtual void pause(bool yes = true)
3583  {}
3584 
3585  virtual void resume(bool yes = true)
3586  {}
3587 
3588  virtual void setSpeedup(double speedup = 1)
3589  {}
3590 
3591  virtual void control(bool override = true)
3592  {
3593  switch (getControlMode())
3594  {
3595  case LGL_CONTROL_ON: if (disabled()) {lgl_AnimationNode::restart(-0.5); lgl_AnimationNode::resume();} break;
3596  case LGL_CONTROL_OFF: if (enabled()) {lgl_AnimationNode::restart(0.5); lgl_AnimationNode::resume();} break;
3597  case LGL_CONTROL_ENABLE: if (enabled() != override) {lgl_AnimationNode::restart(override?-0.5:0.5); lgl_AnimationNode::resume();} break;
3598  case LGL_CONTROL_DISABLE: if (disabled() != override) {lgl_AnimationNode::restart(override?0.5:-0.5); lgl_AnimationNode::resume();} break;
3599  case LGL_CONTROL_INVERT: lgl_AnimationNode::resume(); break;
3600  default: lgl_AnimationNode::control(override); break;
3601  }
3602  }
3603 
3604  virtual void steer(double level, bool override = true)
3605  {
3606  switch (getSteerMode())
3607  {
3608  case LGL_STEER_RESTART: lgl_AnimationNode::restart(level<0.5?-0.5:0.5); break;
3609  case LGL_STEER_RESTART_RESUME: lgl_AnimationNode::restart(level<0.5?-0.5:0.5); if (override) lgl_AnimationNode::resume(); break;
3610  default: lgl_AnimationNode::steer(level, override); break;
3611  }
3612  }
3613 
3616  {
3617  return(style_);
3618  }
3619 
3622  {
3623  style_ = style;
3624  }
3625 
3627  virtual void finish()
3628  {
3629  if (!paused())
3630  {
3631  lgl_AnimationNode::restart(velocity_>0?0.5:-0.5);
3633 
3634  transformation_ = animate(animation_, vector_);
3635  identity_ = false;
3636 
3637  if (signal_)
3638  signal_delayed();
3639  }
3640  }
3641 
3642 protected:
3643 
3644  lgl_transition_enum style_;
3645 
3646  double transition(double w) const
3647  {
3648  static const double c = 2;
3649 
3650  switch (getTransitionStyle())
3651  {
3652  case LGL_TRANSITION_NEAREST: return(w<0.5?0:1);
3653  case LGL_TRANSITION_LINEAR: return(w);
3654  case LGL_TRANSITION_COS: return(0.5-0.5*cos(w*PI));
3655  case LGL_TRANSITION_ATAN: return(0.5*atan(c*(w-0.5))/atan(c*0.5)+0.5);
3656  }
3657 
3658  return(w);
3659  }
3660 
3661  virtual void pre_update(double dt)
3662  {
3663  if (dt == 0)
3664  finish();
3665 
3666  lgl_AnimationNode::pre_update(dt);
3667  }
3668 
3669 public:
3670 
3671  virtual std::string to_string(bool classname = true) const
3672  {
3673  std::stringstream s;
3674 
3675  s << lgl_AnimationNode::to_string(classname);
3676 
3677  if (classname)
3678  {
3679  s << "(";
3680 
3681  switch (getTransitionStyle())
3682  {
3683  case LGL_TRANSITION_NEAREST: s << "nearest"; break;
3684  case LGL_TRANSITION_LINEAR: s << "linear"; break;
3685  case LGL_TRANSITION_COS: s << "cos-lerp"; break;
3686  case LGL_TRANSITION_ATAN: s << "atan-lerp"; break;
3687  }
3688 
3689  s << ")";
3690  }
3691 
3692  return(s.str());
3693  }
3694 
3695  virtual std::string to_label() const
3696  {
3697  lgl_string label = lgl_AnimationNode::to_label();
3698 
3699  switch (getTransitionStyle())
3700  {
3701  case LGL_TRANSITION_NEAREST: label += "\\nnearest"; break;
3702  case LGL_TRANSITION_LINEAR: label += "\\nlinear"; break;
3703  case LGL_TRANSITION_COS: label += "\\ncos-lerp"; break;
3704  case LGL_TRANSITION_ATAN: label += "\\natan-lerp"; break;
3705  }
3706 
3707  return(label.strip("\\n"));
3708  }
3709 
3710 };
3711 
3716 {
3717 public:
3718 
3720  lgl_TranslationTransitionNode(const vec3 &translation, double seconds,
3721  const std::string &id = "",
3722  lgl_Node *node = NULL)
3723  : lgl_TransitionNode(fabs(1/seconds), translation, id, node)
3724  {}
3725 
3726  virtual std::string getClassId() const {return("TranslationTransition");}
3727 
3728 protected:
3729 
3730  virtual mat4 animate(double animation, const vec3 &vector)
3731  {
3732  double w = transition(animation + 0.5);
3733  return(mat4::translate(w * vector));
3734  }
3735 
3736 public:
3737 
3738  virtual std::string to_label() const
3739  {
3740  return(lgl_string(lgl_TransitionNode::to_label() + "\\nT").strip("\\n"));
3741  }
3742 
3743 };
3744 
3749 {
3750 public:
3751 
3753  lgl_RotationTransitionNode(double angle, const vec3 &axis, double seconds,
3754  const std::string &id = "",
3755  lgl_Node *node = NULL)
3756  : lgl_TransitionNode(fabs(1/seconds), axis, id, node),
3757  angle_(angle)
3758  {}
3759 
3760  virtual std::string getClassId() const {return("RotationTransition");}
3761 
3762 protected:
3763 
3764  double angle_;
3765 
3766  virtual mat4 animate(double animation, const vec3 &axis)
3767  {
3768  double w = transition(animation + 0.5);
3769  return(mat4::rotate(angle_ * w, axis));
3770  }
3771 
3772 public:
3773 
3774  virtual std::string to_label() const
3775  {
3776  return(lgl_string(lgl_TransitionNode::to_label() + "\\nR").strip("\\n"));
3777  }
3778 
3779 };
3780 
3785 {
3786 public:
3787 
3789  lgl_ScaleTransitionNode(double scale, double seconds,
3790  const vec3 &axis = vec3(1),
3791  const std::string &id = "",
3792  lgl_Node *node = NULL)
3793  : lgl_TransitionNode(fabs(1/seconds), axis, id, node),
3794  from_(1), to_(scale)
3795  {}
3796 
3798  lgl_ScaleTransitionNode(double from, double to, double seconds,
3799  const vec3 &axis = vec3(1),
3800  const std::string &id = "",
3801  lgl_Node *node = NULL)
3802  : lgl_TransitionNode(fabs(1/seconds), axis, id, node),
3803  from_(from), to_(to)
3804  {}
3805 
3806  virtual std::string getClassId() const {return("ScaleTransition");}
3807 
3808 protected:
3809 
3810  double from_, to_;
3811 
3812  virtual mat4 animate(double animation, const vec3 &axis)
3813  {
3814  double w = transition(animation + 0.5);
3815  double s = (1-w)*from_ + w*to_;
3816  return(mat4::scale(s * axis));
3817  }
3818 
3819 public:
3820 
3821  virtual std::string to_label() const
3822  {
3823  return(lgl_string(lgl_TransitionNode::to_label() + "\\nS").strip("\\n"));
3824  }
3825 
3826 };
3827 
3834 {
3835 public:
3836 
3839  bool scale = true,
3840  const std::string &id = "",
3841  lgl_Node *node = NULL)
3842  : lgl_AnimationNode(omega, vec3(0), 0, 0, 0, id, node),
3843  scale_(scale)
3844  {}
3845 
3846  virtual std::string getClassId() const {return("WarpAnimation");}
3847 
3848 protected:
3849 
3850  bool scale_;
3851 
3852  virtual void init()
3853  {
3854  restart(0);
3855  }
3856 
3857  virtual mat4 animate(double animation, const vec3 &axis)
3858  {
3859  vec3 f = front(animation);
3860  vec3 b = back(animation);
3861  vec3 u = up(animation);
3862 
3863  return(mat4::transform(b, f, u, scale_));
3864  }
3865 
3866  virtual std::string to_label() const
3867  {
3868  return(lgl_string(lgl_AnimationNode::to_label() + "\\nW").strip("\\n"));
3869  }
3870 
3871  virtual vec3 front(double animation) = 0;
3872  virtual vec3 back(double animation) = 0;
3873  virtual vec3 up(double animation) = 0;
3874 };
3875 
3876 inline bool lgl_TransformationNode::optimize()
3877 {
3878  bool optimizable = true;
3879 
3880  if (dynamic_cast<lgl_AnimationNode*>(this))
3881  optimizable = false;
3882 
3883  bool textrans = false;
3884 
3885  if (dynamic_cast<lgl_TextureTransformationNode*>(this))
3886  textrans = true;
3887 
3888  for (unsigned int i=0; i<children_.size(); i++)
3889  if (follow(i))
3890  {
3891  lgl_Node *node = get(i);
3892  lgl_TransformationNode *trans = dynamic_cast<lgl_TransformationNode*>(node);
3893  lgl_VBONode *vbo = dynamic_cast<lgl_VBONode*>(node);
3894 
3895  if (!trans && !vbo)
3896  optimizable = false;
3897  else if (trans)
3898  {
3899  if (dynamic_cast<lgl_AnimationNode*>(trans))
3900  optimizable = false;
3901 
3902  if (!textrans && dynamic_cast<lgl_TextureTransformationNode*>(trans))
3903  optimizable = false;
3904 
3905  if (textrans && !dynamic_cast<lgl_TextureTransformationNode*>(trans))
3906  optimizable = false;
3907  }
3908  else
3909  {
3910  if (!node->leaf())
3911  optimizable = false;
3912  }
3913  }
3914 
3915  if (optimizable)
3916  for (unsigned int i=0; i<children_.size(); i++)
3917  if (follow(i))
3918  {
3919  lgl_Node *node = get(i);
3920 
3921  if (lgl_TransformationNode *trans = dynamic_cast<lgl_TransformationNode*>(node))
3922  {
3923  mat4 m = getTransformation() * trans->getTransformation();
3924  trans->setTransformation(m);
3925  }
3926  else if (lgl_VBONode *vbo = dynamic_cast<lgl_VBONode*>(node))
3927  {
3928  if (!textrans)
3929  {
3930  mat4 m = getTransformation();
3931  vbo->lglModel(m);
3932  vbo->lglApplyModelMatrix();
3933  }
3934  else
3935  {
3936  mat4 m = lglGetTexMatrix();
3937  vbo->lglTex(m);
3938  vbo->lglApplyTexMatrix();
3939  }
3940  }
3941  }
3942 
3943  return(optimizable);
3944 }
3945 
3946 inline void lgl_ActionNode::trigger_children(bool override)
3947 {
3948  if (enabled_)
3949  {
3950  for (unsigned int i=0; i<children_.size(); i++)
3951  {
3952  if (lgl_AnimationNode *anim=dynamic_cast<lgl_AnimationNode*>(children_[i]))
3953  switch (getActionMode())
3954  {
3955  case LGL_ACTION_PAUSE: anim->pause(override); break;
3956  case LGL_ACTION_RESUME: anim->resume(override); break;
3957  case LGL_ACTION_DIRECTION: anim->direction(override); break;
3958  default: break;
3959  }
3960  else if (lgl_ControllableNode *ctrl=dynamic_cast<lgl_ControllableNode*>(children_[i]))
3961  switch (getActionMode())
3962  {
3963  case LGL_ACTION_ON: ctrl->enable(); break;
3964  case LGL_ACTION_OFF: ctrl->disable(); break;
3965  case LGL_ACTION_ENABLE: ctrl->enable(override); break;
3966  case LGL_ACTION_DISABLE: ctrl->disable(override); break;
3967  case LGL_ACTION_HIDE: ctrl->hide(override); break;
3968  case LGL_ACTION_SHOW: ctrl->show(override); break;
3969  default: break;
3970  }
3971  }
3972  }
3973 }
3974 
3980 {
3981 public:
3982 
3984  lgl_LightNode(vec4f light = vec4f(0,0,1,0), bool camera_light = true,
3985  vec3f ka = vec3f(0.1f), vec3f kd = vec3f(0.7f), vec3f ks = vec3f(0.2f),
3986  vec3f Ia = vec3f(1), vec3f Id = vec3f(1), vec3f Is = vec3f(1),
3987  float exponent = 30, vec3f falloff = vec3f(1,0,0),
3988  const std::string &id = "",
3989  lgl_Node *node = NULL)
3990  : lgl_ControllableNode(id, node),
3991  light_(light),
3992  camera_light_(camera_light),
3993  ka_(ka), kd_(kd), ks_(ks),
3994  Ia_(Ia), Id_(Id), Is_(Is),
3995  exponent_(exponent),
3996  falloff_(falloff)
3997  {}
3998 
3999  virtual ~lgl_LightNode() {}
4000 
4001  virtual std::string getClassId() const {return("Light");}
4002 
4005  {
4006  return(light_);
4007  }
4008 
4010  void setLightVector(vec4f light)
4011  {
4012  light_ = light;
4013  }
4014 
4017  {
4018  light_ = vec4f(light, 0);
4019  }
4020 
4023  {
4024  light_ = vec4f(light, 1);
4025  }
4026 
4028  bool isCameraLight() const
4029  {
4030  return(camera_light_);
4031  }
4032 
4034  void getLightParameters(vec3f &ka, vec3f &kd, vec3f &ks,
4035  vec3f &Ia, vec3f &Id, vec3f &Is,
4036  float &exponent, vec3f &falloff) const
4037  {
4038  ka = ka_;
4039  kd = kd_;
4040  ks = ks_;
4041 
4042  Ia = Ia_;
4043  Id = Id_;
4044  Is = Is_;
4045 
4046  exponent = exponent_;
4047  falloff = falloff_;
4048  }
4049 
4051  void setLightParameters(vec3f ka = vec3f(0.1f), vec3f kd = vec3f(0.7f), vec3f ks = vec3f(0.2f),
4052  vec3f Ia = vec3f(1), vec3f Id = vec3f(1), vec3f Is = vec3f(1),
4053  float exponent = 30, vec3f falloff = vec3f(1,0,0))
4054  {
4055  ka_ = ka;
4056  kd_ = kd;
4057  ks_ = ks;
4058 
4059  Ia_ = Ia;
4060  Id_ = Id;
4061  Is_ = Is;
4062 
4063  exponent_ = exponent;
4064  falloff_ = falloff;
4065  }
4066 
4067 protected:
4068 
4069  vec4f light_;
4070  bool camera_light_;
4071  vec3f ka_, kd_, ks_;
4072  vec3f Ia_, Id_, Is_;
4073  float exponent_;
4074  vec3f falloff_;
4075 
4076  virtual void render()
4077  {
4078  if (hidden_) return;
4079 
4080  GL *gl = getGL();
4081 
4082  bool lighting(false);
4083  vec4f light(0);
4084  vec3f ka(0), kd(0), ks(0);
4085  vec3f Ia(0), Id(0), Is(0);
4086  float exponent(0);
4087  vec3f falloff(0);
4088 
4089  if (enabled_)
4090  {
4091  lighting = gl->lglGetLighting();
4092  light = gl->lglGetLightVector();
4093  gl->lglGetLightParameters(ka, kd, ks, Ia, Id, Is, exponent, falloff);
4094 
4095  gl->lglLighting(true);
4096  gl->lglLightVector(light_, camera_light_);
4097  gl->lglLightParameters(ka_, kd_, ks_, Ia_, Id_, Is_, exponent_, falloff_);
4098  }
4099 
4100  lgl_Node::render();
4101 
4102  if (enabled_)
4103  {
4104  gl->lglLighting(lighting);
4105  gl->lglLightVector(light);
4106  gl->lglLightParameters(ka, kd, ks, Ia, Id, Is, exponent, falloff);
4107  }
4108  }
4109 
4110 public:
4111 
4112  virtual std::string to_string(bool classname = true) const
4113  {
4114  std::stringstream s;
4115 
4116  s << lgl_ControllableNode::to_string(classname);
4117 
4118  s << "(";
4119  s << "vec4" << getLightVector() << ", " << (isCameraLight()?"cam":"world") << ", ";
4120  s << "vec3" << ka_ << ", " << "vec3" << kd_ << "vec3" << ks_ << ", ";
4121  s << "vec3" << Ia_ << ", " << "vec3" << Id_ << "vec3" << Is_ << ", ";
4122  s << exponent_ << ", " << "vec3" << falloff_;
4123  s << ")";
4124 
4125  return(s.str());
4126  }
4127 
4128  virtual std::string to_label() const
4129  {
4130  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ')).strip("\\n"));
4131  }
4132 
4133 };
4134 
4139 {
4140 public:
4141 
4143  lgl_LightSourceNode(vec4f light = vec4f(0,0,1,0), bool camera_light = true,
4144  vec3f Ia = vec3f(1), vec3f Id = vec3f(1), vec3f Is = vec3f(1),
4145  vec3f falloff = vec3f(1,0,0),
4146  const std::string &id = "",
4147  lgl_Node *node = NULL)
4148  : lgl_ControllableNode(id, node), lgl_LightSource()
4149  {
4150  setLightVector(light, camera_light);
4151  setLightSourceParameters(Ia, Id, Is, falloff);
4152  }
4153 
4154  virtual ~lgl_LightSourceNode() {}
4155 
4156  virtual std::string getClassId() const {return("LightSource");}
4157 
4158 protected:
4159 
4160  virtual void render()
4161  {
4162  if (hidden_) return;
4163 
4164  GL *gl = getGL();
4165 
4166  bool lighting(false);
4167  vec4f light(0);
4168  vec3f Ia(0), Id(0), Is(0);
4169  vec3f falloff(0);
4170 
4171  if (enabled_)
4172  {
4173  lighting = gl->lglGetLighting();
4174  light = gl->lglGetLightVector();
4175  gl->lglGetLightSourceParameters(Ia, Id, Is, falloff);
4176 
4177  gl->lglLighting(true);
4178  gl->lglLightVector(light_, camera_light_);
4179  gl->lglLightSourceParameters(Ia_, Id_, Is_, falloff_);
4180  }
4181 
4182  lgl_Node::render();
4183 
4184  if (enabled_)
4185  {
4186  gl->lglLighting(lighting);
4187  gl->lglLightVector(light);
4188  gl->lglLightSourceParameters(Ia, Id, Is, falloff);
4189  }
4190  }
4191 
4192 public:
4193 
4194  virtual std::string to_string(bool classname = true) const
4195  {
4196  std::stringstream s;
4197 
4198  s << lgl_ControllableNode::to_string(classname);
4199 
4200  s << "(";
4201  s << "vec4" << getLightVector() << ", " << (isCameraLight()?"cam":"world") << ", ";
4202  s << "vec3" << Ia_ << ", " << "vec3" << Id_ << "vec3" << Is_ << ", ";
4203  s << "vec3" << falloff_;
4204  s << ")";
4205 
4206  return(s.str());
4207  }
4208 
4209  virtual std::string to_label() const
4210  {
4211  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ')).strip("\\n"));
4212  }
4213 
4214 };
4215 
4220 {
4221 public:
4222 
4224  lgl_MaterialNode(vec3f ka = vec3f(0.1f), vec3f kd = vec3f(0.7f), vec3f ks = vec3f(0.2f),
4225  float exponent = 30,
4226  const std::string &id = "",
4227  lgl_Node *node = NULL)
4228  : lgl_ControllableNode(id, node), lgl_Material()
4229  {
4230  setMaterialParameters(ka, kd, ks, exponent);
4231  }
4232 
4233  virtual ~lgl_MaterialNode() {}
4234 
4235  virtual std::string getClassId() const {return("Material");}
4236 
4237 protected:
4238 
4239  virtual void render()
4240  {
4241  if (hidden_) return;
4242 
4243  GL *gl = getGL();
4244 
4245  vec3f ka(0), kd(0), ks(0);
4246  float exponent(0);
4247 
4248  if (enabled_)
4249  {
4250  gl->lglGetMaterialParameters(ka, kd, ks, exponent);
4251  gl->lglMaterialParameters(ka_, kd_, ks_, exponent_);
4252  }
4253 
4254  lgl_Node::render();
4255 
4256  if (enabled_)
4257  {
4258  gl->lglMaterialParameters(ka, kd, ks, exponent);
4259  }
4260  }
4261 
4262 public:
4263 
4264  virtual std::string to_string(bool classname = true) const
4265  {
4266  std::stringstream s;
4267 
4268  s << lgl_ControllableNode::to_string(classname);
4269 
4270  s << "(";
4271  s << "vec3" << ka_ << ", " << "vec3" << kd_ << "vec3" << ks_ << ", ";
4272  s << exponent_;
4273  s << ")";
4274 
4275  return(s.str());
4276  }
4277 
4278  virtual std::string to_label() const
4279  {
4280  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ')).strip("\\n"));
4281  }
4282 
4283 };
4284 
4289 {
4290 public:
4291 
4293  lgl_Texture2DNode(GLuint texid = 0,
4294  const std::string &id = "",
4295  lgl_Node *node = NULL)
4296  : lgl_ControllableNode(id, node),
4297  texid_(texid)
4298  {}
4299 
4300  virtual ~lgl_Texture2DNode() {}
4301 
4302  virtual std::string getClassId() const {return("Texture2D");}
4303 
4304  GLuint getTexId() const
4305  {
4306  return(texid_);
4307  }
4308 
4309  void setTexId(GLuint texid)
4310  {
4311  texid_ = texid;
4312  }
4313 
4314 protected:
4315 
4316  GLuint texid_;
4317 
4318  virtual void render()
4319  {
4320  if (hidden_) return;
4321 
4322  GL *gl = getGL();
4323 
4324  bool texturing = false;
4325  GLuint texid2D = 0;
4326  GLuint texid3D = 0;
4327 
4328  if (texid_!=0 && enabled_)
4329  {
4330  texturing = gl->lglGetTexturing();
4331  texid2D = gl->lglGetTexture2D();
4332  texid3D = gl->lglGetTexture3D();
4333 
4334  gl->lglTexture2D(texid_);
4335  gl->lglTexturing(true);
4336  }
4337 
4338  lgl_Node::render();
4339 
4340  if (texid_!=0 && enabled_)
4341  {
4342  gl->lglTexturing(texturing);
4343  gl->lglTexture2D(texid2D);
4344  gl->lglTexture3D(texid3D);
4345  }
4346  }
4347 
4348 public:
4349 
4350  virtual std::string to_string(bool classname = true) const
4351  {
4352  std::stringstream s;
4353 
4354  s << lgl_ControllableNode::to_string(classname);
4355 
4356  if (getTexId() != 0)
4357  s << "(" << getTexId() << ")";
4358 
4359  return(s.str());
4360  }
4361 
4362  virtual std::string to_label() const
4363  {
4364  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ')).strip("\\n"));
4365  }
4366 
4367 };
4368 
4373 {
4374 public:
4375 
4377  lgl_Texture3DNode(GLuint texid = 0,
4378  const std::string &id = "",
4379  lgl_Node *node = NULL)
4380  : lgl_ControllableNode(id, node),
4381  texid_(texid)
4382  {}
4383 
4384  virtual ~lgl_Texture3DNode() {}
4385 
4386  virtual std::string getClassId() const {return("Texture3D");}
4387 
4388  GLuint getTexId() const
4389  {
4390  return(texid_);
4391  }
4392 
4393  void setTexId(GLuint texid)
4394  {
4395  texid_ = texid;
4396  }
4397 
4398 protected:
4399 
4400  GLuint texid_;
4401 
4402  virtual void render()
4403  {
4404  if (hidden_) return;
4405 
4406  GL *gl = getGL();
4407 
4408  bool texturing = false;
4409  GLuint texid2D = 0;
4410  GLuint texid3D = 0;
4411 
4412  if (texid_!=0 && enabled_)
4413  {
4414  texturing = gl->lglGetTexturing();
4415  texid2D = gl->lglGetTexture2D();
4416  texid3D = gl->lglGetTexture3D();
4417 
4418  gl->lglTexture3D(texid_);
4419  gl->lglTexturing(true);
4420  }
4421 
4422  lgl_Node::render();
4423 
4424  if (texid_!=0 && enabled_)
4425  {
4426  gl->lglTexturing(texturing);
4427  gl->lglTexture2D(texid2D);
4428  gl->lglTexture3D(texid3D);
4429  }
4430  }
4431 
4432 public:
4433 
4434  virtual std::string to_string(bool classname = true) const
4435  {
4436  std::stringstream s;
4437 
4438  s << lgl_ControllableNode::to_string(classname);
4439 
4440  if (getTexId() != 0)
4441  s << "(" << getTexId() << ")";
4442 
4443  return(s.str());
4444  }
4445 
4446  virtual std::string to_label() const
4447  {
4448  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ')).strip("\\n"));
4449  }
4450 
4451 };
4452 
4457 {
4458 public:
4459 
4460  lgl_StateNode(bool state = true,
4461  const std::string &id = "",
4462  lgl_Node *node = NULL)
4463  : lgl_ControllableNode(id, node),
4464  state_(state)
4465  {}
4466 
4467  virtual ~lgl_StateNode() {}
4468 
4469  virtual std::string getClassId() const {return("State");}
4470 
4471  bool state() const
4472  {
4473  return(state_);
4474  }
4475 
4476  void change(bool state)
4477  {
4478  state_ = state;
4479  }
4480 
4481 protected:
4482 
4483  bool state_;
4484 
4485  virtual void render()
4486  {
4487  if (hidden_) return;
4488 
4489  bool state = false;
4490 
4491  if (enabled_)
4492  {
4493  state = saveState();
4494  setState(state_);
4495  }
4496 
4497  lgl_Node::render();
4498 
4499  if (enabled_)
4500  {
4501  restoreState(state);
4502  }
4503  }
4504 
4505  virtual bool getState() const = 0;
4506  virtual void setState(bool state) = 0;
4507 
4508  virtual bool saveState() {return(getState());}
4509  virtual void restoreState(bool state) {setState(state);}
4510 
4511 public:
4512 
4513  virtual std::string to_string(bool classname = true) const
4514  {
4515  std::stringstream s;
4516 
4517  s << lgl_ControllableNode::to_string(classname);
4518  s << "(" << (state()?"on":"off") << ")";
4519 
4520  return(s.str());
4521  }
4522 
4523  virtual std::string to_label() const
4524  {
4525  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ') + " " + (state()?"on":"off")).strip("\\n"));
4526  }
4527 
4528 };
4529 
4534 {
4535 public:
4536 
4537  lgl_DepthWriteNode(bool state = true,
4538  const std::string &id = "",
4539  lgl_Node *node = NULL)
4540  : lgl_StateNode(state, id, node)
4541  {}
4542 
4543  virtual std::string getClassId() const {return("DepthWrite");}
4544 
4545 protected:
4546 
4547  virtual bool getState() const
4548  {
4549  return(lglGetZWrite());
4550  }
4551 
4552  virtual void setState(bool state)
4553  {
4554  lglZWrite(state);
4555  }
4556 
4557 };
4558 
4563 {
4564 public:
4565 
4566  lgl_DepthTestNode(bool state = true,
4567  const std::string &id = "",
4568  lgl_Node *node = NULL)
4569  : lgl_StateNode(state, id, node)
4570  {}
4571 
4572  virtual std::string getClassId() const {return("DepthTest");}
4573 
4574 protected:
4575 
4576  virtual bool getState() const
4577  {
4578  return(lglGetDepthTest());
4579  }
4580 
4581  virtual void setState(bool state)
4582  {
4583  lglDepthTest(state);
4584  }
4585 
4586 };
4587 
4592 {
4593 public:
4594 
4595  lgl_BackFaceCullingNode(bool state = true,
4596  const std::string &id = "",
4597  lgl_Node *node = NULL)
4598  : lgl_StateNode(state, id, node)
4599  {}
4600 
4601  virtual std::string getClassId() const {return("BackFaceCulling");}
4602 
4603 protected:
4604 
4605  virtual bool getState() const
4606  {
4607  return(lglGetBackFaceCulling());
4608  }
4609 
4610  virtual void setState(bool state)
4611  {
4612  lglBackFaceCulling(state);
4613  }
4614 
4615 };
4616 
4621 {
4622 public:
4623 
4624  lgl_BlendingNode(lgl_blendmode_enum mode = LGL_BLEND_ADD,
4625  bool state = true,
4626  const std::string &id = "",
4627  lgl_Node *node = NULL)
4628  : lgl_StateNode(state, id, node),
4629  blend_mode_(mode)
4630  {}
4631 
4632  virtual std::string getClassId() const {return("Blending");}
4633 
4636  {
4637  return(blend_mode_);
4638  }
4639 
4640 protected:
4641 
4642  lgl_blendmode_enum blend_mode_;
4643 
4644  virtual bool getState() const
4645  {
4646  return(lglGetBlending());
4647  }
4648 
4649  virtual void setState(bool state)
4650  {
4651  lglBlendMode(blend_mode_);
4652  }
4653 
4654  virtual bool saveState()
4655  {
4656  saved_blend_mode_ = lglGetBlendMode();
4657  return(getState());
4658  }
4659 
4660  virtual void restoreState(bool state)
4661  {
4662  lglBlendMode(saved_blend_mode_);
4663  }
4664 
4665  lgl_blendmode_enum saved_blend_mode_;
4666 
4667 public:
4668 
4669  virtual std::string to_string(bool classname = true) const
4670  {
4671  std::stringstream s;
4672 
4673  std::string mode;
4674 
4675  switch (getBlendMode())
4676  {
4677  case LGL_BLEND_NONE : mode = "none"; break;
4678  case LGL_BLEND_MULT : mode = "mult"; break;
4679  case LGL_BLEND_ALPHA : mode = "alpha"; break;
4680  case LGL_BLEND_ADD : mode = "add"; break;
4681  case LGL_BLEND_SUB : mode = "sub"; break;
4682  case LGL_BLEND_MAX : mode = "max"; break;
4683  case LGL_BLEND_MIN : mode = "min"; break;
4684  }
4685 
4686  s << lgl_ControllableNode::to_string(classname);
4687  s << "(" << mode << ")";
4688 
4689  return(s.str());
4690  }
4691 
4692 };
4693 
4698 {
4699 public:
4700 
4701  lgl_AlphaTestNode(float alpha_value = 0,
4702  bool state = true,
4703  bool greater = true,
4704  bool equal = false,
4705  const std::string &id = "",
4706  lgl_Node *node = NULL)
4707  : lgl_StateNode(state, id, node),
4708  alpha_value_(alpha_value),
4709  alpha_greater_(greater),
4710  alpha_equal_(equal)
4711  {}
4712 
4713  virtual std::string getClassId() const {return("AlphaTest");}
4714 
4716  float getAlphaTestValue() const
4717  {
4718  return(alpha_value_);
4719  }
4720 
4722  bool getAlphaTestGreater() const
4723  {
4724  return(alpha_greater_);
4725  }
4726 
4728  bool getAlphaTestEqual() const
4729  {
4730  return(alpha_equal_);
4731  }
4732 
4733 protected:
4734 
4735  float alpha_value_;
4736  bool alpha_greater_;
4737  bool alpha_equal_;
4738 
4739  virtual bool getState() const
4740  {
4741  return(lglGetAlphaTest());
4742  }
4743 
4744  virtual void setState(bool state)
4745  {
4746  lglAlphaTest(state, alpha_value_, alpha_greater_, alpha_equal_);
4747  }
4748 
4749  virtual bool saveState()
4750  {
4751  saved_alpha_value_ = lglGetAlphaTestValue();
4752  saved_alpha_greater_ = lglGetAlphaTestGreater();
4753  saved_alpha_equal_ = lglGetAlphaTestEqual();
4754  return(getState());
4755  }
4756 
4757  virtual void restoreState(bool state)
4758  {
4759  lglAlphaTest(state, saved_alpha_value_, saved_alpha_greater_, saved_alpha_equal_);
4760  }
4761 
4762  float saved_alpha_value_;
4763  bool saved_alpha_greater_;
4764  bool saved_alpha_equal_;
4765 
4766 public:
4767 
4768  virtual std::string to_string(bool classname = true) const
4769  {
4770  std::stringstream s;
4771 
4772  s << lgl_StateNode::to_string(classname);
4773 
4774  if (state())
4775  s << "(" << getAlphaTestValue() << ", "
4776  << (getAlphaTestGreater()?"greater":"less") << ", "
4777  << (getAlphaTestEqual()?"equal":"inequal") << ")";
4778 
4779  return(s.str());
4780  }
4781 
4782 };
4783 
4788 {
4789 public:
4790 
4791  lgl_FogNode(float fog_density = 0,
4792  vec4f fog_color = vec4f(1,1,1),
4793  bool state = true,
4794  const std::string &id = "",
4795  lgl_Node *node = NULL)
4796  : lgl_StateNode(state, id, node),
4797  fog_density_(fog_density),
4798  fog_color_(fog_color)
4799  {}
4800 
4801  virtual std::string getClassId() const {return("Fog");}
4802 
4804  float getFogDensity() const
4805  {
4806  return(fog_density_);
4807  }
4808 
4811  {
4812  return(fog_color_);
4813  }
4814 
4815 protected:
4816 
4817  float fog_density_;
4818  vec4f fog_color_;
4819 
4820  virtual bool getState() const
4821  {
4822  return(lglGetFog());
4823  }
4824 
4825  virtual void setState(bool state)
4826  {
4827  if (state)
4828  lglFog(fog_density_, fog_color_);
4829  else
4830  lglFog();
4831  }
4832 
4833  virtual bool saveState()
4834  {
4835  saved_fog_density_ = lglGetFogDensity();
4836  saved_fog_color_ = lglGetFogColor();
4837  return(getState());
4838  }
4839 
4840  virtual void restoreState(bool state)
4841  {
4842  lglFog(saved_fog_density_, saved_fog_color_);
4843  }
4844 
4845  float saved_fog_density_;
4846  vec4f saved_fog_color_;
4847 
4848 public:
4849 
4850  virtual std::string to_string(bool classname = true) const
4851  {
4852  std::stringstream s;
4853 
4854  s << lgl_StateNode::to_string(classname);
4855 
4856  if (state())
4857  s << "(" << getFogDensity() << ", vec4" << getFogColor() << ")";
4858 
4859  return(s.str());
4860  }
4861 
4862 };
4863 
4868 {
4869 public:
4870 
4871  lgl_LineWidthNode(float width = 1,
4872  const std::string &id = "",
4873  lgl_Node *node = NULL)
4874  : lgl_StateNode(true, id, node),
4875  line_width_(width)
4876  {}
4877 
4878  virtual std::string getClassId() const {return("LineWidth");}
4879 
4881  float getLineWidth() const
4882  {
4883  return(line_width_);
4884  }
4885 
4886 protected:
4887 
4888  float line_width_;
4889 
4890  virtual bool getState() const
4891  {
4892  return(true);
4893  }
4894 
4895  virtual void setState(bool state)
4896  {}
4897 
4898  virtual bool saveState()
4899  {
4900  saved_line_width_ = lglGetLineWidth();
4901  return(getState());
4902  }
4903 
4904  virtual void restoreState(bool state)
4905  {
4906  lglLineWidth(saved_line_width_);
4907  }
4908 
4909  float saved_line_width_;
4910 
4911 public:
4912 
4913  virtual std::string to_string(bool classname = true) const
4914  {
4915  std::stringstream s;
4916 
4917  s << lgl_ControllableNode::to_string(classname);
4918  s << "(" << getLineWidth() << ")";
4919 
4920  return(s.str());
4921  }
4922 
4923 };
4924 
4929 {
4930 public:
4931 
4932  lgl_ColoringNode(bool state = true,
4933  const std::string &id = "",
4934  lgl_Node *node = NULL)
4935  : lgl_StateNode(state, id, node)
4936  {}
4937 
4938  virtual std::string getClassId() const {return("Coloring");}
4939 
4940 protected:
4941 
4942  virtual bool getState() const
4943  {
4944  GL *gl = getGL();
4945 
4946  return(gl->lglGetColoring());
4947  }
4948 
4949  virtual void setState(bool state)
4950  {
4951  GL *gl = getGL();
4952 
4953  gl->lglColoring(state);
4954  }
4955 
4956 };
4957 
4962 {
4963 public:
4964 
4965  lgl_LightingNode(bool state = true,
4966  const std::string &id = "",
4967  lgl_Node *node = NULL)
4968  : lgl_StateNode(state, id, node)
4969  {}
4970 
4971  virtual std::string getClassId() const {return("Lighting");}
4972 
4973 protected:
4974 
4975  virtual bool getState() const
4976  {
4977  GL *gl = getGL();
4978 
4979  return(gl->lglGetLighting());
4980  }
4981 
4982  virtual void setState(bool state)
4983  {
4984  GL *gl = getGL();
4985 
4986  gl->lglLighting(state);
4987  }
4988 
4989 };
4990 
4995 {
4996 public:
4997 
4998  lgl_TexturingNode(bool state = true,
4999  const std::string &id = "",
5000  lgl_Node *node = NULL)
5001  : lgl_StateNode(state, id, node)
5002  {}
5003 
5004  virtual std::string getClassId() const {return("Texturing");}
5005 
5006 protected:
5007 
5008  virtual bool getState() const
5009  {
5010  GL *gl = getGL();
5011 
5012  return(gl->lglGetTexturing());
5013  }
5014 
5015  virtual void setState(bool state)
5016  {
5017  GL *gl = getGL();
5018 
5019  gl->lglTexturing(state);
5020  }
5021 
5022 };
5023 
5029 {
5030 public:
5031 
5033  lgl_ClippingNode(vec4 equation = vec4(0,0,0,0),
5034  unsigned int n = 0,
5035  const std::string &id = "",
5036  lgl_Node *node = NULL)
5037  : lgl_ControllableNode(id, node),
5038  clipplane_(equation),
5039  n_(n)
5040  {}
5041 
5043  lgl_ClippingNode(vec3 point, vec3 normal,
5044  unsigned int n = 0,
5045  const std::string &id = "",
5046  lgl_Node *node = NULL)
5047  : lgl_ControllableNode(id, node),
5048  clipplane_(lglGetClipPlaneEquation(point, normal)),
5049  n_(n)
5050  {}
5051 
5053  lgl_ClippingNode(unsigned int n,
5054  const std::string &id = "",
5055  lgl_Node *node = NULL)
5056  : lgl_ControllableNode(id, node),
5057  clipplane_(vec4(0,0,0,0)),
5058  n_(n)
5059  {}
5060 
5061  virtual ~lgl_ClippingNode() {}
5062 
5063  virtual std::string getClassId() const {return("Clipping");}
5064 
5067  {
5068  return(clipplane_);
5069  }
5070 
5072  void setEquation(vec4 equation)
5073  {
5074  clipplane_ = equation;
5075  }
5076 
5078  void setClipPlane(vec3 point, vec3 normal)
5079  {
5080  clipplane_ = lglGetClipPlaneEquation(point, normal);
5081  }
5082 
5084  unsigned int getClipPlaneNumber() const
5085  {
5086  return(n_);
5087  }
5088 
5089 protected:
5090 
5091  vec4 clipplane_;
5092  unsigned int n_;
5093 
5094  virtual void render()
5095  {
5096  if (hidden_) return;
5097 
5098  vec4 equation(0,0,0,0);
5099 
5100  if (enabled_)
5101  {
5102  equation = lglGetClipPlaneEquation(n_);
5103  lglClipPlane(clipplane_, n_, false);
5104  }
5105 
5106  lgl_Node::render();
5107 
5108  if (enabled_)
5109  {
5110  lglClipPlane(equation, n_, true);
5111  }
5112  }
5113 
5114 public:
5115 
5116  virtual std::string to_string(bool classname = true) const
5117  {
5118  std::stringstream s;
5119 
5120  s << lgl_ControllableNode::to_string(classname);
5121 
5122  if (getEquation() != vec4(0,0,0,0))
5123  s << "(vec4" << getEquation() << ", " << getClipPlaneNumber() << ")";
5124  else
5125  s << "(off, " << getClipPlaneNumber() << ")";
5126 
5127  return(s.str());
5128  }
5129 
5130  virtual std::string to_label() const
5131  {
5132  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ') + " #" + glslmath::to_string(getClipPlaneNumber()) + " " + (getEquation()!=vec4(0,0,0,0)?"on":"off")).strip("\\n"));
5133  }
5134 
5135 };
5136 
5137 inline bool lgl_ColorNode::swappable()
5138 {
5139  bool swappable = false;
5140 
5141  if (children() == 1)
5142  if (dynamic_cast<lgl_StateNode*>(get()) ||
5143  dynamic_cast<lgl_ClippingNode*>(get()))
5144  swappable = true;
5145 
5146  return(swappable);
5147 }
5148 
5149 inline bool lgl_TransformationNode::swappable()
5150 {
5151  bool swappable = false;
5152 
5153  if (children() == 1)
5154  if (dynamic_cast<lgl_StateNode*>(get()) ||
5155  dynamic_cast<lgl_ClippingNode*>(get()))
5156  swappable = true;
5157 
5158  return(swappable);
5159 }
5160 
5165 {
5166 public:
5167 
5168  lgl_SwitcherNode(const std::string &id = "",
5169  lgl_Node *node = NULL)
5170  : lgl_ControllableNode(id, node),
5171  switch_(0)
5172  {}
5173 
5174  virtual ~lgl_SwitcherNode() {}
5175 
5176  virtual std::string getClassId() const {return("Switcher");}
5177 
5179  unsigned int getSwitch() const
5180  {
5181  return(switch_);
5182  }
5183 
5185  void setSwitch(unsigned int i)
5186  {
5187  switch_ = i;
5188  }
5189 
5191  void advance(int delta = 1)
5192  {
5193  unsigned int n = children_.size();
5194 
5195  if (n > 0)
5196  switch_ = (switch_+n+delta)%n;
5197  }
5198 
5199  virtual bool ordered() const
5200  {
5201  return(true);
5202  }
5203 
5204 protected:
5205 
5206  unsigned int switch_;
5207 
5208  virtual void render()
5209  {
5210  if (hidden_) return;
5211 
5212  if (enabled_)
5213  lgl_Node::render(switch_);
5214  else
5215  lgl_Node::render(0);
5216  }
5217 
5218  virtual void update(double dt)
5219  {
5220  if (enabled_)
5221  lgl_Node::update(switch_, dt);
5222  else
5223  lgl_Node::update(dt);
5224  }
5225 
5226  virtual void pick()
5227  {
5228  if (hidden_) return;
5229 
5230  if (enabled_)
5231  lgl_Node::pick(switch_);
5232  else
5233  lgl_Node::pick(0);
5234  }
5235 
5236 public:
5237 
5238  virtual std::string to_string(bool classname = true) const
5239  {
5240  std::stringstream s;
5241 
5242  s << lgl_ControllableNode::to_string(classname);
5243 
5244  if (classname)
5245  s << "(" << getSwitch() << ")";
5246 
5247  return(s.str());
5248  }
5249 
5250  virtual std::string to_label() const
5251  {
5252  return(lgl_string(lgl_ControllableNode::to_label() + "\\n" + lgl_string(getClassId()).toLower(' ')).strip("\\n"));
5253  }
5254 
5255 };
5256 
5261 {
5262 public:
5263 
5265  lgl_LevelOfDetailNode(double distance = 0,
5266  const std::string &id = "",
5267  lgl_Node *node = NULL)
5268  : lgl_SwitcherNode(id, node),
5269  distance_(distance)
5270  {}
5271 
5272  virtual ~lgl_LevelOfDetailNode() {}
5273 
5274  virtual std::string getClassId() const {return("LevelOfDetail");}
5275 
5276  double getDistance() const
5277  {
5278  return(distance_);
5279  }
5280 
5281  void setDistance(double distance)
5282  {
5283  distance_ = distance;
5284  }
5285 
5286 protected:
5287 
5288  double distance_;
5289 
5290  virtual void render()
5291  {
5292  if (hidden_) return;
5293 
5294  unsigned int i = 0;
5295  unsigned int n = children_.size();
5296 
5297  if (enabled_)
5298  if (distance_>0 && n>0)
5299  {
5300  static const double log2 = 1.0/log(2.0);
5301 
5302  mat4 mv = lglGetModelViewMatrix();
5303  vec3 o = mv * vec4(0);
5304 
5305  double d = o.length();
5306  double l = ceil(log(d/distance_)*log2);
5307 
5308  i = (unsigned int)l;
5309  if (i >= n) i = n-1;
5310  }
5311 
5312  setSwitch(i);
5314  }
5315 
5316 public:
5317 
5318  virtual std::string to_string(bool classname = true) const
5319  {
5320  std::stringstream s;
5321 
5322  s << lgl_ControllableNode::to_string(classname);
5323 
5324  if (classname)
5325  s << "(" << distance_ << ")";
5326 
5327  return(s.str());
5328  }
5329 
5330 };
5331 
5336 {
5337 public:
5338 
5339  lgl_SubgraphNode(const std::string &id = "",
5340  lgl_Node *node = NULL)
5341  : lgl_ControllableNode(id, node),
5342  graph_(NULL)
5343  {}
5344 
5345  virtual ~lgl_SubgraphNode()
5346  {
5347  if (graph_)
5348  delete graph_;
5349  }
5350 
5351  virtual std::string getClassId() const {return("Subgraph");}
5352 
5353  lgl_Node *getSubgraph()
5354  {
5355  if (!graph_)
5356  graph_ = createSubgraph();
5357 
5358  return(graph_);
5359  }
5360 
5361  void setSubgraph(lgl_Node *node)
5362  {
5363  if (graph_)
5364  delete graph_;
5365 
5366  graph_ = node;
5367  }
5368 
5369  virtual bool checkForCycles()
5370  {
5371  if (!graph_)
5372  graph_ = createSubgraph();
5373 
5374  if (graph_)
5375  if (graph_->checkForCycles())
5376  return(true);
5377 
5379  }
5380 
5381  virtual lgl_Node *find(const std::string &id)
5382  {
5383  if (!graph_)
5384  graph_ = createSubgraph();
5385 
5386  if (graph_)
5387  if (lgl_Node *node=graph_->find(id))
5388  return(node);
5389 
5390  return(lgl_ControllableNode::find(id));
5391  }
5392 
5393  virtual void getBoundingBox(vec3 &bboxmin, vec3 &bboxmax)
5394  {
5395  if (!graph_)
5396  graph_ = createSubgraph();
5397 
5398  lgl_ControllableNode::getBoundingBox(bboxmin, bboxmax);
5399 
5400  if (graph_ && enabled_)
5401  {
5402  vec3 bbmin, bbmax;
5403  graph_->getBoundingBox(bbmin, bbmax);
5404 
5405  growBoundingBox(bboxmin, bboxmax, bbmin);
5406  growBoundingBox(bboxmin, bboxmax, bbmax);
5407  }
5408  }
5409 
5410  virtual std::vector<vec4> getVertexCoordinates(mat4 trans = mat4())
5411  {
5412  if (!graph_)
5413  graph_ = createSubgraph();
5414 
5415  std::vector<vec4> geometry = lgl_ControllableNode::getVertexCoordinates(trans);
5416 
5417  if (graph_ && enabled_)
5418  {
5419  std::vector<vec4> geo = graph_->getVertexCoordinates(trans);
5420  geometry.insert(geometry.begin(), geo.begin(), geo.end());
5421  }
5422 
5423  return(geometry);
5424  }
5425 
5426  virtual bool saveSceneGraph(vec4 color, mat4 trans, FILE *file, int &index, int &nindex, int &tindex)
5427  {
5428  if (!graph_)
5429  graph_ = createSubgraph();
5430 
5431  bool ok = lgl_ControllableNode::saveSceneGraph(color, trans, file, index, nindex, tindex);
5432 
5433  if (graph_ && enabled_)
5434  if (!graph_->saveSceneGraph(color, trans, file, index, nindex, tindex)) ok = false;
5435 
5436  return(ok);
5437  }
5438 
5439  virtual unsigned int countAll()
5440  {
5441  unsigned int count = 0;
5442 
5443  if (!graph_)
5444  graph_ = createSubgraph();
5445 
5446  if (graph_)
5447  count += graph_->countAll();
5448 
5449  count += lgl_ControllableNode::countAll();
5450 
5451  return(count);
5452  }
5453 
5454  virtual unsigned int countAllOnce()
5455  {
5456  unsigned int count = 0;
5457 
5458  if (!graph_)
5459  graph_ = createSubgraph();
5460 
5461  if (graph_)
5462  count += graph_->countAllOnce();
5463 
5465 
5466  return(count);
5467  }
5468 
5469  virtual unsigned int countAllPrimitives()
5470  {
5471  unsigned int count = 0;
5472 
5473  if (!graph_)
5474  graph_ = createSubgraph();
5475 
5476  if (graph_)
5477  count += graph_->countAllPrimitives();
5478 
5480 
5481  return(count);
5482  }
5483 
5484  virtual unsigned int countAllVertices()
5485  {
5486  unsigned int count = 0;
5487 
5488  if (!graph_)
5489  graph_ = createSubgraph();
5490 
5491  if (graph_)
5492  count += graph_->countAllVertices();
5493 
5495 
5496  return(count);
5497  }
5498 
5499 protected:
5500 
5501  virtual void cleanAll()
5502  {
5503  if (!graph_)
5504  graph_ = createSubgraph();
5505 
5506  if (graph_)
5507  graph_->cleanAll();
5508 
5509  lgl_ControllableNode::cleanAll();
5510  }
5511 
5512  virtual unsigned int countOnce()
5513  {
5514  unsigned int count = 0;
5515 
5516  if (!graph_)
5517  graph_ = createSubgraph();
5518 
5519  if (graph_)
5520  count += graph_->countOnce();
5521 
5522  count += lgl_ControllableNode::countOnce();
5523 
5524  return(count);
5525  }
5526 
5527 public:
5528 
5529  virtual void optimizeAll()
5530  {
5531  if (!graph_)
5532  graph_ = createSubgraph();
5533 
5534  if (graph_)
5535  graph_->optimizeAll();
5536 
5538  }
5539 
5540  virtual void restartAll(double animation = 0)
5541  {
5542  if (!graph_)
5543  graph_ = createSubgraph();
5544 
5545  if (graph_)
5546  graph_->restartAll(animation);
5547 
5549  }
5550 
5551  virtual void pauseAll(bool yes = true)
5552  {
5553  if (!graph_)
5554  graph_ = createSubgraph();
5555 
5556  if (graph_)
5557  graph_->pauseAll(yes);
5558 
5560  }
5561 
5562  virtual void speedupAll(double speedup = 1)
5563  {
5564  if (!graph_)
5565  graph_ = createSubgraph();
5566 
5567  if (graph_)
5568  graph_->speedupAll(speedup);
5569 
5571  }
5572 
5573  virtual void finishAll()
5574  {
5575  if (!graph_)
5576  graph_ = createSubgraph();
5577 
5578  if (graph_)
5579  graph_->finishAll();
5580 
5582  }
5583 
5584 protected:
5585 
5586  lgl_Node *graph_;
5587 
5588  virtual void init()
5589  {
5590  if (!graph_)
5591  graph_ = createSubgraph();
5592  }
5593 
5594  virtual void pre_update(double dt)
5595  {
5596  if (graph_)
5597  graph_->pre_update(dt);
5598 
5599  lgl_ControllableNode::pre_update(dt);
5600  }
5601 
5602  virtual void pre_render()
5603  {
5604  if (graph_)
5605  graph_->pre_render();
5606 
5607  lgl_ControllableNode::pre_render();
5608  }
5609 
5610  virtual void render()
5611  {
5612  if (hidden_) return;
5613 
5614  if (graph_ && enabled_)
5615  graph_->render();
5616 
5618  }
5619 
5620  virtual void post_render()
5621  {
5622  if (graph_)
5623  graph_->post_render();
5624 
5625  lgl_ControllableNode::post_render();
5626  }
5627 
5628  virtual void update(double dt)
5629  {
5630  if (graph_)
5631  graph_->update(dt);
5632 
5634  }
5635 
5636  virtual void pick()
5637  {
5638  if (hidden_) return;
5639 
5640  if (graph_ && enabled_)
5641  graph_->pick();
5642 
5644  }
5645 
5646  virtual bool transparency()
5647  {
5648  if (!graph_)
5649  graph_ = createSubgraph();
5650 
5651  if (graph_ && enabled_)
5652  if (graph_->hasTransparency())
5653  return(true);
5654 
5655  return(false);
5656  }
5657 
5658  virtual lgl_Node *createSubgraph() {return(NULL);}
5659 };
5660 
5667 {
5668 public:
5669 
5670  lgl_OptimizingSubgraphNode(const std::string &id = "",
5671  lgl_Node *node = NULL)
5672  : lgl_SubgraphNode(id, node)
5673  {}
5674 
5675  virtual ~lgl_OptimizingSubgraphNode() {}
5676 
5677  virtual std::string getClassId() const {return("OptimizingSubgraph");}
5678 
5679 protected:
5680 
5681  virtual lgl_Node *createSubgraph()
5682  {
5683  lgl_Node *graph = lgl_SubgraphNode::createSubgraph();
5684 
5685  if (graph)
5686  {
5687  graph->optimizeAll();
5688 
5689  if (graph->checkForCycles())
5690  {
5691  delete graph;
5692  graph = NULL;
5693  }
5694  }
5695 
5696  return(graph);
5697  }
5698 
5699 };
5700 
5701 inline std::string lgl_Node::exportAll(lgl_export_enum mode, int indentation, int increment)
5702 {
5703  std::string s;
5704  unsigned int id = 0;
5705 
5706  bool tagged = false;
5707 
5708  // tag root
5709  if (getId() == "")
5710  {
5711  setId("root");
5712  tagged = true;
5713  }
5714 
5715  // init pass
5716  init_export(mode);
5717  scan_export(id, mode);
5718 
5719  // pre-export pass
5720  init_export(mode);
5721  s += pre_export(mode);
5722 
5723  // export pass
5724  init_export(mode);
5725  s += export_to_string(indentation, increment, mode);
5726 
5727  // post-export pass
5728  init_export(mode);
5729  s += post_export(mode);
5730 
5731  // cleanup pass
5732  clean_export(mode);
5733 
5734  // untag root
5735  if (tagged)
5736  setId();
5737 
5738  return(s);
5739 }
5740 
5741 inline void lgl_Node::init_export(lgl_export_enum mode)
5742 {
5743  if (mode != LGL_EXPORT_COMMANDS)
5744  cleanAll();
5745 }
5746 
5747 inline void lgl_Node::scan_export(unsigned int &id, lgl_export_enum mode)
5748 {
5749  if (mode != LGL_EXPORT_COMMANDS)
5750  {
5751  std::string prefix = "node-";
5752  if (mode == LGL_EXPORT_GRAPH) prefix = "#";
5753 
5754  if (visited_)
5755  {
5756  if (getAltId() == "")
5757  {
5758  id++;
5759  setAltId(prefix+glslmath::to_string(id));
5760  }
5761  }
5762  else
5763  {
5764  visited_ = true;
5765 
5766  if (mode == LGL_EXPORT_GRAPH)
5767  {
5768  if (getAltId() == "")
5769  {
5770  id++;
5771  setAltId(prefix+glslmath::to_string(id));
5772  }
5773  }
5774 
5775  for (unsigned int i=0; i<children_.size(); i++)
5776  if (follow(i))
5777  get(i)->scan_export(id, mode);
5778  else
5779  {
5780  if (get(i)->getAltId() == "")
5781  {
5782  id++;
5783  get(i)->setAltId(prefix+glslmath::to_string(id));
5784  }
5785  }
5786  }
5787  }
5788 }
5789 
5790 inline std::string lgl_Node::pre_export(lgl_export_enum mode)
5791 {
5792  std::stringstream s;
5793 
5794  if (mode == LGL_EXPORT_COMMANDS)
5795  {
5796  lgl_CameraNode *camera = dynamic_cast<lgl_CameraNode*>(this);
5797 
5798  for (unsigned int i=0; i<children_.size(); i++)
5799  if (follow(i))
5800  s << get(i)->pre_export(mode);
5801 
5802  if (camera)
5803  {
5804  std::string node = camera->to_string(mode != LGL_EXPORT_COMMANDS);
5805 
5806  if (node != "")
5807  s << node << std::endl;
5808  }
5809  }
5810  else if (mode == LGL_EXPORT_GRAPH)
5811  {
5812  s << "digraph" << std::endl;
5813  s << "{" << std::endl;
5814  s << "node[shape=oval]" << std::endl;
5815  s << "edge[color=\"#000070\"]" << std::endl;
5816  }
5817 
5818  return(s.str());
5819 }
5820 
5821 inline std::string lgl_Node::export_to_string(int indentation, int increment, lgl_export_enum mode)
5822 {
5823  std::stringstream s;
5824 
5825  if (visited_ && mode!=LGL_EXPORT_COMMANDS)
5826  {
5827  if (mode != LGL_EXPORT_GRAPH)
5828  s << glslmath::to_space(indentation) << "link(\"" << getAltId() << "\")" << std::endl;
5829  }
5830  else
5831  {
5832  if (mode != LGL_EXPORT_COMMANDS)
5833  visited_ = true;
5834 
5835  lgl_CameraNode *camera = dynamic_cast<lgl_CameraNode*>(this);
5836  lgl_TransformationNode *transformation = dynamic_cast<lgl_TransformationNode*>(this);
5837  lgl_TextureTransformationNode *textransformation = dynamic_cast<lgl_TextureTransformationNode*>(this);
5838  lgl_AnimationNode *animation = dynamic_cast<lgl_AnimationNode*>(this);
5839  lgl_SwitcherNode *switcher = dynamic_cast<lgl_SwitcherNode*>(this);
5840  lgl_LevelOfDetailNode *lod = dynamic_cast<lgl_LevelOfDetailNode*>(this);
5841  lgl_ControlNode *control = dynamic_cast<lgl_ControlNode*>(this);
5842  lgl_SteerNode *steer = dynamic_cast<lgl_SteerNode*>(this);
5843  lgl_BarrierNode *barrier = dynamic_cast<lgl_BarrierNode*>(this);
5844  lgl_ActionNode *action = dynamic_cast<lgl_ActionNode*>(this);
5845  lgl_ColorNode *color = dynamic_cast<lgl_ColorNode*>(this);
5846  lgl_GeometryNode *geo = dynamic_cast<lgl_GeometryNode*>(this);
5847  lgl_VBONode *vbo = dynamic_cast<lgl_VBONode*>(this);
5848 
5849  bool state = dynamic_cast<lgl_ColorNode*>(this) ||
5850  dynamic_cast<lgl_LightNode*>(this) ||
5851  dynamic_cast<lgl_Texture2DNode*>(this) ||
5852  dynamic_cast<lgl_Texture3DNode*>(this) ||
5853  dynamic_cast<lgl_StateNode*>(this) ||
5854  dynamic_cast<lgl_ClippingNode*>(this);
5855 
5856  std::string node = to_string(mode != LGL_EXPORT_COMMANDS);
5857  bool empty = node.empty();
5858 
5859  unsigned int c = 0;
5860  unsigned int n = children();
5861 
5862  if (mode == LGL_EXPORT_NODES)
5863  {
5864  if (!empty)
5865  {
5866  if (n == 1)
5867  s << glslmath::to_space(indentation) << node << " ->" << std::endl;
5868  else
5869  s << glslmath::to_space(indentation) << node << std::endl;
5870  }
5871 
5872  if (n > 1)
5873  s << glslmath::to_space(indentation) << "{" << std::endl;
5874 
5875  for (unsigned int i=c; i<n; i++)
5876  if (follow(i))
5877  s << get(i)->export_to_string(indentation+increment, increment, mode);
5878  else
5879  s << glslmath::to_space(indentation+increment) << "link(\"" << get(i)->getAltId() << "\")" << std::endl;
5880 
5881  if (n > 1)
5882  s << glslmath::to_space(indentation) << "}" << std::endl;
5883  }
5884  else if (mode == LGL_EXPORT_GRAPH)
5885  {
5886  std::string name = getAltId();
5887  if (lgl_string(name).replaceNonAlphaNumeric() != name) name = "\"" + name + "\"";
5888 
5889  std::string shape;
5890  std::string label = to_label();
5891 
5892  if (camera) shape = "star";
5893  else if (geo || vbo) shape = "triangle";
5894  else if (animation) shape = "doublecircle";
5895  else if (textransformation) shape = "circle,label=\"\",width=0.25";
5896  else if (transformation) shape = "circle,width=0.25";
5897  else if (color)
5898  {
5899  shape = "circle,style=filled,fillcolor=";
5900  char buf[10];
5901  snprintf(buf, 10, "\"#%02x%02x%02x\"", int(255*color->getColor().r), int(255*color->getColor().g), int(255*color->getColor().b));
5902  shape += buf;
5903  }
5904  else if (state) shape = "box";
5905  else if (lod) shape = "tripleoctagon";
5906  else if (switcher) shape = "doubleoctagon";
5907  else if (steer) shape = "hexagon";
5908  else if (control) shape = "diamond";
5909  else if (barrier) shape = "octagon";
5910  else if (action) shape = "diamond";
5911 
5912  s << glslmath::to_space(indentation) << name;
5913  s << "[label=\"" << label << "\"";
5914  if (shape != "") s << ",shape=" << shape;
5915  s << "]" << std::endl;
5916 
5917  if (n > 0)
5918  {
5919  s << glslmath::to_space(indentation) << name << " -> ";
5920 
5921  if (n > 1) s << "{ ";
5922 
5923  for (unsigned int i=c; i<n; i++)
5924  {
5925  std::string link = get(i)->getAltId();
5926  if (lgl_string(link).replaceNonAlphaNumeric() != link) link = "\"" + link + "\"";
5927 
5928  s << link;
5929  if (i < n-1) s << " ";
5930  }
5931 
5932  if (n > 1) s << " }";
5933 
5934  if (control || action) s << " [style=dashed]";
5935 
5936  s << std::endl;
5937  }
5938 
5939  for (unsigned int i=c; i<n; i++)
5940  if (follow(i))
5941  s << get(i)->export_to_string(indentation+increment, increment, mode);
5942  }
5943  else
5944  {
5945  if (disabled())
5946  empty = true;
5947 
5948  if (hidden())
5949  {
5950  empty = true;
5951  n = 0;
5952  }
5953 
5954  if (camera)
5955  {
5956  empty = true;
5957  }
5958  else if (switcher)
5959  {
5960  empty = true;
5961  c = switcher->getSwitch();
5962  if (c < n) n = c+1;
5963  else n = 0;
5964  }
5965  else if (control || action)
5966  {
5967  empty = true;
5968  n = 0;
5969  }
5970 
5971  int inc = increment;
5972  if (n<=1 && !transformation && !state) inc = 0;
5973  if (empty) inc = 0;
5974 
5975  if (!empty)
5976  {
5977  if (textransformation)
5978  s << glslmath::to_space(indentation) << "push_tex_matrix" << std::endl;
5979  else if (transformation)
5980  s << glslmath::to_space(indentation) << "push_matrix" << std::endl;
5981  else if (state)
5982  s << glslmath::to_space(indentation) << "push_state" << std::endl;
5983  }
5984 
5985  if (!empty)
5986  s << glslmath::to_space(indentation+inc) << node << std::endl;
5987 
5988  for (unsigned int i=c; i<n; i++)
5989  if (follow(i))
5990  s << get(i)->export_to_string(indentation+inc, increment, mode);
5991 
5992  if (!empty)
5993  {
5994  if (textransformation)
5995  s << glslmath::to_space(indentation) << "pop_tex_matrix" << std::endl;
5996  else if (transformation)
5997  s << glslmath::to_space(indentation) << "pop_matrix" << std::endl;
5998  else if (state)
5999  s << glslmath::to_space(indentation) << "pop_state" << std::endl;
6000  }
6001  }
6002  }
6003 
6004  return(s.str());
6005 }
6006 
6007 inline std::string lgl_Node::post_export(lgl_export_enum mode)
6008 {
6009  std::stringstream s;
6010 
6011  if (mode == LGL_EXPORT_GRAPH)
6012  {
6013  s << "}" << std::endl;
6014  }
6015 
6016  return(s.str());
6017 }
6018 
6019 inline void lgl_Node::clean_export(lgl_export_enum mode)
6020 {
6021  if (mode != LGL_EXPORT_COMMANDS)
6022  {
6023  visited_ = false;
6024 
6025  if (getAltId() != "")
6026  setAltId();
6027 
6028  for (unsigned int i=0; i<children_.size(); i++)
6029  if (follow(i))
6030  get(i)->clean_export(mode);
6031  else
6032  {
6033  if (getAltId() != "")
6034  get(i)->setAltId();
6035  }
6036  }
6037 }
6038 
6039 inline void lgl_Node::exportNodes(std::string filename)
6040 {
6041  lgl_string fn(filename);
6042  std::string suffix = fn.suffix(".");
6043  fn = fn.chop("."+suffix) + ".lgl";
6044  std::string graph = exportAll();
6045  lglWriteTextFile(fn, graph);
6046 }
6047 
6048 inline void lgl_Node::exportGraph(std::string filename)
6049 {
6050  lgl_string fn(filename);
6051  std::string suffix = fn.suffix(".");
6052  fn = fn.chop("."+suffix) + ".dot";
6053  std::string graph = exportAll(lgl_Node::LGL_EXPORT_GRAPH, 0, 1);
6054  lglWriteTextFile(fn, graph);
6055 }
6056 
6057 inline void lgl_Node::exportCommands(std::string filename)
6058 {
6059  lgl_string fn(filename);
6060  std::string suffix = fn.suffix(".");
6061  fn = fn.chop("."+suffix) + ".gl";
6062  std::string graph = exportAll(lgl_Node::LGL_EXPORT_COMMANDS, 0, 1);
6063  lglWriteTextFile(fn, graph);
6064 }
6065 
6066 #endif
lglSaveObjInto
bool lglSaveObjInto(lglVBO *vbo, FILE *file, int &index, int &nindex, int &tindex, bool flip_v=true)
save vbo to file descriptor
Definition: glvertex_objformat.h:661
lgl_Texture3DNode
3D texture node
Definition: glvertex_nodes.h:4372
lgl_BlendingNode
state change node (blending)
Definition: glvertex_nodes.h:4620
lgl_Node::hide
void hide(bool yes=true)
hide the node and its children
Definition: glvertex_nodes.h:309
lgl_CameraNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1926
vec3f
3D float vector
Definition: glslmath.h:584
lgl::lglMaterialParameters
void lglMaterialParameters(vec3f ka=vec3f(0.1f), vec3f kd=vec3f(0.7f), vec3f ks=vec3f(0.2f), float exponent=30)
set the material parameters
Definition: glvertex_core.h:4244
lgl_ControllableNode::lgl_control_mode_enum
lgl_control_mode_enum
control mode enum
Definition: glvertex_nodes.h:1209
lgl_string::strip
lgl_string strip(const std::string &match) const
strip match from begin
Definition: glvertex_string.h:75
lglBlendMode
void lglBlendMode(lgl_blendmode_enum mode)
change OpenGL state (blending)
Definition: glvertex_api.h:404
lgl_MaterialNode::lgl_MaterialNode
lgl_MaterialNode(vec3f ka=vec3f(0.1f), vec3f kd=vec3f(0.7f), vec3f ks=vec3f(0.2f), float exponent=30, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:4224
lgl_TransitionNode::enable
void enable(bool yes=true)
enable the node
Definition: glvertex_nodes.h:3554
lglAlphaTest
void lglAlphaTest(bool on=false, float value=0.0f, bool greater=true, bool equal=false)
change OpenGL state (alpha test)
Definition: glvertex_api.h:416
lgl::lglGetVertexCoordinates
std::vector< vec4 > lglGetVertexCoordinates() const
return a copy of the vertex coordinates in vbo
Definition: glvertex_core.h:1893
lgl_LightNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:4076
lgl_Node::disable
void disable(bool yes=true)
disable the node
Definition: glvertex_nodes.h:279
lgl_AnimationNode::restart
void restart(double animation=0)
restart the animation
Definition: glvertex_nodes.h:3093
lgl_Node::enabled
bool enabled() const
is the node enabled?
Definition: glvertex_nodes.h:261
lgl_Texture2DNode
2D texture node
Definition: glvertex_nodes.h:4288
lgl_Node::enable
void enable(bool yes=true)
enable the node
Definition: glvertex_nodes.h:273
lgl_Node::renderSceneGraph
void renderSceneGraph(double dt=0)
render and update the entire scene subgraph
Definition: glvertex_nodes.h:351
lgl_ActionNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1397
lgl_Node::setId
void setId(const std::string &id="")
set the node identifier
Definition: glvertex_nodes.h:94
lgl_Node::shared
bool shared() const
is the node shared?
Definition: glvertex_nodes.h:131
lgl_LightNode
light node
Definition: glvertex_nodes.h:3979
lgl_TransformationNode
transformation node
Definition: glvertex_nodes.h:2464
lgl_Material
Blinn-Phong material.
Definition: glvertex_light.h:155
lgl_AnimationNode::getVector
vec3 getVector() const
get the animation vector
Definition: glvertex_nodes.h:3033
lgl_ColorNode::getColor
vec4 getColor() const
get the color
Definition: glvertex_nodes.h:2361
lgl_LightNode::lgl_LightNode
lgl_LightNode(vec4f light=vec4f(0, 0, 1, 0), bool camera_light=true, vec3f ka=vec3f(0.1f), vec3f kd=vec3f(0.7f), vec3f ks=vec3f(0.2f), vec3f Ia=vec3f(1), vec3f Id=vec3f(1), vec3f Is=vec3f(1), float exponent=30, vec3f falloff=vec3f(1, 0, 0), const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3984
lgl::lglTex
void lglTex()
reset the vbo texturing matrix
Definition: glvertex_core.h:2577
lgl_GeometryNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1996
lgl_AnimationNode::stopOnLimit
void stopOnLimit()
stop on animation limit
Definition: glvertex_nodes.h:3051
lgl_Node::preupdateSceneGraph
void preupdateSceneGraph(double dt)
pre-update the entire scene subgraph
Definition: glvertex_nodes.h:404
lgl::lglGetLightVector
vec4 lglGetLightVector() const
get the light vector (in camera coordinates)
Definition: glvertex_core.h:4176
lgl::lglGetPrimitiveCount
int lglGetPrimitiveCount() const
get the number of primitives contained in vbo
Definition: glvertex_core.h:1796
lgl_FogNode::getFogColor
vec4f getFogColor() const
get the fog color
Definition: glvertex_nodes.h:4810
lgl_Cam::lgl_Cam
lgl_Cam()
ctor
Definition: glvertex_cam.h:16
lgl_BackFaceCullingNode
state change node (back-face culling)
Definition: glvertex_nodes.h:4591
lgl_SubgraphNode::getVertexCoordinates
virtual std::vector< vec4 > getVertexCoordinates(mat4 trans=mat4())
Definition: glvertex_nodes.h:5410
lglLineWidth
void lglLineWidth(float width=1.0f)
specify line width (as defined by OpenGL 1.2)
Definition: glvertex_api.h:164
lgl_GeometryNode::lgl_GeometryNode
lgl_GeometryNode(lglVBO *vbo=NULL, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:1983
lgl_Cam::end
void end() const
pop viewing and projection matrix
Definition: glvertex_cam.h:288
lgl_Node::optimizeAll
virtual void optimizeAll()
optimize all nodes
Definition: glvertex_nodes.h:1069
lgl_SubgraphNode::restartAll
virtual void restartAll(double animation=0)
restart all animations
Definition: glvertex_nodes.h:5540
lglGetFog
bool lglGetFog()
get OpenGL state (fog)
Definition: glvertex_api.h:448
lglGetBackFaceCulling
bool lglGetBackFaceCulling()
get OpenGL state (back-face culling)
Definition: glvertex_api.h:400
lgl_RotationAnimationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3489
lgl_AnimationNode::setSteerMode
void setSteerMode(lgl_animation_steer_mode_enum mode)
set the steer mode
Definition: glvertex_nodes.h:3201
lgl_LightNode::setLightDirection
void setLightDirection(vec3f light)
set the light direction
Definition: glvertex_nodes.h:4016
lgl_Node
scene graph node (base class)
Definition: glvertex_nodes.h:22
lgl_ColoringNode
state change node (coloring)
Definition: glvertex_nodes.h:4928
lgl_Node::link
void link(lgl_Node *node)
add the links of a node
Definition: glvertex_nodes.h:221
lgl_SubgraphNode::getBoundingBox
virtual void getBoundingBox(vec3 &bboxmin, vec3 &bboxmax)
get the bounding box of the entire subgraph
Definition: glvertex_nodes.h:5393
lglClipPlane
void lglClipPlane(vec4 equation=vec4(0, 0, 0, 0), unsigned int n=0, bool camera_plane=false)
specify clip plane (as defined by OpenGL 1.2)
Definition: glvertex_api.h:148
lgl_TransitionNode::disabled
bool disabled() const
is the node disabled?
Definition: glvertex_nodes.h:3548
lgl_TranslationTransitionNode::lgl_TranslationTransitionNode
lgl_TranslationTransitionNode(const vec3 &translation, double seconds, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3720
lgl_RotationAnimationNode::animate
virtual mat4 animate(double animation, const vec3 &axis)
to be implemented for a particular type of animation
Definition: glvertex_nodes.h:3493
lgl_string::chop
lgl_string chop(const std::string &match) const
chop match from end
Definition: glvertex_string.h:82
lgl::lglGetTexturing
bool lglGetTexturing() const
check for texturing
Definition: glvertex_core.h:3410
lgl_SteerNode
steer node
Definition: glvertex_nodes.h:1839
lglIsManipApplied
bool lglIsManipApplied()
is the manipulator matrix applied?
Definition: glvertex_api.h:328
lgl_Node::hidden
bool hidden() const
is the node hidden?
Definition: glvertex_nodes.h:297
lgl_Node::cloneable
bool cloneable() const
is the node cloneable?
Definition: glvertex_nodes.h:745
lgl_Node::countAllPrimitives
virtual unsigned int countAllPrimitives()
count all primitives
Definition: glvertex_nodes.h:664
lgl_BarrierNode::setRestartBarrier
void setRestartBarrier(bool yes=false)
set restart barrier
Definition: glvertex_nodes.h:1674
lgl_AlphaTestNode::getAlphaTestValue
float getAlphaTestValue() const
get the alpha test value
Definition: glvertex_nodes.h:4716
lgl_LightNode::setLightParameters
void setLightParameters(vec3f ka=vec3f(0.1f), vec3f kd=vec3f(0.7f), vec3f ks=vec3f(0.2f), vec3f Ia=vec3f(1), vec3f Id=vec3f(1), vec3f Is=vec3f(1), float exponent=30, vec3f falloff=vec3f(1, 0, 0))
set the light parameters
Definition: glvertex_nodes.h:4051
lgl_TextureTransformationNode
texture transformation node
Definition: glvertex_nodes.h:2893
lgl_LineWidthNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4878
lgl_SubgraphNode::finishAll
virtual void finishAll()
finish all transitions
Definition: glvertex_nodes.h:5573
lgl_ScaleNode::lgl_ScaleNode
lgl_ScaleNode(double c, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2829
lgl_BlendingNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4632
lgl_Node::update
virtual void update(double dt)
reimplement this method to update a node
Definition: glvertex_nodes.h:931
lgl_Node::leaf
bool leaf() const
is the node a leaf?
Definition: glvertex_nodes.h:119
lgl_Texture3DNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4386
lgl_LightSource::setLightSourceParameters
void setLightSourceParameters(vec3f Ia=vec3f(1), vec3f Id=vec3f(1), vec3f Is=vec3f(1), vec3f falloff=vec3f(1, 0, 0))
set the light source parameters
Definition: glvertex_light.h:104
lgl_SteerableNode
steerable node (base class)
Definition: glvertex_nodes.h:1800
lglGetManip
mat4 lglGetManip()
get the manipulator matrix
Definition: glvertex_api.h:324
lglGetFogColor
vec4f lglGetFogColor()
get OpenGL state (fog color)
Definition: glvertex_api.h:456
lgl_TextureTransformationNode::lgl_TextureTransformationNode
lgl_TextureTransformationNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2898
operator<<
std::ostream & operator<<(std::ostream &out, const lgl_Node &node)
output operator
Definition: glvertex_nodes.h:1192
lgl_string::suffix
std::string suffix(const std::string &match) const
get suffix after last substring match
Definition: glvertex_string.h:39
lgl_ClippingNode::lgl_ClippingNode
lgl_ClippingNode(vec4 equation=vec4(0, 0, 0, 0), unsigned int n=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:5033
lgl::lglRayCast
static void lglRayCast(lgl *vbo)
cast a ray and intersect it with the transformed triangles contained in the vbo
Definition: glvertex_core.h:4963
lgl_ControlNode::control
virtual void control(lgl_ControllableNode *ctrl, bool override)
reimplement to change control effect
Definition: glvertex_nodes.h:1585
lgl_TransformationNode::lgl_TransformationNode
lgl_TransformationNode(double angle, const vec3 &v, const std::string &id="", lgl_Node *node=NULL)
ctor (rotation)
Definition: glvertex_nodes.h:2495
lgl_AnimationNode::forward
void forward(double delta)
move the animation forward
Definition: glvertex_nodes.h:3141
lgl_Node::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:906
lgl_TransformationNode::transform
vec4 transform(const vec4 &p) const
transform a point
Definition: glvertex_nodes.h:2524
lgl_MaterialNode
light material node
Definition: glvertex_nodes.h:4219
lgl::lglGetLightSourceParameters
void lglGetLightSourceParameters(vec3f &Ia, vec3f &Id, vec3f &Is, vec3f &falloff) const
get the light source parameters
Definition: glvertex_core.h:4233
lgl_SteerNode::getSteerLevel
double getSteerLevel() const
get the steer level
Definition: glvertex_nodes.h:1855
lgl_ClippingNode::lgl_ClippingNode
lgl_ClippingNode(vec3 point, vec3 normal, unsigned int n=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:5043
lgl_FogNode::getFogDensity
float getFogDensity() const
get the fog density
Definition: glvertex_nodes.h:4804
lgl_Node::find
virtual lgl_Node * find(const std::string &id)
find a node with a specific identifier
Definition: glvertex_nodes.h:315
lgl_BarrierNode::setPauseBarrier
void setPauseBarrier(bool yes=false)
set pause barrier
Definition: glvertex_nodes.h:1686
lgl_Node::pick
virtual void pick()
reimplement this method to pick a node
Definition: glvertex_nodes.h:975
lgl_TransitionNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3539
lgl_AnimationNode::speedupAll
virtual void speedupAll(double speedup=1)
speedup all animations
Definition: glvertex_nodes.h:3344
lglEndRayCast
LGL_VBO_TYPE * lglEndRayCast()
end ray casting
Definition: glvertex_api.h:868
lgl_LightSourceNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4156
lgl_RotationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2782
lgl_ColorNode::lgl_ColorNode
lgl_ColorNode(double r, double g, double b, double a=1, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2333
lgl_TextureTransformationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2931
lgl_ColorNode::setColor
void setColor(const vec4 &c)
set the color
Definition: glvertex_nodes.h:2367
lgl_TransformationNode::lgl_TransformationNode
lgl_TransformationNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2469
lgl_LevelOfDetailNode
level-of-detail node
Definition: glvertex_nodes.h:5260
lgl_Node::find
T * find(const std::string &id)
find a node with a specific identifier and type
Definition: glvertex_nodes.h:345
lgl_Node::find
T * find()
find a node with a specific type
Definition: glvertex_nodes.h:330
lgl_LightSource::getLightVector
vec3f getLightVector() const
get light vector
Definition: glvertex_light.h:44
lgl_WarpAnimationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3846
lgl_Node::add
T * add(T *node)
add a child node with a specific type
Definition: glvertex_nodes.h:159
lgl_Node::shown
bool shown() const
is the node shown?
Definition: glvertex_nodes.h:291
lgl_GeometryNode::manage
void manage(bool yes=true)
manage the vbo
Definition: glvertex_nodes.h:2020
lgl_ScaleNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2858
lglBeginRayCast
void lglBeginRayCast(vec3 origin, vec3 direction, double mindist=0)
begin ray casting in view coordinates
Definition: glvertex_api.h:860
lgl_Node::unlink
void unlink()
remove the links of the node
Definition: glvertex_nodes.h:228
GL
LGL API: immediate mode class definition.
Definition: glvertex_core.h:5820
lgl_MaterialNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4235
lglGetFogDensity
float lglGetFogDensity()
get OpenGL state (fog density)
Definition: glvertex_api.h:452
vec4
4D double vector
Definition: glslmath.h:713
lgl_BarrierNode::setSpeedupBarrier
void setSpeedupBarrier(bool yes=false)
set speedup barrier
Definition: glvertex_nodes.h:1710
lgl_WarpAnimationNode::lgl_WarpAnimationNode
lgl_WarpAnimationNode(double omega, bool scale=true, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3838
lgl_TranslationNode::lgl_TranslationNode
lgl_TranslationNode(const vec3 &v, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2701
lgl::lglGetLightParameters
void lglGetLightParameters(vec3f &ka, vec3f &kd, vec3f &ks, vec3f &Ia, vec3f &Id, vec3f &Is, float &exponent, vec3f &falloff) const
get the light parameters
Definition: glvertex_core.h:4202
lgl_SwitcherNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:5176
mat4::rotate
static mat4 rotate(double angle, double vx, double vy, double vz)
create rotation matrix
Definition: glslmath.h:2446
lgl_LevelOfDetailNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:5290
lgl_Node::countAll
virtual unsigned int countAll()
count all nodes (count multiply linked nodes)
Definition: glvertex_nodes.h:641
lgl_ContainerNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2159
lgl_TransitionNode::setTransitionStyle
void setTransitionStyle(lgl_transition_enum style)
set transition style
Definition: glvertex_nodes.h:3621
lgl_AnimationNode::resume
virtual void resume(bool yes=true)
resume the animation
Definition: glvertex_nodes.h:3177
lgl_TexturingNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:5004
lgl_SubgraphNode::checkForCycles
virtual bool checkForCycles()
check for graph cycles
Definition: glvertex_nodes.h:5369
lgl::lglTexture3D
void lglTexture3D(GLuint texid, bool owner=false)
bind a 3D texture for the default GLSL program
Definition: glvertex_core.h:4282
lgl_Node::saveObj
bool saveObj(std::string filename)
save into OBJ file
Definition: glvertex_nodes.h:830
lgl_SteerNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1852
lgl_Node::getCenter
vec3 getCenter()
get the bounding box center of the entire subgraph
Definition: glvertex_nodes.h:483
lgl_StateNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4469
lgl_OptimizingSubgraphNode
optimizing subgraph node
Definition: glvertex_nodes.h:5666
norm
double norm(const vec2 &v)
get squared vector length
Definition: glslmath.h:225
lgl_Node::getGL
static GL * getGL()
get the scene graph GL singleton
Definition: glvertex_nodes.h:803
lgl_DepthTestNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4572
lgl_SubgraphNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:5610
lgl::lglGetBoundingBox
void lglGetBoundingBox(vec3 &bboxmin, vec3 &bboxmax) const
get the bounding box of the contained vertices in vbo
Definition: glvertex_core.h:1803
lgl_LightingNode
state change node (lighting)
Definition: glvertex_nodes.h:4961
lgl_Node::lgl_Node
lgl_Node(const std::string &id="")
default ctor
Definition: glvertex_nodes.h:27
lgl::lglAppliedColoring
bool lglAppliedColoring() const
check for applied vertex color attributes
Definition: glvertex_core.h:3322
lgl_AnimationNode::backward
void backward(double delta)
move the animation backward
Definition: glvertex_nodes.h:3153
lgl_Node::getRadius
double getRadius()
get the bounding sphere radius of the entire subgraph
Definition: glvertex_nodes.h:512
lgl_Cam::getProjectionMatrix
mat4 getProjectionMatrix() const
get projection matrix
Definition: glvertex_cam.h:237
lgl::lglGetTexture2D
GLuint lglGetTexture2D() const
get the bound 2D texture
Definition: glvertex_core.h:4276
glvertex.h
lgl::lglGetTexture3D
GLuint lglGetTexture3D() const
get the bound 3D texture
Definition: glvertex_core.h:4292
lgl_AnimationNode::reverse
void reverse()
reverse the animation
Definition: glvertex_nodes.h:3135
lgl_TransitionNode::disable
void disable(bool yes=true)
disable the node
Definition: glvertex_nodes.h:3564
lgl::lglLightVector
void lglLightVector(vec4f light=vec4f(0, 0, 1, 0), bool camera_light=true)
set the light vector
Definition: glvertex_core.h:4151
lglPopMatrix
void lglPopMatrix()
pop matrix (as defined by OpenGL 1.2)
Definition: glvertex_api.h:78
lgl_ClippingNode::setEquation
void setEquation(vec4 equation)
set the clip plane equation
Definition: glvertex_nodes.h:5072
lgl_DepthWriteNode
state change node (depth write)
Definition: glvertex_nodes.h:4533
lgl_ColorNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2358
lgl_AnimationNode::direction
void direction(bool forward)
set the direction of the animation
Definition: glvertex_nodes.h:3128
lgl_AnimationNode::lgl_animation_steer_mode_enum
lgl_animation_steer_mode_enum
animation steer mode enum
Definition: glvertex_nodes.h:2981
lgl_TransformationNode::transform
vec3 transform(const vec3 &p) const
transform a point
Definition: glvertex_nodes.h:2517
lglColor
void lglColor(const vec4f &c)
specify vertex color attribute (as defined by OpenGL 1.2)
Definition: glvertex_api.h:30
lgl_TransformationNode::scale
void scale(double x, double y, double z, double w=1)
set the transformation matrix (scale)
Definition: glvertex_nodes.h:2582
lgl_ScaleNode::lgl_ScaleNode
lgl_ScaleNode(double x, double y, double z, double w=1, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2839
lgl_AnimationNode::lgl_AnimationNode
lgl_AnimationNode(double delta=0, vec3 vector=vec3(0), double limit=0, double accel=0, double reverse=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3005
lgl_DepthWriteNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4543
lgl_VBONode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2177
lgl::lglLightSourceParameters
void lglLightSourceParameters(vec3f Ia=vec3f(1), vec3f Id=vec3f(1), vec3f Is=vec3f(1), vec3f falloff=vec3f(1, 0, 0))
set the light source parameters
Definition: glvertex_core.h:4219
lgl_GeometryNode::managed
bool managed()
is the vbo managed?
Definition: glvertex_nodes.h:2014
glvertex_cam.h
lglFog
void lglFog(float density=0.0f, vec4f color=vec4f(1))
specify fog (as defined by OpenGL 1.2)
Definition: glvertex_api.h:160
lgl::lglApplyColor
void lglApplyColor(const vec4f &c)
add a color channel to the vbo
Definition: glvertex_core.h:2626
lgl_TranslationTransitionNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3726
lgl_GeometryNode
geometry node
Definition: glvertex_nodes.h:1978
lgl_SubgraphNode::find
virtual lgl_Node * find(const std::string &id)
find a node with a specific identifier
Definition: glvertex_nodes.h:5381
lgl_TranslationAnimationNode::lgl_TranslationAnimationNode
lgl_TranslationAnimationNode(double delta, const vec3 &vector, double limit=0, double accel=0, double reverse=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3453
lglMultMatrix
void lglMultMatrix(const mat4 &matrix)
multiply with matrix (as defined by OpenGL 1.2)
Definition: glvertex_api.h:70
lgl_Node::disabled
bool disabled() const
is the node disabled?
Definition: glvertex_nodes.h:267
lgl_AnimationNode::restartAll
virtual void restartAll(double animation=0)
restart all animations
Definition: glvertex_nodes.h:3332
lgl_AnimationNode::getDelta
double getDelta() const
get the animation delta
Definition: glvertex_nodes.h:3027
lgl_ActionNode::setActionMode
void setActionMode(lgl_action_mode_enum mode)
set the action mode
Definition: glvertex_nodes.h:1412
lgl_AnimationNode::getAcceleration
double getAcceleration() const
get the animation acceleration
Definition: glvertex_nodes.h:3075
lgl_AnimationNode::steer
virtual void steer(double level, bool override=true)
apply the steer level as specified by the steer mode
Definition: glvertex_nodes.h:3207
lgl_SwitcherNode::pick
virtual void pick()
reimplement this method to pick a node
Definition: glvertex_nodes.h:5226
lgl_ScaleNode
scale node
Definition: glvertex_nodes.h:2824
lgl_ClippingNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:5063
lgl_TransformationNode::scale
void scale(const vec4 &c)
set the transformation matrix (scale)
Definition: glvertex_nodes.h:2590
length
double length(const vec2 &v)
get vector length
Definition: glslmath.h:221
lgl_ScaleTransitionNode::lgl_ScaleTransitionNode
lgl_ScaleTransitionNode(double from, double to, double seconds, const vec3 &axis=vec3(1), const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3798
lgl_ScaleNode::getScale
vec4 getScale() const
get the scale vector
Definition: glvertex_nodes.h:2861
lgl_SubgraphNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:5351
lgl_Node::getAltId
std::string getAltId() const
get the alternate node identifier
Definition: glvertex_nodes.h:100
lgl_Node::lgl_Node
lgl_Node(const lgl_Node &node)
copy ctor
Definition: glvertex_nodes.h:39
lgl_TransformationNode::scale
void scale(double c)
set the transformation matrix (scale)
Definition: glvertex_nodes.h:2575
lgl_TextureTransformationNode::lgl_TextureTransformationNode
lgl_TextureTransformationNode(const vec3 &v, const std::string &id="", lgl_Node *node=NULL)
ctor (translation)
Definition: glvertex_nodes.h:2911
lgl_TransitionNode::setSpeedup
virtual void setSpeedup(double speedup=1)
set the animation speedup
Definition: glvertex_nodes.h:3588
lgl_TransformationNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:2601
lgl_Cam::getViewMatrix
mat4 getViewMatrix(bool left=true) const
get viewing matrix
Definition: glvertex_cam.h:246
lgl_LightNode::getLightVector
vec3f getLightVector() const
get the light vector
Definition: glvertex_nodes.h:4004
lgl_WarpAnimationNode
animation node (warp)
Definition: glvertex_nodes.h:3833
lgl_LightSourceNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:4160
lgl_BarrierNode::setResumeBarrier
void setResumeBarrier(bool yes=false)
set resume barrier
Definition: glvertex_nodes.h:1698
lgl_LightSourceNode
light source node
Definition: glvertex_nodes.h:4138
lgl_Material::setMaterialParameters
void setMaterialParameters(vec3f ka=vec3f(0.1f), vec3f kd=vec3f(0.7f), vec3f ks=vec3f(0.2f), float exponent=30)
set the material parameters
Definition: glvertex_light.h:213
lgl_TransitionNode::control
virtual void control(bool override=true)
control the node as specified by the control mode
Definition: glvertex_nodes.h:3591
lgl_TransitionNode::getTransitionStyle
lgl_transition_enum getTransitionStyle() const
get transition style
Definition: glvertex_nodes.h:3615
lgl::lglColoring
void lglColoring(bool on)
enable or disable the vertex color attributes contained in vbo
Definition: glvertex_core.h:3353
lgl_CameraNode
camera node
Definition: glvertex_nodes.h:1914
lgl_BarrierNode::lgl_BarrierNode
lgl_BarrierNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:1654
lgl_string
LGL string class that extends std::string.
Definition: glvertex_string.h:12
lgl_ScaleTransitionNode::lgl_ScaleTransitionNode
lgl_ScaleTransitionNode(double scale, double seconds, const vec3 &axis=vec3(1), const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3789
lgl_AlphaTestNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4713
lglGetTexMatrix
mat4 lglGetTexMatrix()
get the vbo texturing matrix
Definition: glvertex_api.h:356
lgl_ActionNode::control
virtual void control(bool override=true)
trigger the controllable child nodes
Definition: glvertex_nodes.h:1400
lgl_TransformationNode::lgl_TransformationNode
lgl_TransformationNode(double scale, const std::string &id="", lgl_Node *node=NULL)
ctor (scale)
Definition: glvertex_nodes.h:2504
lglDepthTest
void lglDepthTest(bool on=false)
change OpenGL state (depth test)
Definition: glvertex_api.h:388
lgl_Texture3DNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:4402
lgl_WarpAnimationNode::animate
virtual mat4 animate(double animation, const vec3 &axis)
to be implemented for a particular type of animation
Definition: glvertex_nodes.h:3857
lgl_Node::exportNodes
void exportNodes(std::string filename)
export graph nodes
Definition: glvertex_nodes.h:6039
lgl::lglLightParameters
void lglLightParameters(vec3f ka=vec3f(0.1f), vec3f kd=vec3f(0.7f), vec3f ks=vec3f(0.2f), vec3f Ia=vec3f(1), vec3f Id=vec3f(1), vec3f Is=vec3f(1), float exponent=30, vec3f falloff=vec3f(1, 0, 0))
set the light parameters
Definition: glvertex_core.h:4182
lgl_ClippingNode::setClipPlane
void setClipPlane(vec3 point, vec3 normal)
set the clip plane
Definition: glvertex_nodes.h:5078
lgl_Node::exportCommands
void exportCommands(std::string filename)
export graphics commands
Definition: glvertex_nodes.h:6057
lglGetBlending
bool lglGetBlending()
get OpenGL state (blending)
Definition: glvertex_api.h:408
lgl_RotationNode::lgl_RotationNode
lgl_RotationNode(double angle, double x, double y, double z, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2771
lgl_string::remove
lgl_string remove(const std::string &start, const std::string &stop)
remove fragment between start and stop delimiters
Definition: glvertex_string.h:89
lgl_TransitionNode
transition node (base class)
Definition: glvertex_nodes.h:3509
lgl_SubgraphNode
subgraph node
Definition: glvertex_nodes.h:5335
lgl_LightSource::setLightVector
void setLightVector(vec4f light, bool camera_light=true)
set light vector
Definition: glvertex_light.h:37
lgl_TransformationNode::lgl_TransformationNode
lgl_TransformationNode(const vec3 &v, const std::string &id="", lgl_Node *node=NULL)
ctor (translation)
Definition: glvertex_nodes.h:2486
lgl_TransitionNode::finish
virtual void finish()
finish ongoing transition
Definition: glvertex_nodes.h:3627
lgl_SwitcherNode::update
virtual void update(double dt)
reimplement this method to update a node
Definition: glvertex_nodes.h:5218
vec3
3D double vector
Definition: glslmath.h:372
glvertex_objformat.h
lgl_ActionNode
action node
Definition: glvertex_nodes.h:1370
lgl_TextureTransformationNode::lgl_TextureTransformationNode
lgl_TextureTransformationNode(const mat4 &m, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2904
lgl_MaterialNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:4239
lgl_Node::updateSceneGraph
void updateSceneGraph(double dt)
update the entire scene subgraph
Definition: glvertex_nodes.h:410
lgl_TranslationAnimationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3459
lgl_BarrierNode::getResumeBarrier
bool getResumeBarrier() const
get resume barrier
Definition: glvertex_nodes.h:1692
mat4
4x4 double matrix
Definition: glslmath.h:2116
lgl_Node::countAllOnce
virtual unsigned int countAllOnce()
count all nodes (count multiply linked nodes once)
Definition: glvertex_nodes.h:653
lgl_LightNode::setLightVector
void setLightVector(vec4f light)
set the light vector
Definition: glvertex_nodes.h:4010
lgl_Node::optimizable
bool optimizable() const
is the node optimizable?
Definition: glvertex_nodes.h:751
lglBackFaceCulling
void lglBackFaceCulling(bool on=true)
change OpenGL state (back-face culling)
Definition: glvertex_api.h:396
lgl::lglGetLighting
bool lglGetLighting() const
check for lighting
Definition: glvertex_core.h:3389
lgl_ControlNode::control
virtual void control(bool override=true)
override the controllable child nodes
Definition: glvertex_nodes.h:1512
lgl_AlphaTestNode
state change node (alpha testing)
Definition: glvertex_nodes.h:4697
lgl_SwitcherNode::ordered
virtual bool ordered() const
is the node ordered?
Definition: glvertex_nodes.h:5199
lgl_SwitcherNode
switcher node
Definition: glvertex_nodes.h:5164
lgl_Texture2DNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4302
lglError
void lglError(std::string e)
generate an error message
Definition: glvertex_api.h:928
lgl_TransitionNode::lgl_TransitionNode
lgl_TransitionNode(double delta, const vec3 &vector, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3523
lgl_Node::pickSceneGraph
lglVBO * pickSceneGraph(vec3 origin, vec3 direction, double mindist=0)
pick the entire scene subgraph
Definition: glvertex_nodes.h:614
lgl_LightSourceNode::lgl_LightSourceNode
lgl_LightSourceNode(vec4f light=vec4f(0, 0, 1, 0), bool camera_light=true, vec3f Ia=vec3f(1), vec3f Id=vec3f(1), vec3f Is=vec3f(1), vec3f falloff=vec3f(1, 0, 0), const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:4143
lgl_TranslationAnimationNode::animate
virtual mat4 animate(double animation, const vec3 &vector)
to be implemented for a particular type of animation
Definition: glvertex_nodes.h:3463
lgl_BarrierNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1665
lgl_LineWidthNode::getLineWidth
float getLineWidth() const
get the line width
Definition: glvertex_nodes.h:4881
lgl_SubgraphNode::pick
virtual void pick()
reimplement this method to pick a node
Definition: glvertex_nodes.h:5636
lgl_Texture2DNode::lgl_Texture2DNode
lgl_Texture2DNode(GLuint texid=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:4293
lgl_RotationTransitionNode::lgl_RotationTransitionNode
lgl_RotationTransitionNode(double angle, const vec3 &axis, double seconds, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3753
lgl::getName
std::string getName() const
get the vbo name
Definition: glvertex_core.h:203
lglGetAlphaTest
bool lglGetAlphaTest()
get OpenGL state (alpha test)
Definition: glvertex_api.h:420
vec4f
4D float vector
Definition: glslmath.h:961
lgl_ScaleTransitionNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3806
lgl::lglGetMaterialParameters
void lglGetMaterialParameters(vec3f &ka, vec3f &kd, vec3f &ks, float &exponent) const
get the material parameters
Definition: glvertex_core.h:4255
lgl_ClippingNode::lgl_ClippingNode
lgl_ClippingNode(unsigned int n, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:5053
lgl::lglGetColoring
bool lglGetColoring() const
check for coloring
Definition: glvertex_core.h:3368
lgl_ClippingNode::getEquation
vec4 getEquation() const
get the clip plane equation
Definition: glvertex_nodes.h:5066
lgl_ControllableNode::getControlMode
lgl_control_mode_enum getControlMode() const
get the control mode
Definition: glvertex_nodes.h:1257
lgl_SteerNode::setSteerLevel
void setSteerLevel(double level)
set the steer level
Definition: glvertex_nodes.h:1861
lgl_AnimationNode::getReverse
double getReverse() const
get the reverse acceleration after limit has been reached
Definition: glvertex_nodes.h:3081
lgl_SubgraphNode::optimizeAll
virtual void optimizeAll()
optimize all nodes
Definition: glvertex_nodes.h:5529
lgl_Node::exportAll
std::string exportAll(lgl_export_enum mode=LGL_EXPORT_NODES, int indentation=0, int increment=3)
export all nodes
Definition: glvertex_nodes.h:5701
lgl_LightNode::getLightParameters
void getLightParameters(vec3f &ka, vec3f &kd, vec3f &ks, vec3f &Ia, vec3f &Id, vec3f &Is, float &exponent, vec3f &falloff) const
get the light parameters
Definition: glvertex_nodes.h:4034
lgl_LightNode::isCameraLight
bool isCameraLight() const
is the light source a camera light?
Definition: glvertex_nodes.h:4028
lgl_ActionNode::lgl_ActionNode
lgl_ActionNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:1390
lgl_ActionNode::getActionMode
lgl_action_mode_enum getActionMode() const
get the action mode
Definition: glvertex_nodes.h:1406
lgl_ControllableNode::lgl_ControllableNode
lgl_ControllableNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:1225
lglMatrixMode
void lglMatrixMode(lgl_matrixmode_enum mode=LGL_MODELVIEW)
specify matrix mode (as defined by OpenGL 1.2)
Definition: glvertex_api.h:58
lgl_VBONode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:2188
lgl_Cam::begin
void begin(bool left=true) const
push viewing and projection matrix
Definition: glvertex_cam.h:273
lgl_LevelOfDetailNode::lgl_LevelOfDetailNode
lgl_LevelOfDetailNode(double distance=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:5265
lgl_TransitionNode::steer
virtual void steer(double level, bool override=true)
apply the steer level as specified by the steer mode
Definition: glvertex_nodes.h:3604
lgl_Node::references
unsigned int references() const
get the number of references to the node
Definition: glvertex_nodes.h:125
lgl_SteerableNode::steer
virtual void steer(double level, bool override=true)
apply the steer level
Definition: glvertex_nodes.h:1815
lgl_ControlNode::lgl_ControlNode
lgl_ControlNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:1500
lgl_BarrierNode::getPauseBarrier
bool getPauseBarrier() const
get pause barrier
Definition: glvertex_nodes.h:1680
lgl_blendmode_enum
lgl_blendmode_enum
blend mode enum
Definition: glvertex_core.h:70
lgl_TransformationNode::translate
void translate(const vec3 &v)
set the transformation matrix (translation)
Definition: glvertex_nodes.h:2544
lgl_TranslationNode::getTranslation
vec3 getTranslation() const
get the translation vector
Definition: glvertex_nodes.h:2723
lgl_RotationTransitionNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3760
lgl_TextureTransformationNode::pick
virtual void pick()
reimplement this method to pick a node
Definition: glvertex_nodes.h:2959
lgl_GeometryNode::setVBO
void setVBO(lglVBO *vbo)
set the vbo
Definition: glvertex_nodes.h:2005
lgl_ControlNode::update
virtual void update(double dt)
reimplement this method to update a node
Definition: glvertex_nodes.h:1598
lgl_RotationAnimationNode::lgl_RotationAnimationNode
lgl_RotationAnimationNode(double omega, const vec3 &axis, double limit=0, double accel=0, double reverse=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:3483
lgl_VBONode::stateless
virtual bool stateless() const
is the node stateless?
Definition: glvertex_nodes.h:2179
lgl_RotationNode
rotation node
Definition: glvertex_nodes.h:2755
lglGetAlphaTestGreater
bool lglGetAlphaTestGreater()
get OpenGL state (alpha test comparison mode)
Definition: glvertex_api.h:428
lgl_VBONode
vbo node
Definition: glvertex_nodes.h:2165
lgl_Node::getId
std::string getId() const
get the node identifier
Definition: glvertex_nodes.h:88
lgl_Node::ordered
virtual bool ordered() const
is the node ordered?
Definition: glvertex_nodes.h:733
lgl_Node::replace
void replace(lgl_Node *node, unsigned int i=0)
replace a child of the node
Definition: glvertex_nodes.h:188
lgl_TransformationNode::pick
virtual void pick()
reimplement this method to pick a node
Definition: glvertex_nodes.h:2657
lgl_Node::getNorm
double getNorm()
get the bounding sphere norm of the entire subgraph
Definition: glvertex_nodes.h:527
lglGetAlphaTestEqual
bool lglGetAlphaTestEqual()
get OpenGL state (alpha test equality mode)
Definition: glvertex_api.h:432
lgl_ColorNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:2383
lgl_ColorNode::lgl_ColorNode
lgl_ColorNode(const vec4 &color=vec4(1, 1, 1), const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2349
lgl_TransformationNode::translate
void translate(double x, double y, double z)
set the transformation matrix (translation)
Definition: glvertex_nodes.h:2551
lgl_TranslationTransitionNode::animate
virtual mat4 animate(double animation, const vec3 &vector)
to be implemented for a particular type of animation
Definition: glvertex_nodes.h:3730
lgl_RotationNode::getRotationAxis
vec3 getRotationAxis() const
get the rotation axis
Definition: glvertex_nodes.h:2791
lgl_ClippingNode
clipping node
Definition: glvertex_nodes.h:5028
lgl_ColorNode::hasTransparency
virtual bool hasTransparency()
check for transparency
Definition: glvertex_nodes.h:2373
lgl_TransformationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2514
lgl::lglApplyTexMatrix
void lglApplyTexMatrix()
apply the vbo texturing matrix to the vbo and reset the matrix
Definition: glvertex_core.h:2603
lgl::lglRender
virtual void lglRender(const lgl *vbo=NULL)
render the series of vertices contained in vbo
Definition: glvertex_core.h:1079
lgl_BarrierNode::getRestartBarrier
bool getRestartBarrier() const
get restart barrier
Definition: glvertex_nodes.h:1668
lgl_RotationNode::lgl_RotationNode
lgl_RotationNode(double angle, const vec3 &axis, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2760
lgl_Node::drawSceneGraph
void drawSceneGraph(const mat4 &m)
draw the entire scene subgraph without updating
Definition: glvertex_nodes.h:381
lgl_AnimationNode::setSpeedup
virtual void setSpeedup(double speedup=1)
set the animation speedup
Definition: glvertex_nodes.h:3189
lgl_AnimationNode::paused
virtual bool paused() const
is the animation paused?
Definition: glvertex_nodes.h:3165
lgl_BlendingNode::getBlendMode
lgl_blendmode_enum getBlendMode() const
get the blend mode
Definition: glvertex_nodes.h:4635
lgl_Node::~lgl_Node
virtual ~lgl_Node()
dtor
Definition: glvertex_nodes.h:69
lgl_Node::getBoundingSphere
double getBoundingSphere(vec3 &center)
get the bounding sphere of the entire subgraph
Definition: glvertex_nodes.h:466
lgl_ControllableNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1235
lgl_StateNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:4485
lgl_GeometryNode::stateless
virtual bool stateless() const
is the node stateless?
Definition: glvertex_nodes.h:2036
lgl_BarrierNode::pauseAll
virtual void pauseAll(bool yes=true)
pause all animations
Definition: glvertex_nodes.h:1721
vec3::length
double length() const
get vector length
Definition: glslmath.h:420
lgl_Node::show
void show(bool yes=true)
show the node and its children
Definition: glvertex_nodes.h:303
lgl::lglLighting
void lglLighting(bool on)
enable or disable the vertex normal attributes contained in vbo
Definition: glvertex_core.h:3374
lgl_StateNode
state change node (base class)
Definition: glvertex_nodes.h:4456
lgl_LineWidthNode
state change node (line width)
Definition: glvertex_nodes.h:4867
lgl_Node::getVertexCoordinates
virtual std::vector< vec4 > getVertexCoordinates(mat4 trans=mat4())
Definition: glvertex_nodes.h:542
lgl_TextureTransformationNode::lgl_TextureTransformationNode
lgl_TextureTransformationNode(double scale, const std::string &id="", lgl_Node *node=NULL)
ctor (scale)
Definition: glvertex_nodes.h:2925
mat4::scale
static mat4 scale(double s, double t, double r, double w=1.0)
create scaling matrix
Definition: glslmath.h:2409
lgl_SwitcherNode::setSwitch
void setSwitch(unsigned int i)
set the switch index
Definition: glvertex_nodes.h:5185
lgl_Node::setAltId
void setAltId(const std::string &id="")
set the alternate node identifier
Definition: glvertex_nodes.h:107
lgl_ContainerNode
geometry container node
Definition: glvertex_nodes.h:2146
lgl_AnimationNode::signalOnStop
void signalOnStop()
signal on stop
Definition: glvertex_nodes.h:3063
lgl_ScaleTransitionNode::animate
virtual mat4 animate(double animation, const vec3 &axis)
to be implemented for a particular type of animation
Definition: glvertex_nodes.h:3812
lgl_ColoringNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4938
lgl::lglTexture2D
void lglTexture2D(GLuint texid, bool owner=false)
bind a 2D texture for the default GLSL program
Definition: glvertex_core.h:4266
lglVBO
LGL API: vbo class definition.
Definition: glvertex_core.h:5827
lgl_GeometryNode::pick
virtual void pick()
reimplement this method to pick a node
Definition: glvertex_nodes.h:2086
lgl_SwitcherNode::getSwitch
unsigned int getSwitch() const
get the switch index
Definition: glvertex_nodes.h:5179
lgl_TexturingNode
state change node (texturing)
Definition: glvertex_nodes.h:4994
lgl_GeometryNode::getVBO
lglVBO * getVBO() const
get the vbo
Definition: glvertex_nodes.h:1999
lgl_Texture2DNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:4318
lgl_ControlNode::finish
virtual void finish()
finish pending control signal
Definition: glvertex_nodes.h:1536
lgl_AnimationNode::getSteerMode
lgl_animation_steer_mode_enum getSteerMode() const
get the steer mode
Definition: glvertex_nodes.h:3195
lglGetBlendMode
lgl_blendmode_enum lglGetBlendMode()
get OpenGL state (blend mode)
Definition: glvertex_api.h:412
lgl_AnimationNode::animation
double animation() const
get the actual animation state
Definition: glvertex_nodes.h:3087
lgl_AnimationNode::speedup
virtual double speedup()
get the animation speedup
Definition: glvertex_nodes.h:3183
lgl_Cam
camera convenience class
Definition: glvertex_cam.h:11
lgl_Node::remove
void remove(unsigned int i=0)
remove a child from the node
Definition: glvertex_nodes.h:171
lgl_BarrierNode::getSpeedupBarrier
bool getSpeedupBarrier() const
get speedup barrier
Definition: glvertex_nodes.h:1704
lgl_VBONode::pick
virtual void pick()
reimplement this method to pick a node
Definition: glvertex_nodes.h:2228
lgl_TranslationNode
translation node
Definition: glvertex_nodes.h:2696
lgl_TranslationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:2720
lgl_RotationTransitionNode::animate
virtual mat4 animate(double animation, const vec3 &axis)
to be implemented for a particular type of animation
Definition: glvertex_nodes.h:3766
lgl_AnimationNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:3024
lgl_SubgraphNode::pauseAll
virtual void pauseAll(bool yes=true)
pause all animations
Definition: glvertex_nodes.h:5551
lgl_TransitionNode::toggle
void toggle()
toggle the node
Definition: glvertex_nodes.h:3574
lgl_Node::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:85
lgl_AnimationNode
animation node (base class)
Definition: glvertex_nodes.h:2976
lgl_Node::take
lgl_Node * take(unsigned int i=0)
unlink a child and take ownership
Definition: glvertex_nodes.h:201
lgl_Node::getExtent
vec3 getExtent()
get the bounding box extent of the entire subgraph
Definition: glvertex_nodes.h:497
lgl_LightSource::isCameraLight
bool isCameraLight() const
is the light source a camera light?
Definition: glvertex_light.h:50
lgl_SteerableNode::lgl_SteerableNode
lgl_SteerableNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:1805
lgl_Node::pauseAll
virtual void pauseAll(bool yes=true)
pause all animations
Definition: glvertex_nodes.h:777
lgl_AlphaTestNode::getAlphaTestGreater
bool getAlphaTestGreater() const
get the alpha test comparison mode
Definition: glvertex_nodes.h:4722
lgl_RotationNode::getRotationAngle
double getRotationAngle() const
get the rotation angle
Definition: glvertex_nodes.h:2785
lgl_Node::get
lgl_Node * get(unsigned int i=0) const
get a child node
Definition: glvertex_nodes.h:137
lgl_ControllableNode::setControlMode
void setControlMode(lgl_control_mode_enum mode)
set the control mode
Definition: glvertex_nodes.h:1263
lgl_TransformationNode::getTransformation
mat4 getTransformation() const
get the transformation matrix
Definition: glvertex_nodes.h:2531
lgl_TransformationNode::setTransformation
void setTransformation(const mat4 &m)
set the transformation matrix
Definition: glvertex_nodes.h:2537
lglZWrite
void lglZWrite(bool on=true)
change OpenGL state (depth write)
Definition: glvertex_api.h:380
lgl_DepthTestNode
state change node (depth test)
Definition: glvertex_nodes.h:4562
lglGetClipPlaneEquation
vec4 lglGetClipPlaneEquation(unsigned int n=0)
get OpenGL state (clip plane equation)
Definition: glvertex_api.h:440
lglPushMatrix
void lglPushMatrix()
push matrix (as defined by OpenGL 1.2)
Definition: glvertex_api.h:74
lgl_Node::hasTransparency
bool hasTransparency()
check the entire subgraph whether or not it contains semi-transparent geometry
Definition: glvertex_nodes.h:628
lgl_TransitionNode::pause
virtual void pause(bool yes=true)
pause the animation
Definition: glvertex_nodes.h:3582
lglGetAlphaTestValue
float lglGetAlphaTestValue()
get OpenGL state (alpha test value)
Definition: glvertex_api.h:424
lgl_SubgraphNode::update
virtual void update(double dt)
reimplement this method to update a node
Definition: glvertex_nodes.h:5628
lgl::lglModel
void lglModel()
reset the vbo modeling matrix
Definition: glvertex_core.h:2525
lgl_TranslationAnimationNode
animation node (translation)
Definition: glvertex_nodes.h:3448
lgl_Node::countAllVertices
unsigned int countAllVertices()
count all vertices
Definition: glvertex_nodes.h:681
lgl_Texture3DNode::lgl_Texture3DNode
lgl_Texture3DNode(GLuint texid=0, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:4377
lgl_TranslationTransitionNode
animation node (translation transition)
Definition: glvertex_nodes.h:3715
lgl_AnimationNode::getStopOnLimit
bool getStopOnLimit() const
get stop on animation limit
Definition: glvertex_nodes.h:3057
lgl_TransitionNode::enabled
bool enabled() const
is the node enabled?
Definition: glvertex_nodes.h:3542
lgl_Node::exportGraph
void exportGraph(std::string filename)
export link graph
Definition: glvertex_nodes.h:6048
lgl::lglApplyModelMatrix
void lglApplyModelMatrix()
apply the vbo modeling matrix to the vbo and reset the matrix
Definition: glvertex_core.h:2551
lgl_Node::speedupAll
virtual void speedupAll(double speedup=1)
speedup all animations
Definition: glvertex_nodes.h:785
lgl_LightingNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4971
lgl::lglGetVertexCount
int lglGetVertexCount() const
get the number of vertices contained in vbo
Definition: glvertex_core.h:1790
lglGetZWrite
bool lglGetZWrite()
get OpenGL state (depth write)
Definition: glvertex_api.h:384
lgl_Node::children
unsigned int children() const
get the number of children of the node
Definition: glvertex_nodes.h:113
lglGetDepthTest
bool lglGetDepthTest()
get OpenGL state (depth test)
Definition: glvertex_api.h:392
lgl_AnimationNode::update
virtual void update(double dt)
reimplement this method to update a node
Definition: glvertex_nodes.h:3253
lgl_SwitcherNode::advance
void advance(int delta=1)
advance the switch index
Definition: glvertex_nodes.h:5191
lglGetLineWidth
float lglGetLineWidth()
get OpenGL state (line width)
Definition: glvertex_api.h:460
lgl_TransformationNode::lgl_TransformationNode
lgl_TransformationNode(const mat4 &m, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2477
lgl_ControllableNode::stateless
virtual bool stateless() const
is the node stateless?
Definition: glvertex_nodes.h:1268
lgl_Node::checkForCycles
virtual bool checkForCycles()
check for graph cycles
Definition: glvertex_nodes.h:240
lgl_ActionNode::lgl_action_mode_enum
lgl_action_mode_enum
action mode enum
Definition: glvertex_nodes.h:1375
lgl_SteerNode::lgl_SteerNode
lgl_SteerNode(const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:1844
lgl_AnimationNode::pause
virtual void pause(bool yes=true)
pause the animation
Definition: glvertex_nodes.h:3171
lgl_AnimationNode::getVelocity
double getVelocity() const
get the animation velocity
Definition: glvertex_nodes.h:3039
lgl::lglGetVertexMode
lgl_primitive_enum lglGetVertexMode() const
get the primitive mode of vertices contained in vbo
Definition: glvertex_core.h:1784
lgl_string::toLower
lgl_string toLower(char separator='\0') const
convert to lower case
Definition: glvertex_string.h:107
lgl_TransitionNode::resume
virtual void resume(bool yes=true)
resume the animation
Definition: glvertex_nodes.h:3585
lgl_AnimationNode::pauseAll
virtual void pauseAll(bool yes=true)
pause all animations
Definition: glvertex_nodes.h:3338
lgl::lglAppendVerticesTo
void lglAppendVerticesTo(lgl *vbo) const
append a copy of the vertices and attributes in vbo to another vbo
Definition: glvertex_core.h:1928
lgl_ScaleNode::lgl_ScaleNode
lgl_ScaleNode(const vec4 &c, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2849
mat4::translate
static mat4 translate(double x, double y, double z)
create translation matrix
Definition: glslmath.h:2427
lgl_AnimationNode::getSignalOnStop
bool getSignalOnStop() const
get signal on stop
Definition: glvertex_nodes.h:3069
lgl_SteerableNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1812
lgl_Node::toggle
void toggle()
toggle the node
Definition: glvertex_nodes.h:285
lgl_TextureTransformationNode::lgl_TextureTransformationNode
lgl_TextureTransformationNode(double angle, const vec3 &v, const std::string &id="", lgl_Node *node=NULL)
ctor (rotation)
Definition: glvertex_nodes.h:2918
lgl_AnimationNode::getLimit
double getLimit() const
get the animation limit
Definition: glvertex_nodes.h:3045
lgl_ColorNode
color node
Definition: glvertex_nodes.h:2328
lgl_ScaleTransitionNode
animation node (scale transition)
Definition: glvertex_nodes.h:3784
lgl_Node::lgl_export_enum
lgl_export_enum
scene graph export modes
Definition: glvertex_nodes.h:810
lgl_TransitionNode::lgl_transition_enum
lgl_transition_enum
transition style
Definition: glvertex_nodes.h:3514
lgl_AnimationNode::animate
virtual mat4 animate(double animation, const vec3 &vector)=0
to be implemented for a particular type of animation
lgl_Node::finishAll
virtual void finishAll()
finish all transitions
Definition: glvertex_nodes.h:793
lgl_Node::drawSceneGraph
void drawSceneGraph(vec4 color=vec4(1))
draw the entire scene subgraph without updating
Definition: glvertex_nodes.h:359
lgl_AlphaTestNode::getAlphaTestEqual
bool getAlphaTestEqual() const
get the alpha test equality mode
Definition: glvertex_nodes.h:4728
lgl_LightNode::setLightPosition
void setLightPosition(vec3f light)
set the light position
Definition: glvertex_nodes.h:4022
lgl_AnimationNode::rewind
void rewind(double animation=0)
rewind the animation
Definition: glvertex_nodes.h:3119
lgl_LightNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4001
lgl_ControllableNode
controllable node (base class)
Definition: glvertex_nodes.h:1204
lgl::lglTexturing
void lglTexturing(bool on)
enable or disable the vertex texture coordinate attributes contained in vbo
Definition: glvertex_core.h:3395
lgl_ControlNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:1509
lgl_ContainerNode::lgl_ContainerNode
lgl_ContainerNode(lglVBO *vbo, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2151
lgl_SubgraphNode::speedupAll
virtual void speedupAll(double speedup=1)
speedup all animations
Definition: glvertex_nodes.h:5562
lgl_SubgraphNode::countAll
virtual unsigned int countAll()
count all nodes (count multiply linked nodes)
Definition: glvertex_nodes.h:5439
lgl_GeometryNode::getName
std::string getName() const
get the vbo name
Definition: glvertex_nodes.h:2026
lgl_LightSource
Blinn-Phong light source.
Definition: glvertex_light.h:11
lgl_BackFaceCullingNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4601
lgl_TransformationNode::rotate
void rotate(double angle, double x, double y, double z)
set the transformation matrix (rotation)
Definition: glvertex_nodes.h:2566
lgl_SwitcherNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:5208
lglRayCast
void lglRayCast(lglVBO *vbo)
cast a ray and intersect it with the transformed triangles contained in the vbo
Definition: glvertex_api.h:864
lgl_TextureTransformationNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:2935
lgl_SubgraphNode::countAllPrimitives
virtual unsigned int countAllPrimitives()
count all primitives
Definition: glvertex_nodes.h:5469
lgl_BarrierNode
control barrier node
Definition: glvertex_nodes.h:1649
lgl_RotationTransitionNode
animation node (rotation transition)
Definition: glvertex_nodes.h:3748
lgl_ControlNode::setControlDelay
void setControlDelay(double delay)
set the control delay
Definition: glvertex_nodes.h:1524
lgl_TransformationNode::rotate
void rotate(double angle, const vec3 &v)
set the transformation matrix (rotation)
Definition: glvertex_nodes.h:2559
lgl_GeometryNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:2046
lgl_FogNode
state change node (fogging)
Definition: glvertex_nodes.h:4787
lgl_Node::restartAll
virtual void restartAll(double animation=0)
restart all animations
Definition: glvertex_nodes.h:769
lglGetColor
vec4 lglGetColor()
get actual color
Definition: glvertex_api.h:178
lgl_ControllableNode::control
virtual void control(bool override=true)
control the node as specified by the control mode
Definition: glvertex_nodes.h:1238
lgl::setName
void setName(std::string name="")
set the vbo name
Definition: glvertex_core.h:209
lgl_ClippingNode::getClipPlaneNumber
unsigned int getClipPlaneNumber() const
get the clip plane number
Definition: glvertex_nodes.h:5084
lgl_TranslationNode::lgl_TranslationNode
lgl_TranslationNode(double x, double y, double z, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2711
lgl_FogNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:4801
mat4::transform
static mat4 transform(const mat3 &m, const vec3 &v)
create affine (resp.
Definition: glslmath.h:2647
lgl_LevelOfDetailNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:5274
lgl_ControlNode
control node
Definition: glvertex_nodes.h:1495
lgl_RotationAnimationNode
animation node (rotation)
Definition: glvertex_nodes.h:3478
lgl_Node::getBoundingBox
virtual void getBoundingBox(vec3 &bboxmin, vec3 &bboxmax)
get the bounding box of the entire subgraph
Definition: glvertex_nodes.h:417
lgl_Node::add_node
lgl_Node * add_node(lgl_Node *node)
add a child to the node
Definition: glvertex_nodes.h:148
lgl_Node::lgl_Node
lgl_Node(lgl_Node *node, const std::string &id="")
custom ctor
Definition: glvertex_nodes.h:54
lgl_SteerNode::control
virtual void control(lgl_ControllableNode *ctrl, bool override)
reimplement to change control effect
Definition: glvertex_nodes.h:1870
lgl_OptimizingSubgraphNode::getClassId
virtual std::string getClassId() const
get the class id
Definition: glvertex_nodes.h:5677
lgl_SubgraphNode::countAllOnce
virtual unsigned int countAllOnce()
count all nodes (count multiply linked nodes once)
Definition: glvertex_nodes.h:5454
lgl_Node::getExactBoundingBox
void getExactBoundingBox(vec3 &bboxmin, vec3 &bboxmax)
get the exact bounding box of the entire subgraph
Definition: glvertex_nodes.h:565
lgl_BarrierNode::restartAll
virtual void restartAll(double animation=0)
restart all animations
Definition: glvertex_nodes.h:1715
lgl_Node::stateless
virtual bool stateless() const
is the node stateless?
Definition: glvertex_nodes.h:727
lgl_ColorNode::lgl_ColorNode
lgl_ColorNode(double color, const std::string &id="", lgl_Node *node=NULL)
ctor
Definition: glvertex_nodes.h:2341
lgl_BarrierNode::speedupAll
virtual void speedupAll(double speedup=1)
speedup all animations
Definition: glvertex_nodes.h:1735
lgl_ControlNode::getControlDelay
double getControlDelay() const
get the control delay
Definition: glvertex_nodes.h:1530
lgl_ClippingNode::render
virtual void render()
reimplement this method to render a node
Definition: glvertex_nodes.h:5094
lgl_Node::convertable
bool convertable() const
is the node convertable?
Definition: glvertex_nodes.h:739
lglGetModelViewMatrix
mat4 lglGetModelViewMatrix()
get actual modelview matrix
Definition: glvertex_api.h:202