OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentPlacer.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_SEGMENT_PLACER
16 #define OSGPARTICLE_SEGMENT_PLACER 1
17 
18 #include <osgParticle/Placer>
19 #include <osgParticle/Particle>
20 
21 #include <osg/CopyOp>
22 #include <osg/Object>
23 #include <osg/Vec3>
24 
25 namespace osgParticle {
26 
32  class SegmentPlacer: public Placer {
33  public:
34  inline SegmentPlacer();
35  inline SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
36 
38 
40  inline const osg::Vec3& getVertexA() const;
41 
43  inline void setVertexA(const osg::Vec3& v);
44 
46  inline void setVertexA(float x, float y, float z);
47 
49  inline const osg::Vec3& getVertexB() const;
50 
52  inline void setVertexB(const osg::Vec3& v);
53 
55  inline void setVertexB(float x, float y, float z);
56 
58  inline void setSegment(const osg::Vec3& A, const osg::Vec3& B);
59 
61  inline void place(Particle* P) const;
62 
64  inline float volume() const;
65 
67  inline osg::Vec3 getControlPosition() const;
68 
69  protected:
70  virtual ~SegmentPlacer() {}
71  SegmentPlacer& operator=(const SegmentPlacer&) { return *this; }
72 
73  private:
74  osg::Vec3 _vertexA;
75  osg::Vec3 _vertexB;
76  };
77 
78  // INLINE FUNCTIONS
79 
81  : Placer(), _vertexA(-1, 0, 0), _vertexB(1, 0, 0)
82  {
83  }
84 
85  inline SegmentPlacer::SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop)
86  : Placer(copy, copyop), _vertexA(copy._vertexA), _vertexB(copy._vertexB)
87  {
88  }
89 
90  inline const osg::Vec3& SegmentPlacer::getVertexA() const
91  {
92  return _vertexA;
93  }
94 
95  inline const osg::Vec3& SegmentPlacer::getVertexB() const
96  {
97  return _vertexB;
98  }
99 
100  inline void SegmentPlacer::setSegment(const osg::Vec3& A, const osg::Vec3& B)
101  {
102  _vertexA = A;
103  _vertexB = B;
104  }
105 
106  inline void SegmentPlacer::place(Particle* P) const
107  {
108  P->setPosition(rangev3(_vertexA, _vertexB).get_random());
109  }
110 
111  inline float SegmentPlacer::volume() const
112  {
113  return (_vertexB - _vertexA).length();
114  }
115 
116  inline void SegmentPlacer::setVertexA(const osg::Vec3& v)
117  {
118  _vertexA = v;
119  }
120 
121  inline void SegmentPlacer::setVertexA(float x, float y, float z)
122  {
123  _vertexA.set(x, y, z);
124  }
125 
126  inline void SegmentPlacer::setVertexB(const osg::Vec3& v)
127  {
128  _vertexB = v;
129  }
130 
131  inline void SegmentPlacer::setVertexB(float x, float y, float z)
132  {
133  _vertexB.set(x, y, z);
134  }
135 
137  {
138  return (_vertexA+_vertexB)*0.5f;
139  }
140 
141 
142 }
143 
144 #endif
void setVertexB(const osg::Vec3 &v)
Set vertex B of the segment as a vector.
void setVertexA(const osg::Vec3 &v)
Set vertex A of the segment as a vector.
void setSegment(const osg::Vec3 &A, const osg::Vec3 &B)
Set both vertices.
void setPosition(const osg::Vec3 &p)
Set the position vector.
Definition: Particle.h:497
META_Object(osgParticle, SegmentPlacer)
void place(Particle *P) const
Place a particle. This method is called by ModularEmitter, do not call it manually.
const osg::Vec3 & getVertexA() const
get vertex A.
Definition: SegmentPlacer.h:90
const osg::Vec3 & getVertexB() const
get vertex B.
Definition: SegmentPlacer.h:95
float volume() const
return the length of the segment
void set(value_type x, value_type y, value_type z)
Definition: Vec3f.h:67
osg::Vec3 getControlPosition() const
return the control position
range< osg::Vec3 > rangev3
Range of osg::Vec3s.
Definition: range.h:82
SegmentPlacer & operator=(const SegmentPlacer &)
Definition: SegmentPlacer.h:71