OpenSceneGraph 3.6.5
RadialShooter
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
26namespace 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
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
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
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec3f Vec3
Definition Vec3:21
The osgParticle library is a NodeKit that extends the core scene graph to support particle effects.
Definition AccelOperator:27
range< osg::Vec3 > rangev3
Range of osg::Vec3s.
Definition range:82
range< float > rangef
Range of floats.
Definition range:76
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Implementation of a particle.
Definition Particle:47
void setVelocity(const osg::Vec3 &v)
Set the velocity vector.
Definition Particle:488
void setAngularVelocity(const osg::Vec3 &v)
Set the angular velocity vector.
Definition Particle:520
void setPhiRange(const rangef &r)
Set the range of possible values for phi angle.
Definition RadialShooter:144
RadialShooter & operator=(const RadialShooter &)
Definition RadialShooter:84
void shoot(Particle *P) const
Shoot a particle. Do not call this method manually.
Definition RadialShooter:177
const rangev3 & getInitialRotationalSpeedRange() const
Get the range of possible values for initial rotational speed of particles.
Definition RadialShooter:128
META_Object(osgParticle, RadialShooter)
virtual ~RadialShooter()
Definition RadialShooter:83
const rangef & getThetaRange() const
Get the range of possible values for theta angle.
Definition RadialShooter:113
const rangef & getInitialSpeedRange() const
Get the range of possible values for initial speed of particles.
Definition RadialShooter:123
void setThetaRange(const rangef &r)
Set the range of possible values for theta angle.
Definition RadialShooter:133
void setInitialRotationalSpeedRange(const rangev3 &r)
Set the range of possible values for initial rotational speed of particles.
Definition RadialShooter:166
RadialShooter()
Definition RadialShooter:95
const rangef & getPhiRange() const
Get the range of possible values for phi angle.
Definition RadialShooter:118
void setInitialSpeedRange(const rangef &r)
Set the range of possible values for initial speed of particles.
Definition RadialShooter:155
ValueType minimum
Lower bound.
Definition range:42
Shooter()
Definition Shooter:52

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.