OpenSceneGraph 3.6.5
CompositePlacer
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13// Written by Wang Rui, (C) 2010
14
15#ifndef OSGPARTICLE_COMPOSITEPLACER
16#define OSGPARTICLE_COMPOSITEPLACER
17
18#include <osgParticle/Placer>
19#include <osgParticle/Particle>
20
21namespace osgParticle
22{
23
24
26class CompositePlacer : public Placer
27{
28public:
30
32 : Placer(copy, copyop), _placers(copy._placers) {}
33
35
36 // Set a child placer at specific index
37 void setPlacer( unsigned int i, Placer* p )
38 {
39 if (i<_placers.size()) _placers[i] = p;
40 else addPlacer(p);
41 }
42
44 void addPlacer( Placer* p ) { _placers.push_back(p); }
45
47 void removePlacer( unsigned int i )
48 { if (i<_placers.size()) _placers.erase(_placers.begin()+i); }
49
51 Placer* getPlacer( unsigned int i ) { return _placers[i].get(); }
52 const Placer* getPlacer( unsigned int i ) const { return _placers[i].get(); }
53
55 unsigned int getNumPlacers() const { return _placers.size(); }
56
58 inline void place( Particle* P ) const;
59
61 inline float volume() const;
62
64 inline osg::Vec3 getControlPosition() const;
65
66protected:
67 virtual ~CompositePlacer() {}
68 CompositePlacer& operator=( const CompositePlacer& ) { return *this; }
69
70 typedef std::vector< osg::ref_ptr<Placer> > PlacerList;
72};
73
74// INLINE METHODS
75
76inline void CompositePlacer::place( Particle* P ) const
77{
78 rangef sizeRange( 0.0f, volume() );
79 float current = 0.0f, selected = sizeRange.get_random();
80 for ( PlacerList::const_iterator itr=_placers.begin(); itr!=_placers.end(); ++itr )
81 {
82 current += (*itr)->volume();
83 if ( selected<=current ) (*itr)->place( P );
84 }
85}
86
87inline float CompositePlacer::volume() const
88{
89 float total_size = 0.0f;
90 for ( PlacerList::const_iterator itr=_placers.begin(); itr!=_placers.end(); ++itr )
91 total_size += (*itr)->volume();
92 return total_size;
93}
94
96{
97 if ( !_placers.size() ) return osg::Vec3();
98 return _placers.front()->getControlPosition();
99}
100
101
102}
103
104#endif
Vec3f Vec3
Definition Vec3:21
The osgParticle library is a NodeKit that extends the core scene graph to support particle effects.
Definition AccelOperator:27
range< float > rangef
Range of floats.
Definition range:76
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
void setPlacer(unsigned int i, Placer *p)
Definition CompositePlacer:37
CompositePlacer(const CompositePlacer &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition CompositePlacer:31
float volume() const
return the volume of the box
Definition CompositePlacer:87
std::vector< osg::ref_ptr< Placer > > PlacerList
Definition CompositePlacer:70
Placer * getPlacer(unsigned int i)
Get a child placer.
Definition CompositePlacer:51
const Placer * getPlacer(unsigned int i) const
Definition CompositePlacer:52
void addPlacer(Placer *p)
Add a child placer.
Definition CompositePlacer:44
META_Object(osgParticle, CompositePlacer)
void removePlacer(unsigned int i)
Remove a child placer.
Definition CompositePlacer:47
osg::Vec3 getControlPosition() const
return the control position
Definition CompositePlacer:95
CompositePlacer()
Definition CompositePlacer:29
virtual ~CompositePlacer()
Definition CompositePlacer:67
unsigned int getNumPlacers() const
Get number of placers.
Definition CompositePlacer:55
PlacerList _placers
Definition CompositePlacer:71
CompositePlacer & operator=(const CompositePlacer &)
Definition CompositePlacer:68
void place(Particle *P) const
Place a particle. Do not call it manually.
Definition CompositePlacer:76
Implementation of a particle.
Definition Particle:47
Placer()
Definition Placer:56
ValueType get_random() const
Get a random value between min and max.
Definition range:57

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.