vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
abstractturtle.h
Go to the documentation of this file.
1 #ifndef ABSTRACTTURTLE_H_
2 #define ABSTRACTTURTLE_H_
3 
4 #include "utils.h"
5 #include "lsgeode.h"
6 #include "randomizer.h"
7 
8 namespace AP_LSystem {
9 
15 {
23 };
24 
25 const osg::Vec3d HeadVec(0.0,1.0,0.0);
26 const osg::Vec3d UpVec(1.0,0.0,0.0);
27 const osg::Vec3d LeftVec(0.0,0.0,1.0);
28 const osg::Vec3d Center(0.0,0.0,0.0);
29 
30 const osg::Vec4d White(1.0,1.0,1.0,1.0);
31 
36 {
37 protected:
40 
41 public:
42 //****************************************************************
43 //** OTHER **
44 //****************************************************************
49  virtual int initialize() { return 0;}
50 
55  virtual int finalize() { return 0;}
56 
62  virtual int resetValues() { return 0;} // TODO
63 
69  {
70  return properties;
71  }
72 
77  virtual void setProperties( TurtleProperties p )
78  {
79  properties = p;
80  }
81 
88  {
89  // inherit matrix
91  }
92 
98  inline void bindGeode( LSGeode * geode )
99  {
100  this->geode = geode;
101  }
102 
107  inline LSGeode * getGeode( )
108  {
109  return geode;
110  }
111 
116  inline osg::Matrixd getMatrix()
117  {
118  return properties.matrix;
119  }
120 
121 //****************************************************************
122 //** DEBUG **
123 //****************************************************************
124 
130  virtual void drawFrame( osg::Matrixd & matrix, osg::Vec4d * color = NULL ) = 0;
131 
138  virtual void drawVector( const osg::Vec3d & vector, osg::Matrixd & matrix, osg::Vec4d & color)
139  {
140  double s = properties.debugGeometryScale;
141  double l = vector.length();
142  osg::Cylinder * cylinder = new osg::Cylinder(vector * s * (l/2.0f) * matrix,s * 0.01f,s * l);
143  osg::Cone * cone = new osg::Cone(vector * s * ( l + 0.03f ) * matrix, s * 0.03f,s * 0.15f);
144 
145  osg::Matrixd m = osg::Matrixd::rotate( LeftVec, vector ) * matrix;
146  cylinder->setRotation( m.getRotate() );
147  cone->setRotation( m.getRotate() );
148 
149  osg::ShapeDrawable * shape;
150  shape = new osg::ShapeDrawable(cylinder);
151  shape->setColor( color );
152  geode->addDrawable( shape );
153 
154  shape = new osg::ShapeDrawable(cone);
155 // shape->setColor( color );
156  geode->addDrawable( shape );
157  }
158 
159 //****************************************************************
160 //** ROTATION **
161 //****************************************************************
167  inline double toRad( double angle )
168  {
170  return osg::DegreesToRadians( angle );
171  else
172  return angle;
173  }
174 
180  inline double rand( double angle )
181  {
184  return angle;
185  }
186 
194  virtual int turnLeft(std::vector<Parameter> & p) = 0;
195 
203  virtual int turnRight(std::vector<Parameter> & p) = 0;
204 
212  virtual int pitchDown(std::vector<Parameter> & p) = 0;
213 
221  virtual int pitchUp(std::vector<Parameter> & p) = 0;
222 
230  virtual int rollLeft(std::vector<Parameter> & p) = 0;
231 
239  virtual int rollRight(std::vector<Parameter> & p) = 0;
240 
245  virtual int turnArround() = 0;
246 
252  virtual int rollArround() = 0;
253 
258  virtual int rollUntilHorizontal() = 0;
259 
265  virtual int randomTurnPitchRoll(std::vector<Parameter>& p)= 0;
266 
267 //****************************************************************
268 //** CHANGE PROPERTIES **
269 //****************************************************************
277  virtual int multiplyLength(std::vector<Parameter> & p) = 0;
278 
286  virtual int multiplyRadius(std::vector<Parameter> & p) = 0;
287 
295  virtual int multiplyAngle(std::vector<Parameter> & p) = 0;
296 
304  virtual int multiplyTropismElasticity(std::vector<Parameter> & p)= 0;
305 
313  virtual int multiplyGravitropismElasticity(std::vector<Parameter> & p)= 0;
314 
315 //****************************************************************
316 //** MOVEMENT **
317 //****************************************************************
325  virtual int drawForward(std::vector<Parameter> & p) = 0;
326 
331  virtual int drawForwardHalf() = 0;
332 
340  virtual int moveForward(std::vector<Parameter> & p) = 0;
341 
346  virtual int moveForwardHalf() = 0;
347 
348 };
349 }
350 
351 #endif