2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-06-05 20:44:55 +08:00
|
|
|
//osgParticle - Copyright (C) 2002 Marco Jez
|
|
|
|
|
|
|
|
#ifndef OSGPARTICLE_SECTORPLACER_
|
|
|
|
#define OSGPARTICLE_SECTORPLACER_ 1
|
|
|
|
|
|
|
|
#include <osgParticle/CenteredPlacer>
|
|
|
|
#include <osgParticle/Particle>
|
|
|
|
#include <osgParticle/range>
|
|
|
|
|
|
|
|
#include <osg/CopyOp>
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Math>
|
|
|
|
|
|
|
|
namespace osgParticle
|
|
|
|
{
|
|
|
|
|
|
|
|
/** A sector-shaped particle placer.
|
|
|
|
This placer sets the initial position of incoming particle by choosing a random position
|
|
|
|
within a circular sector; this sector is defined by three parameters: a <I>center point</I>,
|
|
|
|
which is inherited directly from <CODE>osgParticle::CenteredPlacer</CODE>, a range of values
|
|
|
|
for <I>radius</I>, and a range of values for the <I>central angle</I> (sometimes called <B>phi</B>).
|
|
|
|
*/
|
|
|
|
class SectorPlacer: public CenteredPlacer {
|
|
|
|
public:
|
|
|
|
inline SectorPlacer();
|
|
|
|
inline SectorPlacer(const SectorPlacer ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
/// Get the range of possible values for radius.
|
|
|
|
inline const rangef &getRadiusRange() const;
|
|
|
|
|
|
|
|
/// Set the range of possible values for radius.
|
|
|
|
inline void setRadiusRange(const rangef &r);
|
|
|
|
|
|
|
|
/// Set the range of possible values for radius.
|
|
|
|
inline void setRadiusRange(float r1, float r2);
|
|
|
|
|
|
|
|
/// Get the range of possible values for the central angle.
|
|
|
|
inline const rangef &getPhiRange() const;
|
|
|
|
|
|
|
|
/// Set the range of possible values for the central angle.
|
|
|
|
inline void setPhiRange(const rangef &r);
|
|
|
|
|
|
|
|
/// Set the range of possible values for the central angle.
|
|
|
|
inline void setPhiRange(float r1, float r2);
|
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Object(osgParticle, SectorPlacer);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Place a particle. Do not call it manually.
|
|
|
|
inline void place(Particle *P) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~SectorPlacer() {}
|
|
|
|
SectorPlacer &operator=(const SectorPlacer &) { return *this; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
rangef rad_range_;
|
|
|
|
rangef phi_range_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
inline SectorPlacer::SectorPlacer()
|
|
|
|
: CenteredPlacer(), rad_range_(0, 1), phi_range_(0, osg::PI*2)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SectorPlacer::SectorPlacer(const SectorPlacer ©, const osg::CopyOp ©op)
|
|
|
|
: CenteredPlacer(copy, copyop), rad_range_(copy.rad_range_), phi_range_(copy.phi_range_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const rangef &SectorPlacer::getRadiusRange() const
|
|
|
|
{
|
|
|
|
return rad_range_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const rangef &SectorPlacer::getPhiRange() const
|
|
|
|
{
|
|
|
|
return phi_range_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SectorPlacer::setRadiusRange(const rangef &r)
|
|
|
|
{
|
|
|
|
rad_range_ = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SectorPlacer::setRadiusRange(float r1, float r2)
|
|
|
|
{
|
2002-08-04 02:03:40 +08:00
|
|
|
rad_range_.minimum = r1;
|
|
|
|
rad_range_.maximum = r2;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SectorPlacer::setPhiRange(const rangef &r)
|
|
|
|
{
|
|
|
|
phi_range_ = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SectorPlacer::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 SectorPlacer::place(Particle *P) const
|
|
|
|
{
|
2004-08-02 15:25:28 +08:00
|
|
|
float rad = rad_range_.get_random_sqrtf();
|
2002-06-05 20:44:55 +08:00
|
|
|
float phi = phi_range_.get_random();
|
|
|
|
|
|
|
|
osg::Vec3 pos(
|
|
|
|
getCenter().x() + rad * cosf(phi),
|
|
|
|
getCenter().y() + rad * sinf(phi),
|
|
|
|
getCenter().z());
|
|
|
|
|
|
|
|
P->setPosition(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|