OpenSceneGraph 3.6.5
RandomRateCounter
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//osgParticle - Copyright (C) 2002 Marco Jez
14
15#ifndef OSGPARTICLE_RANDOMRATE_COUNTER
16#define OSGPARTICLE_RANDOMRATE_COUNTER 1
17
19
20#include <osg/CopyOp>
21#include <osg/Object>
22
23namespace osgParticle
24{
25
27 public:
28 inline RandomRateCounter();
30
32
34 inline int numParticlesToCreate(double dt) const;
35
36 protected:
37 virtual ~RandomRateCounter() {}
38
39 mutable float _np;
40 };
41
42 // INLINE FUNCTIONS
43
48
50 : VariableRateCounter(copy, copyop), _np(copy._np)
51 {
52 }
53
54 inline int RandomRateCounter::numParticlesToCreate(double dt) const
55 {
56 // compute the number of new particles, clamping it to 1 second of particles at the maximum rate
57 float numNewParticles = osg::minimum(static_cast<float>(dt * getRateRange().get_random()), getRateRange().maximum);
58
59 // add the number of new particles to value carried over from the previous call
60 _np += numNewParticles;
61
62 // round down the number of particles.
63 int n = static_cast<int>(_np);
64
65 // take away the number of rounded number of particles leaving the decimal place
66 // this is done so that two frames of 0.5's will results in first frame 0 new particles, second frame 1
67 _np -= n;
68
69 // return the rounded number of particles to be created
70 return n;
71 }
72
73}
74
75
76#endif
T minimum(T lhs, T rhs)
return the minimum of two values, equivalent to std::min.
Definition Math:78
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
virtual ~RandomRateCounter()
Definition RandomRateCounter:37
float _np
Definition RandomRateCounter:39
int numParticlesToCreate(double dt) const
Return the number of particles to be created in this frame.
Definition RandomRateCounter:54
RandomRateCounter()
Definition RandomRateCounter:44
META_Object(osgParticle, RandomRateCounter)
VariableRateCounter()
Definition VariableRateCounter:51
const rangef & getRateRange() const
Definition VariableRateCounter:61

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.