diff --git a/include/osgParticle/BoxPlacer b/include/osgParticle/BoxPlacer index a65b105bc..2be046bc9 100644 --- a/include/osgParticle/BoxPlacer +++ b/include/osgParticle/BoxPlacer @@ -71,7 +71,7 @@ namespace osgParticle inline void place(Particle* P) const; /// return the volume of the box - inline float size() const; + inline float volume() const; /// return the control position inline osg::Vec3 getControlPosition() const; @@ -157,7 +157,7 @@ namespace osgParticle P->setPosition(pos); } - inline float BoxPlacer::size() const + inline float BoxPlacer::volume() const { return (_x_range.maximum - _x_range.minimum) * (_y_range.maximum - _y_range.minimum) * diff --git a/include/osgParticle/CompositePlacer b/include/osgParticle/CompositePlacer index e54d7a94f..744dc9838 100644 --- a/include/osgParticle/CompositePlacer +++ b/include/osgParticle/CompositePlacer @@ -58,7 +58,7 @@ public: inline void place( Particle* P ) const; /// return the volume of the box - inline float size() const; + inline float volume() const; /// return the control position inline osg::Vec3 getControlPosition() const; @@ -75,20 +75,20 @@ protected: inline void CompositePlacer::place( Particle* P ) const { - rangef sizeRange( 0.0f, size() ); + rangef sizeRange( 0.0f, volume() ); float current = 0.0f, selected = sizeRange.get_random(); for ( PlacerList::const_iterator itr=_placers.begin(); itr!=_placers.end(); ++itr ) { - current += (*itr)->size(); + current += (*itr)->volume(); if ( selected<=current ) (*itr)->place( P ); } } -inline float CompositePlacer::size() const +inline float CompositePlacer::volume() const { float total_size = 0.0f; for ( PlacerList::const_iterator itr=_placers.begin(); itr!=_placers.end(); ++itr ) - total_size += (*itr)->size(); + total_size += (*itr)->volume(); return total_size; } diff --git a/include/osgParticle/MultiSegmentPlacer b/include/osgParticle/MultiSegmentPlacer index 3bf8b0c1d..19e103319 100644 --- a/include/osgParticle/MultiSegmentPlacer +++ b/include/osgParticle/MultiSegmentPlacer @@ -65,7 +65,7 @@ namespace osgParticle { void place(Particle* P) const; /// return the length of the multi-segment - inline float size() const; + inline float volume() const; /// return the control position inline osg::Vec3 getControlPosition() const; @@ -130,7 +130,7 @@ namespace osgParticle { recompute_length(); } - inline float MultiSegmentPlacer::size() const + inline float MultiSegmentPlacer::volume() const { return _total_length; } diff --git a/include/osgParticle/Particle b/include/osgParticle/Particle index 7375ca8d4..e5a6f9a52 100644 --- a/include/osgParticle/Particle +++ b/include/osgParticle/Particle @@ -142,7 +142,7 @@ namespace osgParticle inline const osg::Vec4& getCurrentColor() const { return _current_color; } /// Get the current alpha - inline float getCurrentAlpha() const { return _base_prop.z(); } + inline float getCurrentAlpha() const { return _current_alpha; } /// Get the s texture coordinate of the bottom left of the particle inline float getSTexCoord() const { return _s_coord; } @@ -302,7 +302,6 @@ namespace osgParticle osg::ref_ptr _ai; osg::ref_ptr _ci; - //bool _alive; bool _mustdie; double _lifeTime; @@ -319,8 +318,9 @@ namespace osgParticle double _t0; - //float _current_size; - //float _current_alpha; + float _alive; + float _current_size; + float _current_alpha; osg::Vec3 _base_prop; // [0] _alive [1] _current_size [2] _current_alpha osg::Vec4 _current_color; @@ -357,7 +357,7 @@ namespace osgParticle inline bool Particle::isAlive() const { - return _base_prop.x()>0.0; + return _alive>0.0f; } inline double Particle::getLifeTime() const @@ -597,7 +597,7 @@ namespace osgParticle inline float Particle::getCurrentSize() const { - return _base_prop.y(); + return _current_size; } diff --git a/include/osgParticle/Placer b/include/osgParticle/Placer index 65c501c92..662f64667 100644 --- a/include/osgParticle/Placer +++ b/include/osgParticle/Placer @@ -40,8 +40,8 @@ namespace osgParticle /// Place a particle. Must be implemented in descendant classes. virtual void place(Particle* P) const = 0; - /// Size of the placer. Can be implemented in descendant classes. - virtual float size() const { return 1.0f; } + /// Volume of the placer. Can be implemented in descendant classes. + virtual float volume() const { return 1.0f; } /// Return the control position of particles that placer will generate. Must be implemented in descendant classes. virtual osg::Vec3 getControlPosition() const = 0; diff --git a/include/osgParticle/SectorPlacer b/include/osgParticle/SectorPlacer index 693280f5c..ae852e784 100644 --- a/include/osgParticle/SectorPlacer +++ b/include/osgParticle/SectorPlacer @@ -62,7 +62,7 @@ namespace osgParticle inline void place(Particle* P) const; /// return the area of the sector - inline float size() const; + inline float volume() const; /// return the control position inline osg::Vec3 getControlPosition() const; @@ -133,7 +133,7 @@ namespace osgParticle P->setPosition(pos); } - inline float SectorPlacer::size() const + inline float SectorPlacer::volume() const { return 0.5f * (_phi_range.maximum - _phi_range.minimum) * (_rad_range.maximum*_rad_range.maximum - _rad_range.minimum*_rad_range.minimum); diff --git a/include/osgParticle/SegmentPlacer b/include/osgParticle/SegmentPlacer index 7661f7236..22a5e1be6 100644 --- a/include/osgParticle/SegmentPlacer +++ b/include/osgParticle/SegmentPlacer @@ -61,7 +61,7 @@ namespace osgParticle { inline void place(Particle* P) const; /// return the length of the segment - inline float size() const; + inline float volume() const; /// return the control position inline osg::Vec3 getControlPosition() const; @@ -108,7 +108,7 @@ namespace osgParticle { P->setPosition(rangev3(_vertexA, _vertexB).get_random()); } - inline float SegmentPlacer::size() const + inline float SegmentPlacer::volume() const { return (_vertexB - _vertexA).length(); } diff --git a/src/osgParticle/Particle.cpp b/src/osgParticle/Particle.cpp index b72f04bde..a4a618912 100644 --- a/src/osgParticle/Particle.cpp +++ b/src/osgParticle/Particle.cpp @@ -28,7 +28,6 @@ osgParticle::Particle::Particle() _si(new LinearInterpolator), _ai(new LinearInterpolator), _ci(new LinearInterpolator), - //_alive(true), _mustdie(false), _lifeTime(2), _radius(0.2f), @@ -41,8 +40,9 @@ osgParticle::Particle::Particle() _angle(0, 0, 0), _angul_arvel(0, 0, 0), _t0(0), - //_current_size(0), - //_current_alpha(0), + _alive(1.0f), + _current_size(0.0f), + _current_alpha(0.0f), _s_tile(1.0f), _t_tile(1.0f), _start_tile(0), @@ -54,7 +54,6 @@ osgParticle::Particle::Particle() _nextParticle(INVALID_INDEX), _depth(0.0) { - _base_prop.set(1.0f, 0.0f, 0.0f); } bool osgParticle::Particle::update(double dt, bool onlyTimeStamp) @@ -62,7 +61,7 @@ bool osgParticle::Particle::update(double dt, bool onlyTimeStamp) // this method should return false when the particle dies; // so, if we were instructed to die, do it now and return. if (_mustdie) { - _base_prop.x() = -1.0; + _alive = -1.0; return false; } @@ -77,20 +76,20 @@ bool osgParticle::Particle::update(double dt, bool onlyTimeStamp) // if our age is over the lifetime limit, then die and return. if (x > 1) { - _base_prop.x() = -1.0; + _alive = -1.0; return false; } // compute the current values for size, alpha and color. if (_lifeTime <= 0) { if (dt == _t0) { - _base_prop.y() = _sr.get_random(); - _base_prop.z() = _ar.get_random(); + _current_size = _sr.get_random(); + _current_alpha = _ar.get_random(); _current_color = _cr.get_random(); } } else { - _base_prop.y() = _si.get()->interpolate(x, _sr); - _base_prop.z() = _ai.get()->interpolate(x, _ar); + _current_size = _si.get()->interpolate(x, _sr); + _current_alpha = _ai.get()->interpolate(x, _ar); _current_color = _ci.get()->interpolate(x, _cr); } @@ -135,10 +134,10 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3& gl->Color4f( _current_color.x(), _current_color.y(), _current_color.z(), - _current_color.w() * _base_prop.z()); + _current_color.w() * _current_alpha); - osg::Vec3 p1(px * _base_prop.y() * scale); - osg::Vec3 p2(py * _base_prop.y() * scale); + osg::Vec3 p1(px * _current_size * scale); + osg::Vec3 p2(py * _current_size * scale); switch (_shape) { @@ -205,7 +204,7 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3& // calculation of one of the linesegment endpoints. float vl = _velocity.length(); if (vl != 0) { - osg::Vec3 v = _velocity * _base_prop.y() * scale / vl; + osg::Vec3 v = _velocity * _current_size * scale / vl; gl->TexCoord1f(0); gl->Vertex3f(xpos.x(), xpos.y(), xpos.z()); @@ -229,7 +228,7 @@ void osgParticle::Particle::render(osg::RenderInfo& renderInfo, const osg::Vec3& glColor4f(_current_color.x(), _current_color.y(), _current_color.z(), - _current_color.w() * _base_prop.z()); + _current_color.w() * _current_alpha); glPushMatrix(); glTranslatef(xpos.x(), xpos.y(), xpos.z()); if (requiresRotation) diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index 2ce0ce55e..1a98498e2 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -495,7 +495,7 @@ void osgParticle::ParticleSystem::render_vertex_array(osg::RenderInfo& renderInf GLsizei posOffset = (float*)(&(itr->_position)) - ptr; // Position GLsizei colorOffset = (float*)(&(itr->_current_color)) - ptr; // Color GLsizei velOffset = (float*)(&(itr->_velocity)) - ptr; // Velocity - GLsizei propOffset = (float*)(&(itr->_base_prop)) - ptr; // Alive, size & alpha + GLsizei propOffset = (float*)(&(itr->_alive)) - ptr; // Alive, size & alpha // Draw particles as arrays osg::State& state = *renderInfo.getState();