OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RadialShooter.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_RADIAL_SHOOTER
16 #define OSGPARTICLE_RADIAL_SHOOTER 1
17 
18 #include <osgParticle/Shooter>
19 #include <osgParticle/Particle>
20 #include <osgParticle/range>
21 
22 #include <osg/CopyOp>
23 #include <osg/Object>
24 #include <osg/Math>
25 
26 namespace osgParticle
27 {
28 
36  class RadialShooter: public Shooter {
37  public:
38  inline RadialShooter();
39  inline RadialShooter(const RadialShooter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
40 
42 
44  inline const rangef& getThetaRange() const;
45 
47  inline void setThetaRange(const rangef& r);
48 
50  inline void setThetaRange(float r1, float r2);
51 
53  inline const rangef& getPhiRange() const;
54 
56  inline void setPhiRange(const rangef& r);
57 
59  inline void setPhiRange(float r1, float r2);
60 
62  inline const rangef& getInitialSpeedRange() const;
63 
65  inline void setInitialSpeedRange(const rangef& r);
66 
68  inline void setInitialSpeedRange(float r1, float r2);
69 
71  inline const rangev3& getInitialRotationalSpeedRange() const;
72 
74  inline void setInitialRotationalSpeedRange(const rangev3& r);
75 
77  inline void setInitialRotationalSpeedRange(const osg::Vec3& r1, const osg::Vec3& r2);
78 
80  inline void shoot(Particle* P) const;
81 
82  protected:
83  virtual ~RadialShooter() {}
84  RadialShooter& operator=(const RadialShooter&) { return *this; }
85 
86  private:
87  rangef _theta_range;
88  rangef _phi_range;
89  rangef _speed_range;
90  rangev3 _rot_speed_range;
91  };
92 
93  // INLINE FUNCTIONS
94 
96  : Shooter(),
97  _theta_range(0, 0.5f*osg::PI_4),
98  _phi_range(0, 2*osg::PI),
99  _speed_range(10, 10),
100  _rot_speed_range(osg::Vec3(0,0,0), osg::Vec3(0,0,0))
101  {
102  }
103 
104  inline RadialShooter::RadialShooter(const RadialShooter& copy, const osg::CopyOp& copyop)
105  : Shooter(copy, copyop),
106  _theta_range(copy._theta_range),
107  _phi_range(copy._phi_range),
108  _speed_range(copy._speed_range),
109  _rot_speed_range(copy._rot_speed_range)
110  {
111  }
112 
113  inline const rangef& RadialShooter::getThetaRange() const
114  {
115  return _theta_range;
116  }
117 
118  inline const rangef& RadialShooter::getPhiRange() const
119  {
120  return _phi_range;
121  }
122 
124  {
125  return _speed_range;
126  }
127 
129  {
130  return _rot_speed_range;
131  }
132 
133  inline void RadialShooter::setThetaRange(const rangef& r)
134  {
135  _theta_range = r;
136  }
137 
138  inline void RadialShooter::setThetaRange(float r1, float r2)
139  {
140  _theta_range.minimum = r1;
141  _theta_range.maximum = r2;
142  }
143 
144  inline void RadialShooter::setPhiRange(const rangef& r)
145  {
146  _phi_range = r;
147  }
148 
149  inline void RadialShooter::setPhiRange(float r1, float r2)
150  {
151  _phi_range.minimum = r1;
152  _phi_range.maximum = r2;
153  }
154 
156  {
157  _speed_range = r;
158  }
159 
160  inline void RadialShooter::setInitialSpeedRange(float r1, float r2)
161  {
162  _speed_range.minimum = r1;
163  _speed_range.maximum = r2;
164  }
165 
167  {
168  _rot_speed_range = r;
169  }
170 
172  {
173  _rot_speed_range.minimum = r1;
174  _rot_speed_range.maximum = r2;
175  }
176 
177  inline void RadialShooter::shoot(Particle* P) const
178  {
179  float theta = _theta_range.get_random();
180  float phi = _phi_range.get_random();
181  float speed = _speed_range.get_random();
182  osg::Vec3 rot_speed = _rot_speed_range.get_random();
183 
185  speed * sinf(theta) * cosf(phi),
186  speed * sinf(theta) * sinf(phi),
187  speed * cosf(theta)
188  ));
189 
190  P->setAngularVelocity(rot_speed);
191  }
192 
193 }
194 
195 
196 #endif
const rangef & getPhiRange() const
Get the range of possible values for phi angle.
RadialShooter & operator=(const RadialShooter &)
Definition: RadialShooter.h:84
META_Object(osgParticle, RadialShooter)
ValueType maximum
Higher bound.
Definition: range.h:45
void setAngularVelocity(const osg::Vec3 &v)
Definition: Particle.h:534
ValueType get_random() const
Get a random value between min and max.
Definition: range.h:57
void setVelocity(const osg::Vec3 &v)
Definition: Particle.h:502
const rangef & getInitialSpeedRange() const
Get the range of possible values for initial speed of particles.
const double PI_4
Definition: Math.h:32
void shoot(Particle *P) const
Shoot a particle. Do not call this method manually.
Vec3f Vec3
Definition: Vec3.h:21
void setInitialSpeedRange(const rangef &r)
Set the range of possible values for initial speed of particles.
const rangef & getThetaRange() const
Get the range of possible values for theta angle.
const double PI
Definition: Math.h:30
Definition: AlphaFunc.h:19
ValueType minimum
Lower bound.
Definition: range.h:42
const rangev3 & getInitialRotationalSpeedRange() const
Get the range of possible values for initial rotational speed of particles.
void setInitialRotationalSpeedRange(const rangev3 &r)
Set the range of possible values for initial rotational speed of particles.
void setPhiRange(const rangef &r)
Set the range of possible values for phi angle.
void setThetaRange(const rangef &r)
Set the range of possible values for theta angle.