vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PerlinLines.h
Go to the documentation of this file.
1 #ifndef _PERLINELINES_H
2 #define _PERLINELINES_H
3 
4 #include "Controller.h"
5 #include "poa.h"
6 #include <osg/LineWidth>
7 
8 
9 using namespace vrecko;
10 
11 namespace APDYNAMICART
12 {
13 
14 
15 
16 typedef std::vector<osg::ref_ptr<osg::Sphere> > Spheres;
17 
18 
19 class PerlinLines : public PoA
20 {
21 public:
22  PerlinLines(Controller* contr, int numberOfLines, double x, double y, double z);
23  ~PerlinLines();
24 
25  int load(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* PoANode) { return 0; }
26 
27  void save(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* Document, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* poaNode) {}
28 
29  virtual void createMenuStructure( osg::ref_ptr<vreckoUtils::MenuBase> parentMenu ) const;
30 
31  void GUIItemClicked(const char* itemID);
32 
33  void GUISliderChanged(const char* sliderID, float sliderPos);
34 
35  void pointed(bool pointed);
36 
37  void setColor(osg::Vec4 newColour) {}
38 
39  void update();
40 
41  void draw();
42 
43  void setLineParameters(int count);
44 
45  void setLinesParameters();
46 
47  double perlinNoise(osg::Vec3 temp);
48 
49  double smooth(osg::Vec3 temp, double sx, double sy, double sz);
50 
51  double interpolate(double a, double b, double c);
52 
53  void interpolateVec3(osg::Vec3Array* controlPoints, osg::Vec3Array* interpolatedPoints, int p_steps);
54 
55  osg::Vec3 interpolatePoint(double t, osg::Vec3 point1, osg::Vec3 point2, osg::Vec3 point0 = osg::Vec3(0.0, 0.0, 0.0), osg::Vec3 point3 = osg::Vec3(0.0, 0.0, 0.0));
56 
57  double random(double min,double max) { return min + (max-min)*(double)rand()/(double)RAND_MAX;}
58 
59 
60  void setMagnet(osg::Vec3 coordinates, float magnetSize){_magnetUsed = true; _magnetCoords = coordinates; this->_magnetSize = magnetSize;};
61 
62  void createMagnet(EnvironmentObject* daarea, bool first){daarea->addEOChild(magnetEO); daarea->addEOChild(particlesEO);if (first) _magnetCreated = true; else _magnetCreated = false;};
63 
64  void updateMagnetPosition(osg::Vec3 vektor, float size) ;
65 
66  void unsetMagnet() {_magnetUsed = false; _magnetON = false;};
67 
68 
69  void setBounding(float boundingSize, bool first) {_boundingUsed = true; this->_boundingSize = boundingSize;if (first) _boundingCreated = true; else _boundingCreated = false;};
70 
71  void setBoundingVisible() {if(_boundingVisible) _boundingVisible = false; else _boundingVisible = true;};
72 
73  void unsetBounding() {_boundingUsed = false;};
74 
75 
76  void recalculateColorInterpolation();
77 
78  void setColor(osg::Vec3 color){_red = color.x(); _green = color.y(); _blue = color.z();};
79 
80 
81  void setSpeed(int speed) {changedSpeed = 101-speed;};
82 
83  int getSpeed(){return this->_speed;};
84 
85  void setInterpolationCount(int interpolationCount) {changedInterpolation = 5 + interpolationCount; _somethingChaned = true;};
86 
87  int getInterpolationCount() {return this->_interpolationCount;};
88 
89  void setLength(int length) {changedLength = 4 + length; _somethingChaned = true;};
90 
91  void setColor(float r, float g, float b) {_red = r; _green = g; _blue = b; _somethingChaned = true;}
92 
93 
94  void setController(osg::Vec3 vektor);
95 
96  void unsetController(){_controllerUsed = false;};
97 
98  void updateControllerPosition(osg::Vec3 vektor) {if (_request) _controllerCoords = vektor;};
99 
100  int getLength(){return this->_length;};
101 
102  void pause(){if (_paused) _paused = false; else _paused = true;};
103 
104 
105 
106 
107 protected:
108  typedef osg::ref_ptr<osg::Vec3Array> Vec3Ptr;
109 
110  osg::ref_ptr<osg::Geode> _lineGeode, _boxGeode;
111  std::vector<osg::ref_ptr<osg::Geometry>> _lineGeometry;
112  osg::ref_ptr<osg::Vec4Array> _linesColorArray, _boxColorArray;
113  osg::ref_ptr<osg::Vec4Array> _newLinesColorArray;
114  osg::ref_ptr<osg::StateSet> _OSGState, _boxOSGState;
115  osg::ref_ptr<osg::LineWidth> _linewidth;
116  osg::ref_ptr<osg::Material> _linesMaterial, _boxMaterial;
117  std::vector<Vec3Ptr> _lines;
118  std::vector<Vec3Ptr> _interpolatedLines;
120  int _p[512];
121  float _magnetSize, _boundingSize;
122  u_int _speed, _trigger, _interpolationCount, _length;
123  osg::Vec3 _magnetCoords, _unusedMagnetCoords, _controllerCoords;
124  bool _somethingChaned, _request, _pointed, _paused, _magnetUsed, _magnetON, _controllerUsed, _boundingUsed, _boundingVisible;
125  bool _magnetCreated, _boundingCreated;
126  u_int changedSpeed, changedInterpolation, changedLength;
127  float _red, _green, _blue, _changedRed, _changedGreen, _changedBlue;
132 
133  osg::ref_ptr<osg::Geode> magnetGeode;
134  osg::ref_ptr<osg::StateSet> magnetStateSet;
135  osg::ref_ptr<osg::Material> magnetMaterial;
136 };
137 
138 }
139 #endif