vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Grid.h
Go to the documentation of this file.
1 #ifndef APGRID_H
2 #define APGRID_H
3 
4 #include <vrecko/Ability.h>
5 #include <osg/Group>
6 #include <osg/Geometry>
7 
8 using namespace vrecko;
9 
10 namespace APFFDEditor {
11 
12  class Grid {
13  friend class EditorLogic;
14  public:
15  Grid();
16  ~Grid();
17 
18 
19  //this set count of control points in each direction in grid
20  inline void setCountOfControlPoints(osg::Vec3 pom) {
21  //we can not change count of control points if grid was one created(this variable is used in array iteration)
22  if (!gridWasCreated)
23  countOfCP.set(pom);
24  }
25 
26  inline osg::Vec3 getCountOfControlPoints(void) {
27  return countOfCP;
28  }
29 
30  //this function creates grid around selected object, it needs pWold pointer too
31  bool createGrid(vrecko::EnvironmentObject * object);
32 
33  //function that control if grid was changed, return id of ControlPoint which position was changed
34  //this function also set position of edges
35  bool updateGrid(void);
36 
37 
38  inline void setOptimalizationOfCP(unsigned int value){optimalizationOfCP=value;}
39 
40  //two main structures of grid
41 
42 
43 
44  protected:
45  //allocation and deallocation of arrays
46  inline void allocateControlPointArray() {
47  controlPoints = new ControlPoint**[countOfCP.x()];
48  for(unsigned long i=0; i<countOfCP.x(); i++){
49  controlPoints[i] = new ControlPoint*[countOfCP.y()];
50  }
51  for(unsigned long i=0; i<countOfCP.x(); i++){
52  for(unsigned long j=0; j<countOfCP.y(); j++){
53  controlPoints[i][j] = new ControlPoint[countOfCP.z()];
54  }
55  }
56  controlPoint_count = countOfCP.x()*countOfCP.y()*countOfCP.z();
57  }
58 
59  inline void allocateEdgeArray() {
60  //here i am counting number of edges in grid.
61  int countOfEdges = ((countOfCP.y()-1)*(countOfCP.x()) + (countOfCP.y())*(countOfCP.x()-1))*(countOfCP.z()) + (countOfCP.x())*(countOfCP.y())*(countOfCP.z()-1);
62  edges = new Edge[countOfEdges]; edge_count = countOfEdges;
63  }
64 
65  inline void deallocateEdgeArray() { if (edges) { delete[] (edges); } }
66 
67  inline void deallocateControlPointArray() {
68  if (controlPoints) {
69  for(unsigned long i=0; i<countOfCP.x(); i++){
70  for(unsigned long j=0; j<countOfCP.y(); j++){
71  delete[] (controlPoints[i][j]) ;
72  }
73  }
74  for(unsigned long i=0; i<countOfCP.x(); i++){
75  delete[] (controlPoints[i]) ;
76  }
77  delete[] (controlPoints) ;
78  }
79  }
80  struct ControlPoint {
82  osg::Vec3 startPos;
83  osg::Vec3 prevPos;
84 
85  //this is only for construction of edges
86  bool visited;
87  };
88  struct Edge {
89  unsigned long ID1;//id of environmet object ControlPoint
90  unsigned long ID2;
91  osg::ref_ptr<osg::Geometry> osgGeom;
92  };
95 
96  //count of control points
97  osg::Vec3 countOfCP;
98 
99  unsigned long controlPoint_count;
100  unsigned long edge_count;
101 
102  virtual void destroyGeometry();
103 
104  //osgGeode of all edges
105  osg::ref_ptr<osg::Geode> osgGeode;
106  float CPscaling;
108  unsigned int optimalizationOfCP;
109  //this function get transform of all parents
110  //void getParentsTransform(osg::Matrix &parentsTransform, osg::Node * object);
111  };
112 
113 }
114 #endif