OSG
3.4.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
osg_head
include
osgParticle
RandomRateCounter.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
//osgParticle - Copyright (C) 2002 Marco Jez
14
15
#ifndef OSGPARTICLE_RANDOMRATE_COUNTER
16
#define OSGPARTICLE_RANDOMRATE_COUNTER 1
17
18
#include <osgParticle/VariableRateCounter>
19
20
#include <osg/CopyOp>
21
#include <osg/Object>
22
23
namespace
osgParticle
24
{
25
26
class
RandomRateCounter
:
public
VariableRateCounter
{
27
public
:
28
inline
RandomRateCounter
();
29
inline
RandomRateCounter
(
const
RandomRateCounter
& copy,
const
osg::CopyOp
& copyop =
osg::CopyOp::SHALLOW_COPY
);
30
31
META_Object
(
osgParticle
,
RandomRateCounter
);
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
44
inline
RandomRateCounter::RandomRateCounter
()
45
:
VariableRateCounter
(), _np(0)
46
{
47
}
48
49
inline
RandomRateCounter::RandomRateCounter
(
const
RandomRateCounter
& copy,
const
osg::CopyOp
& copyop)
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
osgParticle::RandomRateCounter::META_Object
META_Object(osgParticle, RandomRateCounter)
osgParticle::RandomRateCounter
Definition:
RandomRateCounter.h:26
osgParticle
Definition:
AccelOperator.h:26
osg::minimum
T minimum(T lhs, T rhs)
Definition:
Math.h:59
osg::CopyOp::SHALLOW_COPY
Definition:
CopyOp.h:47
osgParticle::VariableRateCounter::getRateRange
const rangef & getRateRange() const
Definition:
VariableRateCounter.h:59
osgParticle::RandomRateCounter::numParticlesToCreate
int numParticlesToCreate(double dt) const
Return the number of particles to be created in this frame.
Definition:
RandomRateCounter.h:54
osg::maximum
T maximum(T lhs, T rhs)
Definition:
Math.h:66
osgParticle::RandomRateCounter::RandomRateCounter
RandomRateCounter()
Definition:
RandomRateCounter.h:44
osgParticle::VariableRateCounter
Definition:
VariableRateCounter.h:27
osgParticle::RandomRateCounter::~RandomRateCounter
virtual ~RandomRateCounter()
Definition:
RandomRateCounter.h:37
osg::CopyOp
Definition:
CopyOp.h:40
osgParticle::RandomRateCounter::_np
float _np
Definition:
RandomRateCounter.h:39
Generated on Tue Oct 4 2016 19:20:48 for OSG by
1.8.8