CompositePlacer
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 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.
*/
// Written by Wang Rui, (C) 2010
#ifndef OSGPARTICLE_COMPOSITEPLACER
#define OSGPARTICLE_COMPOSITEPLACER
#include <osgParticle/Placer>
#include <osgParticle/Particle>
namespace osgParticle
{
class CompositePlacer : public Placer
{
public:
CompositePlacer() : Placer() {}
CompositePlacer( const CompositePlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY )
: Placer(copy, copyop), _placers(copy._placers) {}
META_Object( osgParticle, CompositePlacer );
// Set a child placer at specific index
void setPlacer( unsigned int i, Placer* p )
{
if (i<_placers.size()) _placers[i] = p;
else addPlacer(p);
}
void addPlacer( Placer* p ) { _placers.push_back(p); }
void removePlacer( unsigned int i )
{ if (i<_placers.size()) _placers.erase(_placers.begin()+i); }
Placer* getPlacer( unsigned int i ) { return _placers[i].get(); }
const Placer* getPlacer( unsigned int i ) const { return _placers[i].get(); }
unsigned int getNumPlacers() const { return _placers.size(); }
inline void place( Particle* P ) const;
inline float volume() const;
inline osg::Vec3 getControlPosition() const;
protected:
virtual ~CompositePlacer() {}
CompositePlacer& operator=( const CompositePlacer& ) { return *this; }
typedef std::vector< osg::ref_ptr<Placer> > PlacerList;
PlacerList _placers;
};
// INLINE METHODS
inline void CompositePlacer::place( Particle* P ) const
{
rangef sizeRange( 0.0f, volume() );
float current = 0.0f, selected = sizeRange.get_random();
for ( PlacerList::const_iterator itr=_placers.begin(); itr!=_placers.end(); ++itr )
{
current += (*itr)->volume();
if ( selected<=current ) (*itr)->place( P );
}
}
inline float CompositePlacer::volume() const
{
float total_size = 0.0f;
for ( PlacerList::const_iterator itr=_placers.begin(); itr!=_placers.end(); ++itr )
total_size += (*itr)->volume();
return total_size;
}
inline osg::Vec3 CompositePlacer::getControlPosition() const
{
if ( !_placers.size() ) return osg::Vec3();
return _placers.front()->getControlPosition();
}
}
#endif
Particle
Placer
osgParticle::CompositePlacer::setPlacer
void setPlacer(unsigned int i, Placer *p)
Definition CompositePlacer:37
osgParticle::CompositePlacer::CompositePlacer
CompositePlacer(const CompositePlacer &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition CompositePlacer:31
osgParticle::CompositePlacer::volume
float volume() const
return the volume of the box
Definition CompositePlacer:87
osgParticle::CompositePlacer::PlacerList
std::vector< osg::ref_ptr< Placer > > PlacerList
Definition CompositePlacer:70
osgParticle::CompositePlacer::getPlacer
Placer * getPlacer(unsigned int i)
Get a child placer.
Definition CompositePlacer:51
osgParticle::CompositePlacer::getPlacer
const Placer * getPlacer(unsigned int i) const
Definition CompositePlacer:52
osgParticle::CompositePlacer::addPlacer
void addPlacer(Placer *p)
Add a child placer.
Definition CompositePlacer:44
osgParticle::CompositePlacer::META_Object
META_Object(osgParticle, CompositePlacer)
osgParticle::CompositePlacer::removePlacer
void removePlacer(unsigned int i)
Remove a child placer.
Definition CompositePlacer:47
osgParticle::CompositePlacer::getControlPosition
osg::Vec3 getControlPosition() const
return the control position
Definition CompositePlacer:95
osgParticle::CompositePlacer::CompositePlacer
CompositePlacer()
Definition CompositePlacer:29
osgParticle::CompositePlacer::~CompositePlacer
virtual ~CompositePlacer()
Definition CompositePlacer:67
osgParticle::CompositePlacer::getNumPlacers
unsigned int getNumPlacers() const
Get number of placers.
Definition CompositePlacer:55
osgParticle::CompositePlacer::_placers
PlacerList _placers
Definition CompositePlacer:71
osgParticle::CompositePlacer::operator=
CompositePlacer & operator=(const CompositePlacer &)
Definition CompositePlacer:68
osgParticle::CompositePlacer::place
void place(Particle *P) const
Place a particle. Do not call it manually.
Definition CompositePlacer:76
osgParticle::Particle
Definition Particle:47
osgParticle::Placer::Placer
Placer()
Definition Placer:56
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osgParticle
Definition AccelOperator:27
osgParticle::rangef
range< float > rangef
Range of floats.
Definition range:76
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osgParticle::range::get_random
ValueType get_random() const
Get a random value between min and max.
Definition range:57