2002-06-05 20:44:55 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
//osgParticle - Copyright (C) 2002 Marco Jez
|
|
|
|
|
|
|
|
#ifndef OSGPARTICLE_RADIALSHOOTER_
|
|
|
|
#define OSGPARTICLE_RADIALSHOOTER_ 1
|
|
|
|
|
|
|
|
#include <osgParticle/Shooter>
|
|
|
|
#include <osgParticle/Particle>
|
|
|
|
#include <osgParticle/range>
|
|
|
|
|
|
|
|
#include <osg/CopyOp>
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/Math>
|
|
|
|
|
|
|
|
namespace osgParticle
|
|
|
|
{
|
|
|
|
|
|
|
|
/** A shooter class that shoots particles radially.
|
|
|
|
This shooter computes the velocity vector of incoming particles by choosing a
|
|
|
|
random direction and a random speed. Both direction and speed are chosen within
|
|
|
|
specified ranges. The direction is defined by two angles: <B>theta</B>, which
|
|
|
|
is the angle between the velocity vector and the Z axis, and <B>phi</B>, which is
|
|
|
|
the angle between the X axis and the velocity vector projected onto the X-Y plane.
|
|
|
|
*/
|
|
|
|
class RadialShooter: public Shooter {
|
|
|
|
public:
|
|
|
|
inline RadialShooter();
|
|
|
|
inline RadialShooter(const RadialShooter ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Object(osgParticle, RadialShooter);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get the range of possible values for <B>theta</B> angle.
|
|
|
|
inline const rangef &getThetaRange() const;
|
|
|
|
|
|
|
|
/// Set the range of possible values for <B>theta</B> angle.
|
|
|
|
inline void setThetaRange(const rangef &r);
|
|
|
|
|
|
|
|
/// Set the range of possible values for <B>theta</B> angle.
|
|
|
|
inline void setThetaRange(float r1, float r2);
|
|
|
|
|
|
|
|
/// Get the range of possible values for <B>phi</B> angle.
|
|
|
|
inline const rangef &getPhiRange() const;
|
|
|
|
|
|
|
|
/// Set the range of possible values for <B>phi</B> angle.
|
|
|
|
inline void setPhiRange(const rangef &r);
|
|
|
|
|
|
|
|
/// Set the range of possible values for <B>phi</B> angle.
|
|
|
|
inline void setPhiRange(float r1, float r2);
|
|
|
|
|
|
|
|
/// Get the range of possible values for initial speed of particles.
|
|
|
|
inline const rangef &getInitialSpeedRange() const;
|
|
|
|
|
|
|
|
/// Set the range of possible values for initial speed of particles.
|
|
|
|
inline void setInitialSpeedRange(const rangef &r);
|
|
|
|
|
|
|
|
/// Set the range of possible values for initial speed of particles.
|
|
|
|
inline void setInitialSpeedRange(float r1, float r2);
|
|
|
|
|
|
|
|
/// Shoot a particle. Do not call this method manually.
|
|
|
|
inline void shoot(Particle *P) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~RadialShooter() {}
|
|
|
|
RadialShooter &operator=(const RadialShooter &) { return *this; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
rangef theta_range_;
|
|
|
|
rangef phi_range_;
|
|
|
|
rangef speed_range_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
inline RadialShooter::RadialShooter()
|
|
|
|
: Shooter(),
|
|
|
|
theta_range_(0, 0.5f*osg::PI_4),
|
|
|
|
phi_range_(0, 2*osg::PI),
|
|
|
|
speed_range_(10, 10)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline RadialShooter::RadialShooter(const RadialShooter ©, const osg::CopyOp ©op)
|
|
|
|
: Shooter(copy, copyop),
|
|
|
|
theta_range_(copy.theta_range_),
|
|
|
|
phi_range_(copy.phi_range_),
|
|
|
|
speed_range_(copy.speed_range_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const rangef &RadialShooter::getThetaRange() const
|
|
|
|
{
|
|
|
|
return theta_range_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const rangef &RadialShooter::getPhiRange() const
|
|
|
|
{
|
|
|
|
return phi_range_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const rangef &RadialShooter::getInitialSpeedRange() const
|
|
|
|
{
|
|
|
|
return speed_range_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RadialShooter::setThetaRange(const rangef &r)
|
|
|
|
{
|
|
|
|
theta_range_ = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RadialShooter::setThetaRange(float r1, float r2)
|
|
|
|
{
|
2002-08-04 02:03:40 +08:00
|
|
|
theta_range_.minimum = r1;
|
|
|
|
theta_range_.maximum = r2;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void RadialShooter::setPhiRange(const rangef &r)
|
|
|
|
{
|
|
|
|
phi_range_ = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RadialShooter::setPhiRange(float r1, float r2)
|
|
|
|
{
|
2002-08-04 02:03:40 +08:00
|
|
|
phi_range_.minimum = r1;
|
|
|
|
phi_range_.maximum = r2;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void RadialShooter::setInitialSpeedRange(const rangef &r)
|
|
|
|
{
|
|
|
|
speed_range_ = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RadialShooter::setInitialSpeedRange(float r1, float r2)
|
|
|
|
{
|
2002-08-04 02:03:40 +08:00
|
|
|
speed_range_.minimum = r1;
|
|
|
|
speed_range_.maximum = r2;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void RadialShooter::shoot(Particle *P) const
|
|
|
|
{
|
|
|
|
float theta = theta_range_.get_random();
|
|
|
|
float phi = phi_range_.get_random();
|
|
|
|
float speed = speed_range_.get_random();
|
|
|
|
|
|
|
|
P->setVelocity(osg::Vec3(
|
|
|
|
speed * sinf(theta) * cosf(phi),
|
|
|
|
speed * sinf(theta) * sinf(phi),
|
|
|
|
speed * cosf(theta)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|