1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
13//osgParticle - Copyright (C) 2002 Marco Jez
15#ifndef OSGPARTICLE_RADIAL_SHOOTER
16#define OSGPARTICLE_RADIAL_SHOOTER 1
18#include <osgParticle/Shooter>
19#include <osgParticle/Particle>
20#include <osgParticle/range>
29 /** A shooter class that shoots particles radially.
30 This shooter computes the velocity vector of incoming particles by choosing a
31 random direction and a random speed. Both direction and speed are chosen within
32 specified ranges. The direction is defined by two angles: <B>theta</B>, which
33 is the angle between the velocity vector and the Z axis, and <B>phi</B>, which is
34 the angle between the X axis and the velocity vector projected onto the X-Y plane.
36 class RadialShooter: public Shooter {
38 inline RadialShooter();
39 inline RadialShooter(const RadialShooter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
41 META_Object(osgParticle, RadialShooter);
43 /// Get the range of possible values for <B>theta</B> angle.
44 inline const rangef& getThetaRange() const;
46 /// Set the range of possible values for <B>theta</B> angle.
47 inline void setThetaRange(const rangef& r);
49 /// Set the range of possible values for <B>theta</B> angle.
50 inline void setThetaRange(float r1, float r2);
52 /// Get the range of possible values for <B>phi</B> angle.
53 inline const rangef& getPhiRange() const;
55 /// Set the range of possible values for <B>phi</B> angle.
56 inline void setPhiRange(const rangef& r);
58 /// Set the range of possible values for <B>phi</B> angle.
59 inline void setPhiRange(float r1, float r2);
61 /// Get the range of possible values for initial speed of particles.
62 inline const rangef& getInitialSpeedRange() const;
64 /// Set the range of possible values for initial speed of particles.
65 inline void setInitialSpeedRange(const rangef& r);
67 /// Set the range of possible values for initial speed of particles.
68 inline void setInitialSpeedRange(float r1, float r2);
70 /// Get the range of possible values for initial rotational speed of particles.
71 inline const rangev3& getInitialRotationalSpeedRange() const;
73 /// Set the range of possible values for initial rotational speed of particles.
74 inline void setInitialRotationalSpeedRange(const rangev3& r);
76 /// Set the range of possible values for initial rotational speed of particles.
77 inline void setInitialRotationalSpeedRange(const osg::Vec3& r1, const osg::Vec3& r2);
79 /// Shoot a particle. Do not call this method manually.
80 inline void shoot(Particle* P) const;
83 virtual ~RadialShooter() {}
84 RadialShooter& operator=(const RadialShooter&) { return *this; }
90 rangev3 _rot_speed_range;
95 inline RadialShooter::RadialShooter()
97 _theta_range(0, 0.5f*osg::PI_4),
98 _phi_range(0, 2*osg::PI),
100 _rot_speed_range(osg::Vec3(0,0,0), osg::Vec3(0,0,0))
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)
113 inline const rangef& RadialShooter::getThetaRange() const
118 inline const rangef& RadialShooter::getPhiRange() const
123 inline const rangef& RadialShooter::getInitialSpeedRange() const
128 inline const rangev3& RadialShooter::getInitialRotationalSpeedRange() const
130 return _rot_speed_range;
133 inline void RadialShooter::setThetaRange(const rangef& r)
138 inline void RadialShooter::setThetaRange(float r1, float r2)
140 _theta_range.minimum = r1;
141 _theta_range.maximum = r2;
144 inline void RadialShooter::setPhiRange(const rangef& r)
149 inline void RadialShooter::setPhiRange(float r1, float r2)
151 _phi_range.minimum = r1;
152 _phi_range.maximum = r2;
155 inline void RadialShooter::setInitialSpeedRange(const rangef& r)
160 inline void RadialShooter::setInitialSpeedRange(float r1, float r2)
162 _speed_range.minimum = r1;
163 _speed_range.maximum = r2;
166 inline void RadialShooter::setInitialRotationalSpeedRange(const rangev3& r)
168 _rot_speed_range = r;
171 inline void RadialShooter::setInitialRotationalSpeedRange(const osg::Vec3& r1, const osg::Vec3& r2)
173 _rot_speed_range.minimum = r1;
174 _rot_speed_range.maximum = r2;
177 inline void RadialShooter::shoot(Particle* P) const
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();
184 P->setVelocity(osg::Vec3(
185 speed * sinf(theta) * cosf(phi),
186 speed * sinf(theta) * sinf(phi),
190 P->setAngularVelocity(rot_speed);