OpenSceneGraph 3.6.5
ConstantRateCounter
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
22namespace osgParticle
23{
24
26 public:
34
42
43
45
46 void setMinimumNumberOfParticlesToCreate(int minNumToCreate) { _minimumNumberOfParticlesToCreate = minNumToCreate; }
48
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
67 virtual int getEstimatedMaxNumOfParticles(double lifeTime) const
68 {
69 int minNumParticles = static_cast<int>(_minimumNumberOfParticlesToCreate*60.0f*lifeTime);
70 int baseNumPartciles = static_cast<int>(_numberOfParticlesPerSecondToCreate * lifeTime);
71 return osg::maximum(minNumParticles, baseNumPartciles);
72 }
73
74
75 protected:
77
80 mutable double _carryOver;
81 };
82
83}
84
85
86#endif
T maximum(T lhs, T rhs)
return the maximum of two values, equivalent to std::max.
Definition Math:85
The osgParticle library is a NodeKit that extends the core scene graph to support particle effects.
Definition AccelOperator:27
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
double _numberOfParticlesPerSecondToCreate
Definition ConstantRateCounter:79
virtual ~ConstantRateCounter()
Definition ConstantRateCounter:76
double _carryOver
Definition ConstantRateCounter:80
META_Object(osgParticle, ConstantRateCounter)
void setNumberOfParticlesPerSecondToCreate(double numPerSecond)
Definition ConstantRateCounter:49
virtual int getEstimatedMaxNumOfParticles(double lifeTime) const
get the esimated maximum number of particles that would be generated duration the lifetime of a parti...
Definition ConstantRateCounter:67
int _minimumNumberOfParticlesToCreate
Definition ConstantRateCounter:78
virtual int numParticlesToCreate(double dt) const
Return the number of particles to be created in this frame.
Definition ConstantRateCounter:53
int getMinimumNumberOfParticlesToCreate() const
Definition ConstantRateCounter:47
double getNumberOfParticlesPerSecondToCreate() const
Definition ConstantRateCounter:50
void setMinimumNumberOfParticlesToCreate(int minNumToCreate)
Definition ConstantRateCounter:46
ConstantRateCounter()
Definition ConstantRateCounter:27
ConstantRateCounter(const ConstantRateCounter &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition ConstantRateCounter:35
Counter()
Definition Counter:46

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