2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
#ifndef OSGPARTICLE_SECTOR_PLACER
|
|
|
|
#define OSGPARTICLE_SECTOR_PLACER 1
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
#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();
|
2005-04-29 17:47:57 +08:00
|
|
|
inline SectorPlacer(const SectorPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get the range of possible values for radius.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const rangef& getRadiusRange() const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set the range of possible values for radius.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void setRadiusRange(const rangef& r);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// 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.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const rangef& getPhiRange() const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set the range of possible values for the central angle.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void setPhiRange(const rangef& r);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// 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.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void place(Particle* P) const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
2005-08-25 22:12:08 +08:00
|
|
|
/// return the control position
|
|
|
|
inline osg::Vec3 getControlPosition() const;
|
|
|
|
|
2002-06-05 20:44:55 +08:00
|
|
|
protected:
|
|
|
|
virtual ~SectorPlacer() {}
|
2005-04-29 17:47:57 +08:00
|
|
|
SectorPlacer& operator=(const SectorPlacer&) { return *this; }
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
private:
|
2005-04-29 17:47:57 +08:00
|
|
|
rangef _rad_range;
|
|
|
|
rangef _phi_range;
|
2002-06-05 20:44:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
inline SectorPlacer::SectorPlacer()
|
2005-04-29 17:47:57 +08:00
|
|
|
: CenteredPlacer(), _rad_range(0, 1), _phi_range(0, osg::PI*2)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline SectorPlacer::SectorPlacer(const SectorPlacer& copy, const osg::CopyOp& copyop)
|
|
|
|
: CenteredPlacer(copy, copyop), _rad_range(copy._rad_range), _phi_range(copy._phi_range)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const rangef& SectorPlacer::getRadiusRange() const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _rad_range;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const rangef& SectorPlacer::getPhiRange() const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _phi_range;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void SectorPlacer::setRadiusRange(const rangef& r)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_rad_range = r;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SectorPlacer::setRadiusRange(float r1, float r2)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_rad_range.minimum = r1;
|
|
|
|
_rad_range.maximum = r2;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void SectorPlacer::setPhiRange(const rangef& r)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_phi_range = r;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SectorPlacer::setPhiRange(float r1, float r2)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_phi_range.minimum = r1;
|
|
|
|
_phi_range.maximum = r2;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void SectorPlacer::place(Particle* P) const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
float rad = _rad_range.get_random_sqrtf();
|
|
|
|
float phi = _phi_range.get_random();
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
osg::Vec3 pos(
|
|
|
|
getCenter().x() + rad * cosf(phi),
|
|
|
|
getCenter().y() + rad * sinf(phi),
|
|
|
|
getCenter().z());
|
|
|
|
|
|
|
|
P->setPosition(pos);
|
|
|
|
}
|
|
|
|
|
2005-08-25 22:12:08 +08:00
|
|
|
inline osg::Vec3 SectorPlacer::getControlPosition() const
|
|
|
|
{
|
|
|
|
return getCenter();
|
|
|
|
}
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|