OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MultiSegmentPlacer.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 //osgParticle - Copyright (C) 2002 Marco Jez
14 
15 #ifndef OSGPARTICLE_MULTISEGMENT_PLACER
16 #define OSGPARTICLE_MULTISEGMENT_PLACER 1
17 
18 #include <osgParticle/Export>
19 #include <osgParticle/Placer>
20 #include <osgParticle/Particle>
21 
22 #include <vector>
23 #include <utility>
24 
25 #include <osg/Notify>
26 #include <osg/CopyOp>
27 #include <osg/Object>
28 #include <osg/Vec3>
29 
30 namespace osgParticle {
31 
37  public:
40 
42 
44  inline int numVertices() const;
45 
47  inline const osg::Vec3& getVertex(int i) const;
48 
50  inline void setVertex(int i, const osg::Vec3& v);
51 
53  inline void setVertex(int i, float x, float y, float z);
54 
56  inline void addVertex(const osg::Vec3& v);
57 
59  inline void addVertex(float x, float y, float z);
60 
62  inline void removeVertex(int i);
63 
65  void place(Particle* P) const;
66 
68  inline float volume() const;
69 
71  inline osg::Vec3 getControlPosition() const;
72 
73  protected:
74  virtual ~MultiSegmentPlacer() {}
75  MultiSegmentPlacer& operator=(const MultiSegmentPlacer&) { return *this; }
76 
77  private:
78  typedef std::pair<osg::Vec3, float> Vertex_data;
79  typedef std::vector<Vertex_data> Vertex_vector;
80 
81  Vertex_vector _vx;
82  float _total_length;
83 
84  void recompute_length();
85  };
86 
87  // INLINE FUNCTIONS
88 
89 
91  {
92  return static_cast<int>(_vx.size());
93  }
94 
95  inline const osg::Vec3& MultiSegmentPlacer::getVertex(int i) const
96  {
97  return _vx[i].first;
98  }
99 
100  inline void MultiSegmentPlacer::setVertex(int i, const osg::Vec3& v)
101  {
102  _vx[i].first = v;
103  recompute_length();
104  }
105 
106  inline void MultiSegmentPlacer::setVertex(int i, float x, float y, float z)
107  {
108  _vx[i].first.set(x, y, z);
109  recompute_length();
110  }
111 
113  {
114  float l = 0;
115  if (_vx.size() > 0) {
116  l = (v - _vx.back().first).length();
117  }
118  _total_length += l;
119  _vx.push_back(std::make_pair(v, _total_length));
120  }
121 
122  inline void MultiSegmentPlacer::addVertex(float x, float y, float z)
123  {
124  addVertex(osg::Vec3(x, y, z));
125  }
126 
128  {
129  _vx.erase(_vx.begin()+i);
130  recompute_length();
131  }
132 
133  inline float MultiSegmentPlacer::volume() const
134  {
135  return _total_length;
136  }
137 
139  {
140  return _vx.empty() ? osg::Vec3(0.0f,0.0f,0.0f) : _vx[0].first;
141  }
142 
143 }
144 #endif
float volume() const
return the length of the multi-segment
int numVertices() const
Get the number of vertices which define the segments.
osg::Vec3 getControlPosition() const
return the control position
void setVertex(int i, const osg::Vec3 &v)
Set a vertex.
const osg::Vec3 & getVertex(int i) const
Get a vertex.
#define OSGPARTICLE_EXPORT
Definition: Export.h:40
void removeVertex(int i)
Remove a vertex.
MultiSegmentPlacer & operator=(const MultiSegmentPlacer &)
#define META_Object(library, name)
Definition: Object.h:42
Vec3f Vec3
Definition: Vec3.h:21
void addVertex(const osg::Vec3 &v)
Add a vertex.