OpenSceneGraph/include/osgParticle/RadialShooter

157 lines
4.6 KiB
Plaintext
Raw Normal View History

//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 &copy, const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgParticle, RadialShooter);
/// 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 &copy, const osg::CopyOp &copyop)
: 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)
{
theta_range_.min = r1;
theta_range_.max = r2;
}
inline void RadialShooter::setPhiRange(const rangef &r)
{
phi_range_ = r;
}
inline void RadialShooter::setPhiRange(float r1, float r2)
{
phi_range_.min = r1;
phi_range_.max = r2;
}
inline void RadialShooter::setInitialSpeedRange(const rangef &r)
{
speed_range_ = r;
}
inline void RadialShooter::setInitialSpeedRange(float r1, float r2)
{
speed_range_.min = r1;
speed_range_.max = r2;
}
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