OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstantRateCounter.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 
14 #ifndef OSGPARTICLE_CONSTANTRATECOUNTER
15 #define OSGPARTICLE_CONSTANTRATECOUNTER 1
16 
17 #include <osgParticle/Counter>
18 
19 #include <osg/Object>
20 #include <osg/Math>
21 
22 namespace osgParticle
23 {
24 
25  class ConstantRateCounter: public Counter {
26  public:
28  Counter(),
31  _carryOver(0)
32  {
33  }
34 
36  Counter(copy, copyop),
40  {
41  }
42 
43 
45 
46  void setMinimumNumberOfParticlesToCreate(int minNumToCreate) { _minimumNumberOfParticlesToCreate = minNumToCreate; }
48 
49  void setNumberOfParticlesPerSecondToCreate(double numPerSecond) { _numberOfParticlesPerSecondToCreate = numPerSecond; }
51 
53  virtual int numParticlesToCreate(double dt) const
54  {
56  int i = (int)(v);
57  _carryOver += (v-(double)i);
58  if (_carryOver>1.0)
59  {
60  ++i;
61  _carryOver -= 1.0;
62  }
64  }
65 
66  protected:
67  virtual ~ConstantRateCounter() {}
68 
71  mutable double _carryOver;
72  };
73 
74 }
75 
76 
77 #endif
ConstantRateCounter(const ConstantRateCounter &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
META_Object(osgParticle, ConstantRateCounter)
double getNumberOfParticlesPerSecondToCreate() const
T maximum(T lhs, T rhs)
Definition: Math.h:66
void setNumberOfParticlesPerSecondToCreate(double numPerSecond)
virtual int numParticlesToCreate(double dt) const
Return the number of particles to be created in this frame.
void setMinimumNumberOfParticlesToCreate(int minNumToCreate)