From 44d0bb05e70f448181be60c9b09a48ef5c45c2ea Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Jul 2002 09:14:46 +0000 Subject: [PATCH] Updates from Macro to support the new multitexture API, and improve bounding box computation. --- include/osgParticle/Particle | 8 ++++++++ include/osgParticle/ParticleSystem | 20 ++++++++++---------- src/osgParticle/ParticleSystem.cpp | 8 ++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/osgParticle/Particle b/include/osgParticle/Particle index 1de466d9e..14675e649 100644 --- a/include/osgParticle/Particle +++ b/include/osgParticle/Particle @@ -171,6 +171,9 @@ namespace osgParticle /// Perform some post-rendering tasks. Called automatically by particle systems. inline void endRender(); + + /// Get the current (interpolated) polygon size. Valid only after the first call to update(). + inline float getCurrentSize() const; private: Shape shape_; @@ -391,6 +394,11 @@ namespace osgParticle default: ; } } + + inline float Particle::getCurrentSize() const + { + return current_size_; + } } diff --git a/include/osgParticle/ParticleSystem b/include/osgParticle/ParticleSystem index 510f31892..943a9d770 100644 --- a/include/osgParticle/ParticleSystem +++ b/include/osgParticle/ParticleSystem @@ -104,7 +104,7 @@ namespace osgParticle /** A useful method to set the most common StateAttribute's in one call. If texturefile is empty, then texturing is turned off. */ - void setDefaultAttributes(const std::string &texturefile = "", bool emissive_particles = true, bool lighting = false); + void setDefaultAttributes(const std::string &texturefile = "", bool emissive_particles = true, bool lighting = false, int texture_unit = 0); /// (EXPERIMENTAL) Get the level of detail. inline int getLevelOfDetail() const; @@ -126,7 +126,7 @@ namespace osgParticle inline virtual const bool computeBound() const; virtual void drawImmediateMode(osg::State &state); - inline void update_bounds(const osg::Vec3 &p); + inline void update_bounds(const osg::Vec3 &p, float r); void single_pass_render(const osg::Matrix &modelview); private: @@ -237,19 +237,19 @@ namespace osgParticle return true; } - inline void ParticleSystem::update_bounds(const osg::Vec3 &p) + inline void ParticleSystem::update_bounds(const osg::Vec3 &p, float r) { if (reset_bounds_flag_) { reset_bounds_flag_ = false; bmin_ = p; - bmax_ = p; + bmax_ = p; } else { - if (p.x() < bmin_.x()) bmin_.x() = p.x(); - if (p.y() < bmin_.y()) bmin_.y() = p.y(); - if (p.z() < bmin_.z()) bmin_.z() = p.z(); - if (p.x() > bmax_.x()) bmax_.x() = p.x(); - if (p.y() > bmax_.y()) bmax_.y() = p.y(); - if (p.z() > bmax_.z()) bmax_.z() = p.z(); + if (p.x() - r < bmin_.x()) bmin_.x() = p.x() - r; + if (p.y() - r < bmin_.y()) bmin_.y() = p.y() - r; + if (p.z() - r < bmin_.z()) bmin_.z() = p.z() - r; + if (p.x() + r > bmax_.x()) bmax_.x() = p.x() + r; + if (p.y() + r > bmax_.y()) bmax_.y() = p.y() + r; + if (p.z() + r > bmax_.z()) bmax_.z() = p.z() + r; if (!bounds_computed_) bounds_computed_ = true; diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index dd3e50e2c..a793b34c8 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -69,7 +69,7 @@ void osgParticle::ParticleSystem::update(double dt) for (i=particles_.begin(); i!=end; ++i) { if (i->isAlive()) { if (i->update(dt)) { - update_bounds(i->getPosition()); + update_bounds(i->getPosition(), i->getCurrentSize()); } else { deadparts_.push(&(*i)); } @@ -136,7 +136,7 @@ void osgParticle::ParticleSystem::drawImmediateMode(osg::State &state) } } -void osgParticle::ParticleSystem::setDefaultAttributes(const std::string &texturefile, bool emissive_particles, bool lighting) +void osgParticle::ParticleSystem::setDefaultAttributes(const std::string &texturefile, bool emissive_particles, bool lighting, int texture_unit) { osg::StateSet *stateset = osgNew osg::StateSet; @@ -154,11 +154,11 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string &textur texture->setImage(osgDB::readImageFile(texturefile)); texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); - stateset->setAttributeAndModes(texture, osg::StateAttribute::ON); + stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON); osg::TexEnv *texenv = osgNew osg::TexEnv; texenv->setMode(osg::TexEnv::MODULATE); - stateset->setAttribute(texenv); + stateset->setTextureAttribute(texture_unit, texenv); } osg::Transparency *transparency = osgNew osg::Transparency;