OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BoxPlacer.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 //Build by Zach Deedler
14 
15 #ifndef OSGPARTICLE_BOX_PLACER
16 #define OSGPARTICLE_BOX_PLACER 1
17 
18 #include <osgParticle/CenteredPlacer>
19 #include <osgParticle/Particle>
20 #include <osgParticle/range>
21 
22 #include <osg/CopyOp>
23 #include <osg/Object>
24 #include <osg/Vec3>
25 #include <osg/Math>
26 
27 namespace osgParticle
28 {
29 
36  class BoxPlacer: public CenteredPlacer {
37  public:
38  inline BoxPlacer();
39  inline BoxPlacer(const BoxPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
40 
42  inline const rangef& getXRange() const;
43 
45  inline void setXRange(const rangef& r);
46 
48  inline void setXRange(float r1, float r2);
49 
51  inline const rangef& getYRange() const;
52 
54  inline void setYRange(const rangef& r);
55 
57  inline void setYRange(float r1, float r2);
58 
60  inline const rangef& getZRange() const;
61 
63  inline void setZRange(const rangef& r);
64 
66  inline void setZRange(float r1, float r2);
67 
69 
71  inline void place(Particle* P) const;
72 
74  inline float volume() const;
75 
77  inline osg::Vec3 getControlPosition() const;
78 
79  protected:
80  virtual ~BoxPlacer() {}
81  BoxPlacer& operator=(const BoxPlacer&) { return *this; }
82 
83  private:
84  rangef _x_range;
85  rangef _y_range;
86  rangef _z_range;
87  };
88 
89  // INLINE FUNCTIONS
90 
92  : CenteredPlacer(), _x_range(-1, 1), _y_range(-1, 1), _z_range(-1, 1)
93  {
94  }
95 
96  inline BoxPlacer::BoxPlacer(const BoxPlacer& copy, const osg::CopyOp& copyop)
97  : CenteredPlacer(copy, copyop),
98  _x_range(copy._x_range), _y_range(copy._y_range), _z_range(copy._z_range)
99  {
100  }
101 
102  inline const rangef& BoxPlacer::getXRange() const
103  {
104  return _x_range;
105  }
106 
107  inline void BoxPlacer::setXRange(const rangef& r)
108  {
109  _x_range = r;
110  }
111 
112  inline void BoxPlacer::setXRange(float r1, float r2)
113  {
114  _x_range.minimum = r1;
115  _x_range.maximum = r2;
116  }
117 
118  inline const rangef& BoxPlacer::getYRange() const
119  {
120  return _y_range;
121  }
122 
123  inline void BoxPlacer::setYRange(const rangef& r)
124  {
125  _y_range = r;
126  }
127 
128  inline void BoxPlacer::setYRange(float r1, float r2)
129  {
130  _y_range.minimum = r1;
131  _y_range.maximum = r2;
132  }
133 
134  inline const rangef& BoxPlacer::getZRange() const
135  {
136  return _z_range;
137  }
138 
139  inline void BoxPlacer::setZRange(const rangef& r)
140  {
141  _z_range = r;
142  }
143 
144  inline void BoxPlacer::setZRange(float r1, float r2)
145  {
146  _z_range.minimum = r1;
147  _z_range.maximum = r2;
148  }
149 
150  inline void BoxPlacer::place(Particle* P) const
151  {
152  osg::Vec3 pos(
153  getCenter().x() + _x_range.get_random(),
154  getCenter().y() + _y_range.get_random(),
155  getCenter().z() + _z_range.get_random());
156 
157  P->setPosition(pos);
158  }
159 
160  inline float BoxPlacer::volume() const
161  {
162  return (_x_range.maximum - _x_range.minimum) *
163  (_y_range.maximum - _y_range.minimum) *
164  (_z_range.maximum - _z_range.minimum);
165  }
166 
168  {
169  return getCenter();
170  }
171 
172 }
173 
174 #endif
value_type & z()
Definition: Vec3f.h:82
void setPosition(const osg::Vec3 &p)
Set the position vector.
Definition: Particle.h:497
ValueType maximum
Higher bound.
Definition: range.h:45
const rangef & getYRange() const
Get the range of possible values along the Y axis.
Definition: BoxPlacer.h:118
const rangef & getZRange() const
Get the range of possible values along the Z axis.
Definition: BoxPlacer.h:134
BoxPlacer & operator=(const BoxPlacer &)
Definition: BoxPlacer.h:81
void setXRange(const rangef &r)
Set the range of possible values along the X axis.
Definition: BoxPlacer.h:107
ValueType get_random() const
Get a random value between min and max.
Definition: range.h:57
void place(Particle *P) const
Place a particle. Do not call it manually.
Definition: BoxPlacer.h:150
void setZRange(const rangef &r)
Set the range of possible values along the Z axis.
Definition: BoxPlacer.h:139
value_type & y()
Definition: Vec3f.h:81
META_Object(osgParticle, BoxPlacer)
const osg::Vec3 & getCenter() const
Get the center point.
const rangef & getXRange() const
Get the range of possible values along the X axis.
Definition: BoxPlacer.h:102
osg::Vec3 getControlPosition() const
return the control position
Definition: BoxPlacer.h:167
ValueType minimum
Lower bound.
Definition: range.h:42
virtual ~BoxPlacer()
Definition: BoxPlacer.h:80
float volume() const
return the volume of the box
Definition: BoxPlacer.h:160
void setYRange(const rangef &r)
Set the range of possible values along the Y axis.
Definition: BoxPlacer.h:123