openscenegraph
VariableRateCounter
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_VARIABLERATE_COUNTER
16#define OSGPARTICLE_VARIABLERATE_COUNTER 1
17
18#include <osgParticle/Counter>
19#include <osgParticle/range>
20
21#include <osg/CopyOp>
22#include <osg/Object>
23
24namespace osgParticle
25{
26
27 class VariableRateCounter: public Counter {
28 public:
29 inline VariableRateCounter();
30 inline VariableRateCounter(const VariableRateCounter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
31
32 virtual const char* libraryName() const { return "osgParticle"; }
33 virtual const char* className() const { return "VariableRateCounter"; }
34 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const VariableRateCounter *>(obj) != 0; }
35
36 inline const rangef& getRateRange() const;
37 inline void setRateRange(const rangef& r);
38 inline void setRateRange(float minrange, float maxrange);
39
40 virtual int getEstimatedMaxNumOfParticles(double lifeTime) const { return static_cast<int>(_rate_range.maximum * lifeTime); }
41
42 protected:
43 virtual ~VariableRateCounter() {}
44
45 private:
46 rangef _rate_range;
47 };
48
49 // INLINE FUNCTIONS
50
51 inline VariableRateCounter::VariableRateCounter()
52 : Counter(), _rate_range(1, 1)
53 {
54 }
55
56 inline VariableRateCounter::VariableRateCounter(const VariableRateCounter& copy, const osg::CopyOp& copyop)
57 : Counter(copy, copyop), _rate_range(copy._rate_range)
58 {
59 }
60
61 inline const rangef &VariableRateCounter::getRateRange() const
62 {
63 return _rate_range;
64 }
65
66 inline void VariableRateCounter::setRateRange(const rangef& r)
67 {
68 _rate_range = r;
69 }
70
71 inline void VariableRateCounter::setRateRange(float minrange, float maxrange)
72 {
73 _rate_range.set(minrange, maxrange);
74 }
75
76}
77
78
79#endif