Ran script to remove trailing spaces and tabs
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
// Written by Wang Rui, (C) 2010
|
||||
@@ -23,19 +23,19 @@ void BounceOperator::handleTriangle( const Domain& domain, Particle* P, double d
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv);
|
||||
|
||||
|
||||
float upos = (hitPoint - domain.v1) * domain.s1;
|
||||
float vpos = (hitPoint - domain.v1) * domain.s2;
|
||||
if ( upos<0.0f || vpos<0.0f || (upos + vpos)>1.0f ) return;
|
||||
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
@@ -46,19 +46,19 @@ void BounceOperator::handleRectangle( const Domain& domain, Particle* P, double
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv);
|
||||
|
||||
|
||||
float upos = (hitPoint - domain.v1) * domain.s1;
|
||||
float vpos = (hitPoint - domain.v1) * domain.s2;
|
||||
if ( upos<0.0f || upos>1.0f || vpos<0.0f || vpos>1.0f ) return;
|
||||
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
@@ -69,14 +69,14 @@ void BounceOperator::handlePlane( const Domain& domain, Particle* P, double dt )
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
@@ -90,27 +90,27 @@ void BounceOperator::handleSphere( const Domain& domain, Particle* P, double dt
|
||||
{
|
||||
float distance2 = (nextpos - domain.v1).length();
|
||||
if ( distance2<=domain.r1 ) return;
|
||||
|
||||
|
||||
// Bounce back in if going outside
|
||||
osg::Vec3 normal = domain.v1 - P->getPosition(); normal.normalize();
|
||||
float nmag = P->getVelocity() * normal;
|
||||
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nmag;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
if ( nmag<0 ) vn = -vn;
|
||||
|
||||
|
||||
// Compute new velocity
|
||||
float tanscale = (vt.length2()<=_cutoff) ? 1.0f : (1.0f - _friction);
|
||||
P->setVelocity( vt * tanscale + vn * _resilience );
|
||||
|
||||
|
||||
// Make sure the particle is fixed to stay inside
|
||||
nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
distance2 = (nextpos - domain.v1).length();
|
||||
if ( distance2>domain.r1 )
|
||||
{
|
||||
normal = domain.v1 - nextpos; normal.normalize();
|
||||
|
||||
|
||||
osg::Vec3 wishPoint = domain.v1 - normal * (0.999f * domain.r1);
|
||||
P->setVelocity( (wishPoint - P->getPosition()) / dt );
|
||||
}
|
||||
@@ -119,16 +119,16 @@ void BounceOperator::handleSphere( const Domain& domain, Particle* P, double dt
|
||||
{
|
||||
float distance2 = (nextpos - domain.v1).length();
|
||||
if ( distance2>domain.r1 ) return;
|
||||
|
||||
|
||||
// Bounce back out if going inside
|
||||
osg::Vec3 normal = P->getPosition() - domain.v1; normal.normalize();
|
||||
float nmag = P->getVelocity() * normal;
|
||||
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nmag;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
if ( nmag<0 ) vn = -vn;
|
||||
|
||||
|
||||
// Compute new velocity
|
||||
float tanscale = (vt.length2()<=_cutoff) ? 1.0f : (1.0f - _friction);
|
||||
P->setVelocity( vt * tanscale + vn * _resilience );
|
||||
@@ -140,18 +140,18 @@ void BounceOperator::handleDisk( const Domain& domain, Particle* P, double dt )
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv);
|
||||
|
||||
|
||||
float radius = (hitPoint - domain.v1).length();
|
||||
if ( radius>domain.r1 || radius<domain.r2 ) return;
|
||||
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -43,13 +43,13 @@ Particle* ConnectedParticleSystem::createParticle(const Particle* ptemplate)
|
||||
|
||||
Particle* particle = ParticleSystem::createParticle(ptemplate);
|
||||
int particleIndex = (int)(particle - &_particles[0]);
|
||||
|
||||
|
||||
if (particle)
|
||||
{
|
||||
|
||||
|
||||
if (_startParticle == Particle::INVALID_INDEX)
|
||||
{
|
||||
// we are the fisrt particle create, so start the connect particle list
|
||||
// we are the fisrt particle create, so start the connect particle list
|
||||
_startParticle = particleIndex;
|
||||
}
|
||||
|
||||
@@ -64,18 +64,18 @@ Particle* ConnectedParticleSystem::createParticle(const Particle* ptemplate)
|
||||
|
||||
// set the new particle as the last particle created.
|
||||
_lastParticleCreated = particleIndex;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return particle;
|
||||
}
|
||||
|
||||
|
||||
void ConnectedParticleSystem::reuseParticle(int particleIndex)
|
||||
{
|
||||
// OSG_NOTICE<<this<< " Reusing particle "<<particleIndex<<std::endl;
|
||||
|
||||
if (particleIndex<0 || particleIndex>=(int)_particles.size()) return;
|
||||
|
||||
|
||||
Particle* particle = &_particles[particleIndex];
|
||||
int previous = particle->getPreviousParticle();
|
||||
int next = particle->getNextParticle();
|
||||
@@ -85,19 +85,19 @@ void ConnectedParticleSystem::reuseParticle(int particleIndex)
|
||||
{
|
||||
_startParticle = particle->getNextParticle();
|
||||
}
|
||||
|
||||
|
||||
if (_lastParticleCreated == particleIndex)
|
||||
{
|
||||
_lastParticleCreated = Particle::INVALID_INDEX;
|
||||
}
|
||||
|
||||
|
||||
// join up the previous and next particles to account for
|
||||
// the deletion of the this particle
|
||||
if (previous != Particle::INVALID_INDEX)
|
||||
{
|
||||
_particles[previous].setNextParticle(next);
|
||||
}
|
||||
|
||||
|
||||
if (next != Particle::INVALID_INDEX)
|
||||
{
|
||||
_particles[next].setPreviousParticle(previous);
|
||||
@@ -106,7 +106,7 @@ void ConnectedParticleSystem::reuseParticle(int particleIndex)
|
||||
// reset the next and previous particle entries of this particle
|
||||
particle->setPreviousParticle(Particle::INVALID_INDEX);
|
||||
particle->setNextParticle(Particle::INVALID_INDEX);
|
||||
|
||||
|
||||
// put the particle on the death stack
|
||||
ParticleSystem::reuseParticle(particleIndex);
|
||||
|
||||
@@ -121,7 +121,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co
|
||||
|
||||
const Particle* particle = (_startParticle != Particle::INVALID_INDEX) ? &_particles[_startParticle] : 0;
|
||||
if (!particle) return;
|
||||
|
||||
|
||||
|
||||
osg::Vec4 pixelSizeVector = osg::CullingSet::computePixelSizeVector(*state.getCurrentViewport(),state.getProjectionMatrix(),state.getModelViewMatrix());
|
||||
float unitPixelSize = fabs(1.0/(particle->getPosition()*pixelSizeVector));
|
||||
@@ -170,7 +170,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co
|
||||
else
|
||||
{
|
||||
|
||||
// draw the connected particles as a quad stripped aligned to be orthogonal to the eye
|
||||
// draw the connected particles as a quad stripped aligned to be orthogonal to the eye
|
||||
osg::Matrix eyeToLocalTransform;
|
||||
eyeToLocalTransform.invert(state.getModelViewMatrix());
|
||||
osg::Vec3 eyeLocal = osg::Vec3(0.0f,0.0,0.0f)*eyeToLocalTransform;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
// Written by Wang Rui, (C) 2010
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
#include <osg/CopyOp>
|
||||
|
||||
osgParticle::Emitter::Emitter()
|
||||
: ParticleProcessor(),
|
||||
: ParticleProcessor(),
|
||||
_usedeftemp(true)
|
||||
{
|
||||
}
|
||||
|
||||
osgParticle::Emitter::Emitter(const Emitter& copy, const osg::CopyOp& copyop)
|
||||
: ParticleProcessor(copy, copyop),
|
||||
_usedeftemp(copy._usedeftemp),
|
||||
_usedeftemp(copy._usedeftemp),
|
||||
_ptemp(copy._ptemp)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -29,28 +29,28 @@ ExplosionDebrisEffect::ExplosionDebrisEffect(bool automaticSetup):
|
||||
ParticleEffect(automaticSetup)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position.set(0.0f,0.0f,0.0f);
|
||||
_scale = 1.0f;
|
||||
_intensity = 1.0f;
|
||||
|
||||
|
||||
_emitterDuration = 0.1;
|
||||
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
ExplosionDebrisEffect::ExplosionDebrisEffect(const osg::Vec3& position, float scale, float intensity)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position = position;
|
||||
_scale = scale;
|
||||
_intensity = intensity;
|
||||
|
||||
|
||||
_emitterDuration = 0.1;
|
||||
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
@@ -63,16 +63,16 @@ ExplosionDebrisEffect::ExplosionDebrisEffect(const ExplosionDebrisEffect& copy,
|
||||
void ExplosionDebrisEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/particle.rgb";
|
||||
|
||||
_textureFileName = "Images/particle.rgb";
|
||||
_emitterDuration = 0.1;
|
||||
|
||||
|
||||
// set up unit particle.
|
||||
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
|
||||
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.0f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(0.5f, 0.5f, 0.0f, 1.0f),
|
||||
osg::Vec4(0.5f, 0.5f, 0.0f, 1.0f),
|
||||
osg::Vec4(0.2f, 0.2f, 0.2f, 0.5f)));
|
||||
|
||||
}
|
||||
@@ -92,12 +92,12 @@ void ExplosionDebrisEffect::setUpEmitterAndProgram()
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
|
||||
float radius = 0.05f*_scale;
|
||||
float radius = 0.05f*_scale;
|
||||
float density = 1000.0f; // 1000.0kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
@@ -154,15 +154,15 @@ void ExplosionDebrisEffect::setUpEmitterAndProgram()
|
||||
|
||||
// set up program.
|
||||
if (!_program)
|
||||
{
|
||||
{
|
||||
_program = new osgParticle::FluidProgram;
|
||||
}
|
||||
|
||||
|
||||
if (_program.valid())
|
||||
{
|
||||
_program->setParticleSystem(_particleSystem.get());
|
||||
_program->setWind(_wind);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -31,26 +31,26 @@ ExplosionEffect::ExplosionEffect(bool automaticSetup):
|
||||
ParticleEffect(automaticSetup)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position.set(0.0f,0.0f,0.0f);
|
||||
_scale = 1.0f;
|
||||
_intensity = 1.0f;
|
||||
|
||||
|
||||
_emitterDuration = 1.0;
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
ExplosionEffect::ExplosionEffect(const osg::Vec3& position, float scale, float intensity)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position = position;
|
||||
_scale = scale;
|
||||
_intensity = intensity;
|
||||
|
||||
|
||||
_emitterDuration = 1.0;
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ ExplosionEffect::ExplosionEffect(const ExplosionEffect& copy, const osg::CopyOp&
|
||||
void ExplosionEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
_emitterDuration = 1.0;
|
||||
|
||||
// set up unit particle.
|
||||
@@ -72,7 +72,7 @@ void ExplosionEffect::setDefaults()
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1.0f, 0.8f, 0.2f, 1.0f),
|
||||
osg::Vec4(1.0f, 0.8f, 0.2f, 1.0f),
|
||||
osg::Vec4(1.0f, 0.4f, 0.1f, 0.0f)));
|
||||
|
||||
}
|
||||
@@ -92,12 +92,12 @@ void ExplosionEffect::setUpEmitterAndProgram()
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
|
||||
float radius = 0.4f*_scale;
|
||||
float radius = 0.4f*_scale;
|
||||
float density = 1.2f; // 1.0kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
@@ -108,7 +108,7 @@ void ExplosionEffect::setUpEmitterAndProgram()
|
||||
ptemplate.setRadius(radius);
|
||||
ptemplate.setMass(density*radius*radius*radius*osg::PI*4.0f/3.0f);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// set up emitter
|
||||
@@ -154,15 +154,15 @@ void ExplosionEffect::setUpEmitterAndProgram()
|
||||
|
||||
// set up the program
|
||||
if (!_program)
|
||||
{
|
||||
{
|
||||
_program = new osgParticle::FluidProgram;
|
||||
}
|
||||
|
||||
|
||||
if (_program.valid())
|
||||
{
|
||||
_program->setParticleSystem(_particleSystem.get());
|
||||
_program->setWind(_wind);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -30,28 +30,28 @@ FireEffect::FireEffect(bool automaticSetup):
|
||||
ParticleEffect(automaticSetup)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position.set(0.0f,0.0f,0.0f);
|
||||
_scale = 1.0f;
|
||||
_intensity = 1.0f;
|
||||
|
||||
|
||||
_emitterDuration = 60.0;
|
||||
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
FireEffect::FireEffect(const osg::Vec3& position, float scale, float intensity)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position = position;
|
||||
_scale = scale;
|
||||
_intensity = intensity;
|
||||
|
||||
|
||||
_emitterDuration = 60.0;
|
||||
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ FireEffect::FireEffect(const FireEffect& copy, const osg::CopyOp& copyop):
|
||||
void FireEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
_emitterDuration = 60.0;
|
||||
|
||||
// set up unit particle.
|
||||
@@ -73,7 +73,7 @@ void FireEffect::setDefaults()
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1, 0.8f, 0.2f, 1.0f),
|
||||
osg::Vec4(1, 0.8f, 0.2f, 1.0f),
|
||||
osg::Vec4(1, 0.3f, 0.2f, 0.0f)));
|
||||
}
|
||||
|
||||
@@ -92,12 +92,12 @@ void FireEffect::setUpEmitterAndProgram()
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
|
||||
float radius = 0.25f*_scale;
|
||||
float radius = 0.25f*_scale;
|
||||
float density = 0.5f; // 0.5kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
@@ -157,10 +157,10 @@ void FireEffect::setUpEmitterAndProgram()
|
||||
|
||||
// set up program.
|
||||
if (!_program)
|
||||
{
|
||||
{
|
||||
_program = new osgParticle::FluidProgram;
|
||||
}
|
||||
|
||||
|
||||
if (_program.valid())
|
||||
{
|
||||
_program->setParticleSystem(_particleSystem.get());
|
||||
|
||||
@@ -20,7 +20,7 @@ osgParticle::FluidFrictionOperator::FluidFrictionOperator(const FluidFrictionOpe
|
||||
: Operator(copy, copyop),
|
||||
_coeff_A(copy._coeff_A),
|
||||
_coeff_B(copy._coeff_B),
|
||||
_density(copy._density),
|
||||
_density(copy._density),
|
||||
_viscosity(copy._viscosity),
|
||||
_ovr_rad(copy._ovr_rad),
|
||||
_current_program(0)
|
||||
@@ -34,9 +34,9 @@ void osgParticle::FluidFrictionOperator::operate(Particle* P, double dt)
|
||||
|
||||
float vm = v.normalize();
|
||||
float R = _coeff_A * r * vm + _coeff_B * r * r * vm * vm;
|
||||
|
||||
|
||||
osg::Vec3 Fr(-R * v.x(), -R * v.y(), -R * v.z());
|
||||
|
||||
|
||||
#if 0
|
||||
// Commenting out rotation of force vector rotation from local to world as the particle velocity itself
|
||||
// should already be in world coords so shouldn't need rotating.
|
||||
|
||||
@@ -30,12 +30,12 @@ void osgParticle::FluidProgram::execute(double dt)
|
||||
float radius = particle->getRadius();
|
||||
float Area = osg::PI*radius*radius;
|
||||
float Volume = Area*radius*four_over_three;
|
||||
|
||||
|
||||
// compute force due to gravity + boyancy of displacing the fluid that the particle is emersed in.
|
||||
osg::Vec3 accel_gravity = _acceleration * ((particle->getMass() - _density*Volume) * particle->getMassInv());
|
||||
|
||||
|
||||
// compute force due to friction
|
||||
osg::Vec3 relative_wind = particle->getVelocity()-_wind;
|
||||
osg::Vec3 relative_wind = particle->getVelocity()-_wind;
|
||||
osg::Vec3 wind_force = - relative_wind * Area * (_viscosityCoefficient + _densityCoefficient*relative_wind.length());
|
||||
osg::Vec3 wind_accel = wind_force * particle->getMassInv();
|
||||
|
||||
@@ -48,7 +48,7 @@ void osgParticle::FluidProgram::execute(double dt)
|
||||
}
|
||||
|
||||
particle->addVelocity(accel_gravity*dt + wind_accel*compenstated_dt);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ osgParticle::ModularEmitter::ModularEmitter()
|
||||
_shooter(new RadialShooter)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
osgParticle::ModularEmitter::ModularEmitter(const ModularEmitter& copy, const osg::CopyOp& copyop):
|
||||
Emitter(copy, copyop),
|
||||
_numParticleToCreateMovementCompensationRatio(copy._numParticleToCreateMovementCompensationRatio),
|
||||
_counter(static_cast<Counter *>(copyop(copy._counter.get()))),
|
||||
_placer(static_cast<Placer *>(copyop(copy._placer.get()))),
|
||||
_counter(static_cast<Counter *>(copyop(copy._counter.get()))),
|
||||
_placer(static_cast<Placer *>(copyop(copy._placer.get()))),
|
||||
_shooter(static_cast<Shooter *>(copyop(copy._shooter.get())))
|
||||
{
|
||||
}
|
||||
@@ -51,7 +51,7 @@ void osgParticle::ModularEmitter::emitParticles(double dt)
|
||||
osg::Vec3d currentPosition = controlPosition * ltw;
|
||||
float distance = (currentPosition-previousPosition).length();
|
||||
|
||||
float size = getUseDefaultTemplate() ?
|
||||
float size = getUseDefaultTemplate() ?
|
||||
getParticleSystem()->getDefaultParticleTemplate().getSizeRange().minimum :
|
||||
getParticleTemplate().getSizeRange().minimum;
|
||||
|
||||
@@ -61,7 +61,7 @@ void osgParticle::ModularEmitter::emitParticles(double dt)
|
||||
|
||||
n = osg::maximum(n, int(rounded_down) + (((float) rand() < remainder * (float)RAND_MAX) ? 1 : 0));
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i<n; ++i)
|
||||
{
|
||||
Particle* P = getParticleSystem()->createParticle(getUseDefaultTemplate()? 0: &getParticleTemplate());
|
||||
@@ -69,14 +69,14 @@ void osgParticle::ModularEmitter::emitParticles(double dt)
|
||||
{
|
||||
_placer->place(P);
|
||||
_shooter->shoot(P);
|
||||
|
||||
|
||||
// Now need to transform the position and velocity because we having a moving model.
|
||||
float r = ((float)rand()/(float)RAND_MAX);
|
||||
P->transformPositionVelocity(emitterToPs, prevEmitterToPs, r);
|
||||
//P->transformPositionVelocity(ltw);
|
||||
|
||||
|
||||
if (cps) P->setUpTexCoordsAsPartOfConnectedParticleSystem(cps);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ void osgParticle::ModularProgram::execute(double dt)
|
||||
Operator_vector::iterator ci_end = _operators.end();
|
||||
|
||||
ParticleSystem* ps = getParticleSystem();
|
||||
for (ci=_operators.begin(); ci!=ci_end; ++ci) {
|
||||
for (ci=_operators.begin(); ci!=ci_end; ++ci) {
|
||||
(*ci)->beginOperate(this);
|
||||
(*ci)->operateParticles(ps, dt);
|
||||
(*ci)->endOperate();
|
||||
|
||||
@@ -8,7 +8,7 @@ osgParticle::MultiSegmentPlacer::MultiSegmentPlacer()
|
||||
: Placer(), _total_length(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
osgParticle::MultiSegmentPlacer::MultiSegmentPlacer(const MultiSegmentPlacer& copy, const osg::CopyOp& copyop)
|
||||
: Placer(copy, copyop), _vx(copy._vx), _total_length(copy._total_length)
|
||||
{
|
||||
@@ -18,13 +18,13 @@ void osgParticle::MultiSegmentPlacer::recompute_length()
|
||||
{
|
||||
Vertex_vector::iterator i;
|
||||
Vertex_vector::iterator i0 = _vx.begin();
|
||||
|
||||
|
||||
_total_length = 0;
|
||||
for (i=_vx.begin(); i!=_vx.end(); ++i)
|
||||
{
|
||||
_total_length += (i->first - i0->first).length();
|
||||
i->second = _total_length;
|
||||
i0 = i;
|
||||
i0 = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ void osgParticle::MultiSegmentPlacer::place(Particle* P) const
|
||||
{
|
||||
if (_vx.size() >= 2) {
|
||||
float x = rangef(0, _total_length).get_random();
|
||||
|
||||
|
||||
Vertex_vector::const_iterator i;
|
||||
Vertex_vector::const_iterator i0 = _vx.begin();
|
||||
const Vertex_vector::const_iterator vend = _vx.end();
|
||||
@@ -46,7 +46,7 @@ void osgParticle::MultiSegmentPlacer::place(Particle* P) const
|
||||
return;
|
||||
}
|
||||
i0 = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -25,8 +25,8 @@ osgParticle::Particle::Particle()
|
||||
_sr(0.2f, 0.2f),
|
||||
_ar(1, 0),
|
||||
_cr(osg::Vec4(1, 1, 1, 1), osg::Vec4(1, 1, 1, 1)),
|
||||
_si(new LinearInterpolator),
|
||||
_ai(new LinearInterpolator),
|
||||
_si(new LinearInterpolator),
|
||||
_ai(new LinearInterpolator),
|
||||
_ci(new LinearInterpolator),
|
||||
_mustdie(false),
|
||||
_lifeTime(2),
|
||||
@@ -65,7 +65,7 @@ bool osgParticle::Particle::update(double dt, bool onlyTimeStamp)
|
||||
return false;
|
||||
}
|
||||
|
||||
double x = 0;
|
||||
double x = 0;
|
||||
|
||||
// if we don't live forever, compute our normalized age.
|
||||
if (_lifeTime > 0) {
|
||||
@@ -79,7 +79,7 @@ bool osgParticle::Particle::update(double dt, bool onlyTimeStamp)
|
||||
_alive = -1.0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// compute the current values for size, alpha and color.
|
||||
if (_lifeTime <= 0) {
|
||||
if (dt == _t0) {
|
||||
@@ -92,29 +92,29 @@ bool osgParticle::Particle::update(double dt, bool onlyTimeStamp)
|
||||
_current_alpha = _ai.get()->interpolate(x, _ar);
|
||||
_current_color = _ci.get()->interpolate(x, _cr);
|
||||
}
|
||||
|
||||
|
||||
// update position
|
||||
_prev_pos = _position;
|
||||
_position += _velocity * dt;
|
||||
|
||||
|
||||
// return now if we indicate that only time stamp should be updated
|
||||
// the shader will handle remain properties in this case
|
||||
if (onlyTimeStamp) return true;
|
||||
|
||||
//Compute the current texture tile based on our normalized age
|
||||
int currentTile = _start_tile + static_cast<int>(x * getNumTiles());
|
||||
|
||||
|
||||
//If the current texture tile is different from previous, then compute new texture coords
|
||||
if(currentTile != _cur_tile)
|
||||
{
|
||||
|
||||
|
||||
_cur_tile = currentTile;
|
||||
_s_coord = _s_tile * fmod(_cur_tile , 1.0 / _s_tile);
|
||||
_t_coord = 1.0 - _t_tile * (static_cast<int>(_cur_tile * _t_tile) + 1);
|
||||
|
||||
// OSG_NOTICE<<this<<" setting tex coords "<<_s_coord<<" "<<_t_coord<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
// update angle
|
||||
_prev_angle = _angle;
|
||||
_angle += _angul_arvel * dt;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@ ParticleEffect::ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& co
|
||||
void ParticleEffect::setUseLocalParticleSystem(bool local)
|
||||
{
|
||||
if (_useLocalParticleSystem==local) return;
|
||||
|
||||
|
||||
_useLocalParticleSystem = local;
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
@@ -85,7 +85,7 @@ void ParticleEffect::setIntensity(float intensity)
|
||||
void ParticleEffect::setStartTime(double startTime)
|
||||
{
|
||||
if (_startTime==startTime) return;
|
||||
|
||||
|
||||
_startTime =startTime;
|
||||
|
||||
if (_automaticSetup) setUpEmitterAndProgram();
|
||||
@@ -105,7 +105,7 @@ void ParticleEffect::setParticleDuration(double duration)
|
||||
if (_defaultParticleTemplate.getLifeTime()==duration) return;
|
||||
|
||||
_defaultParticleTemplate.setLifeTime(duration);
|
||||
|
||||
|
||||
if (_automaticSetup) setUpEmitterAndProgram();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ void ParticleEffect::setWind(const osg::Vec3& wind)
|
||||
void ParticleEffect::setParticleSystem(ParticleSystem* ps)
|
||||
{
|
||||
if (_particleSystem==ps) return;
|
||||
|
||||
|
||||
_particleSystem = ps;
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
@@ -145,15 +145,15 @@ void ParticleEffect::buildEffect()
|
||||
osg::ref_ptr<Program> program = getProgram();
|
||||
osg::ref_ptr<ParticleSystem> particleSystem = getParticleSystem();
|
||||
|
||||
if (!emitter || !particleSystem || !program) return;
|
||||
if (!emitter || !particleSystem || !program) return;
|
||||
|
||||
|
||||
// clear the children.
|
||||
removeChildren(0,getNumChildren());
|
||||
|
||||
|
||||
// add the emitter
|
||||
addChild(emitter.get());
|
||||
|
||||
|
||||
// add the program to update the particles
|
||||
addChild(program.get());
|
||||
|
||||
@@ -165,7 +165,7 @@ void ParticleEffect::buildEffect()
|
||||
if (_useLocalParticleSystem)
|
||||
{
|
||||
particleSystem->setParticleScaleReferenceFrame(ParticleSystem::LOCAL_COORDINATES);
|
||||
|
||||
|
||||
// add the geode to the scene graph
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addDrawable(particleSystem.get());
|
||||
|
||||
@@ -66,7 +66,7 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
ParticleSystem::ScopedWriteLock lock(*(_ps->getReadWriteMutex()));
|
||||
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//a check to make sure we havent updated yet this frame
|
||||
if(_frameNumber < nv.getFrameStamp()->getFrameNumber())
|
||||
{
|
||||
@@ -81,7 +81,7 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
|
||||
_currentTime = 0;
|
||||
_t0 = -1;
|
||||
}
|
||||
|
||||
|
||||
// skip if we haven't initialized _t0 yet
|
||||
if (_t0 != -1)
|
||||
{
|
||||
@@ -93,21 +93,21 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
|
||||
if (_endless || (_currentTime < (_startTime + _lifeTime)))
|
||||
alive = true;
|
||||
}
|
||||
|
||||
|
||||
// update current time
|
||||
_currentTime += t - _t0;
|
||||
|
||||
|
||||
// process only if the particle system is not frozen/culled
|
||||
if (alive &&
|
||||
_enabled &&
|
||||
!_ps->isFrozen() &&
|
||||
if (alive &&
|
||||
_enabled &&
|
||||
!_ps->isFrozen() &&
|
||||
((_ps->getLastFrameNumber()+1) >= (nv.getFrameStamp()->getFrameNumber()) || !_ps->getFreezeOnCull()))
|
||||
{
|
||||
// initialize matrix flags
|
||||
_need_ltw_matrix = true;
|
||||
_need_wtl_matrix = true;
|
||||
_current_nodevisitor = &nv;
|
||||
|
||||
|
||||
// do some process (unimplemented in this base class)
|
||||
process( t - _t0 );
|
||||
} else {
|
||||
@@ -120,8 +120,8 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
|
||||
_t0 = t;
|
||||
}
|
||||
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//updates the _frameNumber, keeping it current
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//updates the _frameNumber, keeping it current
|
||||
_frameNumber = nv.getFrameStamp()->getFrameNumber();
|
||||
}
|
||||
else
|
||||
@@ -129,7 +129,7 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
|
||||
OSG_WARN << "osgParticle::ParticleProcessor::traverse(NodeVisitor&) requires a valid FrameStamp to function, particles not updated.\n";
|
||||
}
|
||||
|
||||
} else
|
||||
} else
|
||||
{
|
||||
OSG_WARN << "ParticleProcessor \"" << getName() << "\": invalid particle system\n";
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ static double distance(const osg::Vec3& coord, const osg::Matrix& matrix)
|
||||
}
|
||||
|
||||
osgParticle::ParticleSystem::ParticleSystem()
|
||||
: osg::Drawable(),
|
||||
: osg::Drawable(),
|
||||
_def_bbox(osg::Vec3(-10, -10, -10), osg::Vec3(10, 10, 10)),
|
||||
_alignment(BILLBOARD),
|
||||
_align_X_axis(1, 0, 0),
|
||||
@@ -41,8 +41,8 @@ osgParticle::ParticleSystem::ParticleSystem()
|
||||
_dirty_uniforms(false),
|
||||
_doublepass(false),
|
||||
_frozen(false),
|
||||
_bmin(0, 0, 0),
|
||||
_bmax(0, 0, 0),
|
||||
_bmin(0, 0, 0),
|
||||
_bmax(0, 0, 0),
|
||||
_reset_bounds_flag(false),
|
||||
_bounds_computed(false),
|
||||
_def_ptemp(Particle()),
|
||||
@@ -62,7 +62,7 @@ osgParticle::ParticleSystem::ParticleSystem()
|
||||
}
|
||||
|
||||
osgParticle::ParticleSystem::ParticleSystem(const ParticleSystem& copy, const osg::CopyOp& copyop)
|
||||
: osg::Drawable(copy, copyop),
|
||||
: osg::Drawable(copy, copyop),
|
||||
_def_bbox(copy._def_bbox),
|
||||
_alignment(copy._alignment),
|
||||
_align_X_axis(copy._align_X_axis),
|
||||
@@ -73,8 +73,8 @@ osgParticle::ParticleSystem::ParticleSystem(const ParticleSystem& copy, const os
|
||||
_dirty_uniforms(copy._dirty_uniforms),
|
||||
_doublepass(copy._doublepass),
|
||||
_frozen(copy._frozen),
|
||||
_bmin(copy._bmin),
|
||||
_bmax(copy._bmax),
|
||||
_bmin(copy._bmin),
|
||||
_bmax(copy._bmax),
|
||||
_reset_bounds_flag(copy._reset_bounds_flag),
|
||||
_bounds_computed(copy._bounds_computed),
|
||||
_def_ptemp(copy._def_ptemp),
|
||||
@@ -107,7 +107,7 @@ void osgParticle::ParticleSystem::update(double dt, osg::NodeVisitor& nv)
|
||||
// At present, our lcoal shader implementation will ignore these particle props:
|
||||
// _cur_tile, _s_coord, _t_coord, _prev_pos, _prev_angle and _angle
|
||||
osg::StateSet* stateset = getOrCreateStateSet();
|
||||
|
||||
|
||||
if (_dirty_uniforms)
|
||||
{
|
||||
osg::Uniform* u_vd = stateset->getUniform("visibilityDistance");
|
||||
@@ -115,7 +115,7 @@ void osgParticle::ParticleSystem::update(double dt, osg::NodeVisitor& nv)
|
||||
_dirty_uniforms = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(unsigned int i=0; i<_particles.size(); ++i)
|
||||
{
|
||||
Particle& particle = _particles[i];
|
||||
@@ -131,7 +131,7 @@ void osgParticle::ParticleSystem::update(double dt, osg::NodeVisitor& nv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_sortMode != NO_SORT)
|
||||
{
|
||||
// sort particles
|
||||
@@ -151,7 +151,7 @@ void osgParticle::ParticleSystem::update(double dt, osg::NodeVisitor& nv)
|
||||
std::sort<Particle_vector::iterator>(_particles.begin(), _particles.end());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// force recomputing of bounding box on next frame
|
||||
dirtyBound();
|
||||
}
|
||||
@@ -165,19 +165,19 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo
|
||||
// update the frame count, so other objects can detect when
|
||||
// this particle system is culled
|
||||
_last_frame = state.getFrameStamp()->getFrameNumber();
|
||||
|
||||
|
||||
// update the dirty flag of delta time, so next time a new request for delta time
|
||||
// will automatically cause recomputing
|
||||
_dirty_dt = true;
|
||||
|
||||
|
||||
// get the current modelview matrix
|
||||
osg::Matrix modelview = state.getModelViewMatrix();
|
||||
|
||||
// set up depth mask for first rendering pass
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
||||
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
||||
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
||||
#endif
|
||||
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
// render, first pass
|
||||
@@ -192,7 +192,7 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo
|
||||
#endif
|
||||
|
||||
// render, second pass
|
||||
if (_doublepass) {
|
||||
if (_doublepass) {
|
||||
// set up color mask for second rendering pass
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
||||
glPushAttrib(GL_COLOR_BUFFER_BIT);
|
||||
@@ -236,7 +236,7 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string& textur
|
||||
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
|
||||
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR);
|
||||
stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON);
|
||||
|
||||
osg::TexEnv *texenv = new osg::TexEnv;
|
||||
@@ -245,7 +245,7 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string& textur
|
||||
}
|
||||
|
||||
osg::BlendFunc *blend = new osg::BlendFunc;
|
||||
if (emissive_particles) {
|
||||
if (emissive_particles) {
|
||||
blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE);
|
||||
} else {
|
||||
blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
|
||||
@@ -262,16 +262,16 @@ void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::st
|
||||
{
|
||||
osg::StateSet *stateset = new osg::StateSet;
|
||||
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
|
||||
|
||||
osg::PointSprite *sprite = new osg::PointSprite;
|
||||
stateset->setTextureAttributeAndModes(texture_unit, sprite, osg::StateAttribute::ON);
|
||||
|
||||
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
|
||||
stateset->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON);
|
||||
#else
|
||||
OSG_NOTICE<<"Warning: ParticleSystem::setDefaultAttributesUsingShaders(..) not fully implemented."<<std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
if (!texturefile.empty())
|
||||
{
|
||||
osg::Texture2D *texture = new osg::Texture2D;
|
||||
@@ -279,13 +279,13 @@ void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::st
|
||||
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
|
||||
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR);
|
||||
stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
|
||||
osg::BlendFunc *blend = new osg::BlendFunc;
|
||||
if (emissive_particles)
|
||||
{
|
||||
{
|
||||
blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE);
|
||||
}
|
||||
else
|
||||
@@ -293,7 +293,7 @@ void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::st
|
||||
blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
stateset->setAttributeAndModes(blend, osg::StateAttribute::ON);
|
||||
|
||||
|
||||
osg::Program *program = new osg::Program;
|
||||
#ifdef USE_LOCAL_SHADERS
|
||||
char vertexShaderSource[] =
|
||||
@@ -337,11 +337,11 @@ void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::st
|
||||
program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, osgDB::findDataFile("shaders/particle.frag")));
|
||||
#endif
|
||||
stateset->setAttributeAndModes(program, osg::StateAttribute::ON);
|
||||
|
||||
|
||||
stateset->addUniform(new osg::Uniform("visibilityDistance", (float)_visibilityDistance));
|
||||
stateset->addUniform(new osg::Uniform("baseTexture", texture_unit));
|
||||
setStateSet(stateset);
|
||||
|
||||
|
||||
setUseVertexArray(true);
|
||||
setUseShaders(true);
|
||||
}
|
||||
@@ -383,10 +383,10 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
|
||||
xScale = 1.0f/lengthX2;
|
||||
yScale = 1.0f/lengthY2;
|
||||
}
|
||||
|
||||
|
||||
scaled_aligned_xAxis *= xScale;
|
||||
scaled_aligned_yAxis *= yScale;
|
||||
|
||||
|
||||
xAxis *= xScale;
|
||||
yAxis *= yScale;
|
||||
}
|
||||
@@ -403,15 +403,15 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
|
||||
// Enable writing depth mask when drawing user-defined particles
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
for(unsigned int i=0; i<_particles.size(); i+=_detail)
|
||||
{
|
||||
const Particle* currentParticle = &_particles[i];
|
||||
|
||||
|
||||
bool insideDistance = true;
|
||||
if (_sortMode != NO_SORT && _visibilityDistance>0.0)
|
||||
insideDistance = (currentParticle->getDepth()>=0.0 && currentParticle->getDepth()<=_visibilityDistance);
|
||||
|
||||
|
||||
if (currentParticle->isAlive() && insideDistance)
|
||||
{
|
||||
if (currentParticle->getShape() != startParticle->getShape())
|
||||
@@ -428,7 +428,7 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
++_draw_count;
|
||||
|
||||
|
||||
if (currentParticle->getShape() == Particle::USER)
|
||||
{
|
||||
if (requiresEndRender)
|
||||
@@ -439,22 +439,22 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
|
||||
currentParticle->render(renderInfo, currentParticle->getPosition(), currentParticle->getAngle());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const osg::Vec3& angle = currentParticle->getAngle();
|
||||
bool requiresRotation = (angle.x()!=0.0f || angle.y()!=0.0f || angle.z()!=0.0f);
|
||||
if (requiresRotation)
|
||||
{
|
||||
osg::Matrix R;
|
||||
R.makeRotate(
|
||||
angle.x(), osg::Vec3(1, 0, 0),
|
||||
angle.y(), osg::Vec3(0, 1, 0),
|
||||
angle.x(), osg::Vec3(1, 0, 0),
|
||||
angle.y(), osg::Vec3(0, 1, 0),
|
||||
angle.z(), osg::Vec3(0, 0, 1));
|
||||
|
||||
if (_alignment==BILLBOARD)
|
||||
{
|
||||
xAxis = osg::Matrix::transform3x3(R,scaled_aligned_xAxis);
|
||||
xAxis = osg::Matrix::transform3x3(modelview,xAxis);
|
||||
|
||||
|
||||
yAxis = osg::Matrix::transform3x3(R,scaled_aligned_yAxis);
|
||||
yAxis = osg::Matrix::transform3x3(modelview,yAxis);
|
||||
|
||||
@@ -472,7 +472,7 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
|
||||
{
|
||||
currentParticle->render(gl,currentParticle->getPosition(), xAxis, yAxis, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (requiresEndRender)
|
||||
@@ -482,7 +482,7 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
|
||||
void osgParticle::ParticleSystem::render_vertex_array(osg::RenderInfo& renderInfo) const
|
||||
{
|
||||
if (_particles.size() <= 0) return;
|
||||
|
||||
|
||||
// Compute the pointer and offsets
|
||||
Particle_vector::const_iterator itr = _particles.begin();
|
||||
float* ptr = (float*)(&(*itr));
|
||||
@@ -496,7 +496,7 @@ void osgParticle::ParticleSystem::render_vertex_array(osg::RenderInfo& renderInf
|
||||
GLsizei colorOffset = (float*)(&(itr->_current_color)) - ptr; // Color
|
||||
GLsizei velOffset = (float*)(&(itr->_velocity)) - ptr; // Velocity
|
||||
GLsizei propOffset = (float*)(&(itr->_alive)) - ptr; // Alive, size & alpha
|
||||
|
||||
|
||||
// Draw particles as arrays
|
||||
osg::State& state = *renderInfo.getState();
|
||||
state.lazyDisablingOfVertexAttributes();
|
||||
@@ -512,7 +512,7 @@ void osgParticle::ParticleSystem::render_vertex_array(osg::RenderInfo& renderInf
|
||||
}
|
||||
|
||||
osg::BoundingBox osgParticle::ParticleSystem::computeBound() const
|
||||
{
|
||||
{
|
||||
if (!_bounds_computed)
|
||||
{
|
||||
return _def_bbox;
|
||||
|
||||
@@ -23,14 +23,14 @@ osgParticle::ParticleSystemUpdater::ParticleSystemUpdater(const ParticleSystemUp
|
||||
void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(&nv);
|
||||
if (cv)
|
||||
if (cv)
|
||||
{
|
||||
if (nv.getFrameStamp())
|
||||
{
|
||||
if( _frameNumber < nv.getFrameStamp()->getFrameNumber())
|
||||
{
|
||||
_frameNumber = nv.getFrameStamp()->getFrameNumber();
|
||||
|
||||
|
||||
double t = nv.getFrameStamp()->getSimulationTime();
|
||||
if (_t0 != -1.0)
|
||||
{
|
||||
@@ -38,9 +38,9 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
|
||||
for (i=_psv.begin(); i!=_psv.end(); ++i)
|
||||
{
|
||||
ParticleSystem* ps = i->get();
|
||||
|
||||
|
||||
ParticleSystem::ScopedWriteLock lock(*(ps->getReadWriteMutex()));
|
||||
|
||||
|
||||
if (!ps->isFrozen() && (ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps->getFreezeOnCull()))
|
||||
{
|
||||
ps->update(t - _t0, nv);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ PrecipitationEffect::PrecipitationEffect():
|
||||
_previousFrameTime(FLT_MAX)
|
||||
{
|
||||
setNumChildrenRequiringUpdateTraversal(1);
|
||||
|
||||
|
||||
setUpGeometries(1024);
|
||||
|
||||
rain(0.5);
|
||||
@@ -81,7 +81,7 @@ void PrecipitationEffect::rain(float intensity)
|
||||
_cellSize.set(5.0f / (0.25f+intensity), 5.0f / (0.25f+intensity), 5.0f);
|
||||
_nearTransition = 25.f;
|
||||
_farTransition = 100.0f - 60.0f*sqrtf(intensity);
|
||||
|
||||
|
||||
if (!_fog) _fog = new osg::Fog;
|
||||
|
||||
_fog->setMode(osg::Fog::EXP);
|
||||
@@ -89,7 +89,7 @@ void PrecipitationEffect::rain(float intensity)
|
||||
_fog->setColor(osg::Vec4(0.5, 0.5, 0.5, 1.0));
|
||||
|
||||
_useFarLineSegments = false;
|
||||
|
||||
|
||||
_dirty = true;
|
||||
|
||||
update();
|
||||
@@ -105,7 +105,7 @@ void PrecipitationEffect::snow(float intensity)
|
||||
_cellSize.set(5.0f / (0.25f+intensity), 5.0f / (0.25f+intensity), 5.0f);
|
||||
_nearTransition = 25.f;
|
||||
_farTransition = 100.0f - 60.0f*sqrtf(intensity);
|
||||
|
||||
|
||||
if (!_fog) _fog = new osg::Fog;
|
||||
|
||||
_fog->setMode(osg::Fog::EXP);
|
||||
@@ -113,7 +113,7 @@ void PrecipitationEffect::snow(float intensity)
|
||||
_fog->setColor(osg::Vec4(0.6, 0.6, 0.6, 1.0));
|
||||
|
||||
_useFarLineSegments = false;
|
||||
|
||||
|
||||
_dirty = true;
|
||||
|
||||
update();
|
||||
@@ -121,19 +121,19 @@ void PrecipitationEffect::snow(float intensity)
|
||||
|
||||
void PrecipitationEffect::compileGLObjects(osg::RenderInfo& renderInfo) const
|
||||
{
|
||||
if (_quadGeometry.valid())
|
||||
if (_quadGeometry.valid())
|
||||
{
|
||||
_quadGeometry->compileGLObjects(renderInfo);
|
||||
if (_quadGeometry->getStateSet()) _quadGeometry->getStateSet()->compileGLObjects(*renderInfo.getState());
|
||||
}
|
||||
|
||||
if (_lineGeometry.valid())
|
||||
if (_lineGeometry.valid())
|
||||
{
|
||||
_lineGeometry->compileGLObjects(renderInfo);
|
||||
if (_lineGeometry->getStateSet()) _lineGeometry->getStateSet()->compileGLObjects(*renderInfo.getState());
|
||||
}
|
||||
|
||||
if (_pointGeometry.valid())
|
||||
if (_pointGeometry.valid())
|
||||
{
|
||||
_pointGeometry->compileGLObjects(renderInfo);
|
||||
if (_pointGeometry->getStateSet()) _pointGeometry->getStateSet()->compileGLObjects(*renderInfo.getState());
|
||||
@@ -146,7 +146,7 @@ void PrecipitationEffect::traverse(osg::NodeVisitor& nv)
|
||||
if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
if (_dirty) update();
|
||||
|
||||
|
||||
if (nv.getFrameStamp())
|
||||
{
|
||||
double currentTime = nv.getFrameStamp()->getSimulationTime();
|
||||
@@ -159,7 +159,7 @@ void PrecipitationEffect::traverse(osg::NodeVisitor& nv)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (nv.getVisitorType() == osg::NodeVisitor::NODE_VISITOR)
|
||||
{
|
||||
if (_dirty) update();
|
||||
@@ -172,10 +172,10 @@ void PrecipitationEffect::traverse(osg::NodeVisitor& nv)
|
||||
compileGLObjects(globjVisitor->getRenderInfo());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (nv.getVisitorType() != osg::NodeVisitor::CULL_VISITOR)
|
||||
{
|
||||
@@ -189,14 +189,14 @@ void PrecipitationEffect::traverse(osg::NodeVisitor& nv)
|
||||
}
|
||||
|
||||
ViewIdentifier viewIndentifier(cv, nv.getNodePath());
|
||||
|
||||
|
||||
{
|
||||
PrecipitationDrawableSet* precipitationDrawableSet = 0;
|
||||
|
||||
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
precipitationDrawableSet = &(_viewDrawableMap[viewIndentifier]);
|
||||
|
||||
|
||||
if (!precipitationDrawableSet->_quadPrecipitationDrawable)
|
||||
{
|
||||
precipitationDrawableSet->_quadPrecipitationDrawable = new PrecipitationDrawable;
|
||||
@@ -218,30 +218,30 @@ void PrecipitationEffect::traverse(osg::NodeVisitor& nv)
|
||||
precipitationDrawableSet->_pointPrecipitationDrawable->setDrawType(GL_POINTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cull(*precipitationDrawableSet, cv);
|
||||
|
||||
|
||||
cv->pushStateSet(_stateset.get());
|
||||
float depth = 0.0f;
|
||||
|
||||
if (!precipitationDrawableSet->_quadPrecipitationDrawable->getCurrentCellMatrixMap().empty())
|
||||
{
|
||||
cv->pushStateSet(precipitationDrawableSet->_quadPrecipitationDrawable->getStateSet());
|
||||
cv->addDrawableAndDepth(precipitationDrawableSet->_quadPrecipitationDrawable.get(),cv->getModelViewMatrix(),depth);
|
||||
cv->addDrawableAndDepth(precipitationDrawableSet->_quadPrecipitationDrawable.get(),cv->getModelViewMatrix(),depth);
|
||||
cv->popStateSet();
|
||||
}
|
||||
|
||||
if (!precipitationDrawableSet->_linePrecipitationDrawable->getCurrentCellMatrixMap().empty())
|
||||
{
|
||||
cv->pushStateSet(precipitationDrawableSet->_linePrecipitationDrawable->getStateSet());
|
||||
cv->addDrawableAndDepth(precipitationDrawableSet->_linePrecipitationDrawable.get(),cv->getModelViewMatrix(),depth);
|
||||
cv->addDrawableAndDepth(precipitationDrawableSet->_linePrecipitationDrawable.get(),cv->getModelViewMatrix(),depth);
|
||||
cv->popStateSet();
|
||||
}
|
||||
|
||||
if (!precipitationDrawableSet->_pointPrecipitationDrawable->getCurrentCellMatrixMap().empty())
|
||||
{
|
||||
cv->pushStateSet(precipitationDrawableSet->_pointPrecipitationDrawable->getStateSet());
|
||||
cv->addDrawableAndDepth(precipitationDrawableSet->_pointPrecipitationDrawable.get(),cv->getModelViewMatrix(),depth);
|
||||
cv->addDrawableAndDepth(precipitationDrawableSet->_pointPrecipitationDrawable.get(),cv->getModelViewMatrix(),depth);
|
||||
cv->popStateSet();
|
||||
}
|
||||
|
||||
@@ -270,16 +270,16 @@ void PrecipitationEffect::update()
|
||||
_inverse_du.set(1.0f/length_u, 0.0f, 0.0f);
|
||||
_inverse_dv.set(0.0f, 1.0f/length_v, 0.0f);
|
||||
_inverse_dw.set(0.0f, 0.0f, 1.0f/length_w);
|
||||
|
||||
|
||||
OSG_INFO<<"Cell size X="<<length_u<<std::endl;
|
||||
OSG_INFO<<"Cell size Y="<<length_v<<std::endl;
|
||||
OSG_INFO<<"Cell size Z="<<length_w<<std::endl;
|
||||
|
||||
|
||||
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_viewDrawableMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// set up state/
|
||||
{
|
||||
@@ -308,7 +308,7 @@ void PrecipitationEffect::update()
|
||||
_stateset->addUniform(_particleColorUniform.get());
|
||||
}
|
||||
else _particleColorUniform->set(_particleColor);
|
||||
|
||||
|
||||
if (!_particleSizeUniform)
|
||||
{
|
||||
_particleSizeUniform = new osg::Uniform("particleSize", _particleSize);
|
||||
@@ -317,11 +317,11 @@ void PrecipitationEffect::update()
|
||||
else _particleSizeUniform->set(_particleSize);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void PrecipitationEffect::createGeometry(unsigned int numParticles,
|
||||
osg::Geometry* quad_geometry,
|
||||
void PrecipitationEffect::createGeometry(unsigned int numParticles,
|
||||
osg::Geometry* quad_geometry,
|
||||
osg::Geometry* line_geometry,
|
||||
osg::Geometry* point_geometry)
|
||||
{
|
||||
@@ -330,7 +330,7 @@ void PrecipitationEffect::createGeometry(unsigned int numParticles,
|
||||
osg::Vec2 offset10(1.0f,0.0f);
|
||||
osg::Vec2 offset01(0.0f,1.0f);
|
||||
osg::Vec2 offset11(1.0f,1.0f);
|
||||
|
||||
|
||||
osg::Vec2 offset0(0.5f,0.0f);
|
||||
osg::Vec2 offset1(0.5f,1.0f);
|
||||
|
||||
@@ -343,7 +343,7 @@ void PrecipitationEffect::createGeometry(unsigned int numParticles,
|
||||
if (quad_geometry)
|
||||
{
|
||||
quad_geometry->setName("quad");
|
||||
|
||||
|
||||
quad_vertices = new osg::Vec3Array(numParticles*4);
|
||||
quad_offsets = new osg::Vec2Array(numParticles*4);
|
||||
|
||||
@@ -383,7 +383,7 @@ void PrecipitationEffect::createGeometry(unsigned int numParticles,
|
||||
for(unsigned int i=0; i< numParticles; ++i)
|
||||
{
|
||||
osg::Vec3 pos( random(0.0f, 1.0f), random(0.0f, 1.0f), random(0.0f, 1.0f));
|
||||
|
||||
|
||||
// quad particles
|
||||
if (quad_vertices)
|
||||
{
|
||||
@@ -396,7 +396,7 @@ void PrecipitationEffect::createGeometry(unsigned int numParticles,
|
||||
(*quad_offsets)[i*4+2] = offset11;
|
||||
(*quad_offsets)[i*4+3] = offset10;
|
||||
}
|
||||
|
||||
|
||||
// line particles
|
||||
if (line_vertices)
|
||||
{
|
||||
@@ -405,7 +405,7 @@ void PrecipitationEffect::createGeometry(unsigned int numParticles,
|
||||
(*line_offsets)[i*2] = offset0;
|
||||
(*line_offsets)[i*2+1] = offset1;
|
||||
}
|
||||
|
||||
|
||||
// point particles
|
||||
if (point_vertices)
|
||||
{
|
||||
@@ -420,8 +420,8 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
unsigned int quadRenderBin = 13;
|
||||
unsigned int lineRenderBin = 12;
|
||||
unsigned int pointRenderBin = 11;
|
||||
|
||||
|
||||
|
||||
|
||||
OSG_INFO<<"PrecipitationEffect::setUpGeometries("<<numParticles<<")"<<std::endl;
|
||||
|
||||
bool needGeometryRebuild = false;
|
||||
@@ -439,15 +439,15 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
_lineGeometry->setUseVertexBufferObjects(true);
|
||||
needGeometryRebuild = true;
|
||||
}
|
||||
|
||||
|
||||
if (!_pointGeometry || _pointGeometry->getVertexArray()->getNumElements() != numParticles)
|
||||
{
|
||||
_pointGeometry = new osg::Geometry;
|
||||
_pointGeometry->setUseVertexBufferObjects(true);
|
||||
needGeometryRebuild = true;
|
||||
}
|
||||
|
||||
if (needGeometryRebuild)
|
||||
|
||||
if (needGeometryRebuild)
|
||||
{
|
||||
createGeometry(numParticles, _quadGeometry.get(), _lineGeometry.get(), _pointGeometry.get());
|
||||
}
|
||||
@@ -456,13 +456,13 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
if (!_quadStateSet)
|
||||
{
|
||||
_quadStateSet = new osg::StateSet;
|
||||
|
||||
|
||||
osg::Program* program = new osg::Program;
|
||||
_quadStateSet->setAttribute(program);
|
||||
_quadStateSet->setRenderBinDetails(quadRenderBin,"DepthSortedBin");
|
||||
|
||||
#ifdef USE_LOCAL_SHADERS
|
||||
char vertexShaderSource[] =
|
||||
char vertexShaderSource[] =
|
||||
"uniform float inversePeriod;\n"
|
||||
"uniform vec4 particleColour;\n"
|
||||
"uniform float particleSize;\n"
|
||||
@@ -508,7 +508,7 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
" gl_ClipVertex = v1;\n"
|
||||
"}\n";
|
||||
|
||||
char fragmentShaderSource[] =
|
||||
char fragmentShaderSource[] =
|
||||
"uniform sampler2D baseTexture;\n"
|
||||
"varying vec2 texCoord;\n"
|
||||
"varying vec4 colour;\n"
|
||||
@@ -537,7 +537,7 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
_lineStateSet->setRenderBinDetails(lineRenderBin,"DepthSortedBin");
|
||||
|
||||
#ifdef USE_LOCAL_SHADERS
|
||||
char vertexShaderSource[] =
|
||||
char vertexShaderSource[] =
|
||||
"uniform float inversePeriod;\n"
|
||||
"uniform vec4 particleColour;\n"
|
||||
"uniform float particleSize;\n"
|
||||
@@ -580,7 +580,7 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
" gl_ClipVertex = v1;\n"
|
||||
"}\n";
|
||||
|
||||
char fragmentShaderSource[] =
|
||||
char fragmentShaderSource[] =
|
||||
"uniform sampler2D baseTexture;\n"
|
||||
"varying vec2 texCoord;\n"
|
||||
"varying vec4 colour;\n"
|
||||
@@ -608,7 +608,7 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
_pointStateSet->setAttribute(program);
|
||||
|
||||
#ifdef USE_LOCAL_SHADERS
|
||||
char vertexShaderSource[] =
|
||||
char vertexShaderSource[] =
|
||||
"uniform float inversePeriod;\n"
|
||||
"uniform vec4 particleColour;\n"
|
||||
"uniform float particleSize;\n"
|
||||
@@ -638,7 +638,7 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
" gl_ClipVertex = gl_ModelViewMatrix * v_current;\n"
|
||||
"}\n";
|
||||
|
||||
char fragmentShaderSource[] =
|
||||
char fragmentShaderSource[] =
|
||||
"uniform sampler2D baseTexture;\n"
|
||||
"varying vec4 colour;\n"
|
||||
"\n"
|
||||
@@ -664,7 +664,7 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles)
|
||||
#else
|
||||
OSG_NOTICE<<"Warning: ParticleEffect::setUpGeometries(..) not fully implemented."<<std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
_pointStateSet->setRenderBinDetails(pointRenderBin,"DepthSortedBin");
|
||||
}
|
||||
|
||||
@@ -692,18 +692,18 @@ void PrecipitationEffect::cull(PrecipitationDrawableSet& pds, osgUtil::CullVisit
|
||||
|
||||
osg::Matrix inverse_modelview;
|
||||
inverse_modelview.invert(*(cv->getModelViewMatrix()));
|
||||
|
||||
|
||||
osg::Vec3 eyeLocal = osg::Vec3(0.0f,0.0f,0.0f) * inverse_modelview;
|
||||
//OSG_NOTICE<<" eyeLocal "<<eyeLocal<<std::endl;
|
||||
|
||||
|
||||
float eye_k = (eyeLocal-_origin)*_inverse_dw;
|
||||
osg::Vec3 eye_kPlane = eyeLocal-_dw*eye_k-_origin;
|
||||
|
||||
|
||||
// OSG_NOTICE<<" eye_kPlane "<<eye_kPlane<<std::endl;
|
||||
|
||||
|
||||
float eye_i = eye_kPlane*_inverse_du;
|
||||
float eye_j = eye_kPlane*_inverse_dv;
|
||||
|
||||
|
||||
osg::Polytope frustum;
|
||||
frustum.setToUnitFrustum(false,false);
|
||||
frustum.transformProvidingInverse(*(cv->getProjectionMatrix()));
|
||||
@@ -712,7 +712,7 @@ void PrecipitationEffect::cull(PrecipitationDrawableSet& pds, osgUtil::CullVisit
|
||||
float i_delta = _farTransition * _inverse_du.x();
|
||||
float j_delta = _farTransition * _inverse_dv.y();
|
||||
float k_delta = 1;//_nearTransition * _inverse_dw.z();
|
||||
|
||||
|
||||
int i_min = (int)floor(eye_i - i_delta);
|
||||
int j_min = (int)floor(eye_j - j_delta);
|
||||
int k_min = (int)floor(eye_k - k_delta);
|
||||
@@ -720,7 +720,7 @@ void PrecipitationEffect::cull(PrecipitationDrawableSet& pds, osgUtil::CullVisit
|
||||
int i_max = (int)ceil(eye_i + i_delta);
|
||||
int j_max = (int)ceil(eye_j + j_delta);
|
||||
int k_max = (int)ceil(eye_k + k_delta);
|
||||
|
||||
|
||||
//OSG_NOTICE<<"i_delta="<<i_delta<<" j_delta="<<j_delta<<" k_delta="<<k_delta<<std::endl;
|
||||
|
||||
unsigned int numTested=0;
|
||||
@@ -737,14 +737,14 @@ void PrecipitationEffect::cull(PrecipitationDrawableSet& pds, osgUtil::CullVisit
|
||||
{
|
||||
float startTime = (float)(i)*iCyle + (float)(j)*jCyle;
|
||||
startTime = (startTime-floor(startTime))*_period;
|
||||
|
||||
|
||||
if (build(eyeLocal, i,j,k, startTime, pds, frustum, cv)) ++numInFrustum;
|
||||
++numTested;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef DO_TIMING
|
||||
osg::Timer_t endTick = osg::Timer::instance()->tick();
|
||||
|
||||
@@ -760,7 +760,7 @@ bool PrecipitationEffect::build(const osg::Vec3 eyeLocal, int i, int j, int k, f
|
||||
|
||||
osg::BoundingBox bb(position.x(), position.y(), position.z()+scale.z(),
|
||||
position.x()+scale.x(), position.y()+scale.y(), position.z());
|
||||
|
||||
|
||||
if (!frustum.contains(bb)) return false;
|
||||
|
||||
osg::Vec3 center = position + scale*0.5f;
|
||||
@@ -799,7 +799,7 @@ bool PrecipitationEffect::build(const osg::Vec3 eyeLocal, int i, int j, int k, f
|
||||
*mymodelview = *(cv->getModelViewMatrix());
|
||||
mymodelview->preMultTranslate(position);
|
||||
mymodelview->preMultScale(scale);
|
||||
|
||||
|
||||
cv->updateCalculatedNearFar(*(cv->getModelViewMatrix()),bb);
|
||||
|
||||
return true;
|
||||
@@ -839,17 +839,17 @@ if (!_geometry) return;
|
||||
|
||||
|
||||
const osg::Geometry::Extensions* extensions = osg::Geometry::getExtensions(renderInfo.getContextID(),true);
|
||||
|
||||
|
||||
// save OpenGL matrices
|
||||
glPushMatrix();
|
||||
|
||||
|
||||
if (_requiresPreviousMatrix)
|
||||
{
|
||||
renderInfo.getState()->setActiveTextureUnit(0);
|
||||
glMatrixMode( GL_TEXTURE );
|
||||
glPushMatrix();
|
||||
}
|
||||
|
||||
|
||||
typedef std::vector<const CellMatrixMap::value_type*> DepthMatrixStartTimeVector;
|
||||
DepthMatrixStartTimeVector orderedEntries;
|
||||
orderedEntries.reserve(_currentCellMatrixMap.size());
|
||||
@@ -860,9 +860,9 @@ if (!_geometry) return;
|
||||
{
|
||||
orderedEntries.push_back(&(*citr));
|
||||
}
|
||||
|
||||
|
||||
std::sort(orderedEntries.begin(),orderedEntries.end(),LessFunctor());
|
||||
|
||||
|
||||
for(DepthMatrixStartTimeVector::reverse_iterator itr = orderedEntries.rbegin();
|
||||
itr != orderedEntries.rend();
|
||||
++itr)
|
||||
@@ -880,13 +880,13 @@ if (!_geometry) return;
|
||||
{
|
||||
// load previous frame modelview matrix for motion blurr effect
|
||||
glMatrixMode( GL_TEXTURE );
|
||||
glLoadMatrix(pitr->second.modelview.ptr());
|
||||
glLoadMatrix(pitr->second.modelview.ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
// use current modelview matrix as "previous" frame value, cancelling motion blurr effect
|
||||
glMatrixMode( GL_TEXTURE );
|
||||
glLoadMatrix((*itr)->second.modelview.ptr());
|
||||
glLoadMatrix((*itr)->second.modelview.ptr());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -895,7 +895,7 @@ if (!_geometry) return;
|
||||
}
|
||||
|
||||
_geometry->draw(renderInfo);
|
||||
|
||||
|
||||
unsigned int numVertices = osg::minimum(_geometry->getVertexArray()->getNumElements(), _numberOfVertices);
|
||||
glDrawArrays(_drawType, 0, numVertices);
|
||||
}
|
||||
@@ -906,7 +906,7 @@ if (!_geometry) return;
|
||||
glPopMatrix();
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
}
|
||||
|
||||
|
||||
glPopMatrix();
|
||||
#else
|
||||
OSG_NOTICE<<"Warning: ParticleEffect::drawImplementation(..) not fully implemented."<<std::endl;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
// Written by Wang Rui, (C) 2010
|
||||
@@ -38,7 +38,7 @@ void SinkOperator::handleLineSegment( const Domain& domain, Particle* P, double
|
||||
const osg::Vec3& value = getValue(P);
|
||||
osg::Vec3 offset = value - domain.v1, normal = domain.v2 - domain.v1;
|
||||
normal.normalize();
|
||||
|
||||
|
||||
float diff = fabs(normal*offset - offset.length()) / domain.r1;
|
||||
kill( P, (diff<SINK_EPSILON) );
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -26,28 +26,28 @@ SmokeEffect::SmokeEffect(bool automaticSetup):
|
||||
ParticleEffect(automaticSetup)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position.set(0.0f,0.0f,0.0f);
|
||||
_scale = 1.0f;
|
||||
_intensity = 1.0f;
|
||||
|
||||
_emitterDuration = 65.0;
|
||||
_defaultParticleTemplate.setLifeTime(5.0*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
SmokeEffect::SmokeEffect(const osg::Vec3& position, float scale, float intensity)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position = position;
|
||||
_scale = scale;
|
||||
_intensity = intensity;
|
||||
|
||||
_emitterDuration = 65.0;
|
||||
_defaultParticleTemplate.setLifeTime(5.0*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ SmokeEffect::SmokeEffect(const SmokeEffect& copy, const osg::CopyOp& copyop):
|
||||
void SmokeEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
_emitterDuration = 65.0;
|
||||
|
||||
// set up unit particle.
|
||||
@@ -69,7 +69,7 @@ void SmokeEffect::setDefaults()
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 2.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1, 1.0f, 1.0f, 1.0f),
|
||||
osg::Vec4(1, 1.0f, 1.0f, 1.0f),
|
||||
osg::Vec4(1, 1.0f, 1.f, 0.0f)));
|
||||
|
||||
|
||||
@@ -89,12 +89,12 @@ void SmokeEffect::setUpEmitterAndProgram()
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
|
||||
float radius = 0.5f*_scale;
|
||||
float radius = 0.5f*_scale;
|
||||
float density = 1.0f; // 1.0kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
@@ -152,10 +152,10 @@ void SmokeEffect::setUpEmitterAndProgram()
|
||||
|
||||
// set up program.
|
||||
if (!_program)
|
||||
{
|
||||
{
|
||||
_program = new osgParticle::FluidProgram;
|
||||
}
|
||||
|
||||
|
||||
if (_program.valid())
|
||||
{
|
||||
_program->setParticleSystem(_particleSystem.get());
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -24,31 +24,31 @@
|
||||
using namespace osgParticle;
|
||||
|
||||
SmokeTrailEffect::SmokeTrailEffect(bool automaticSetup):
|
||||
ParticleEffect(automaticSetup)
|
||||
ParticleEffect(automaticSetup)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position.set(0.0f,0.0f,0.0f);
|
||||
_scale = 1.0f;
|
||||
_intensity = 1.0f;
|
||||
|
||||
_emitterDuration = 65.0;
|
||||
_defaultParticleTemplate.setLifeTime(5.0*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
SmokeTrailEffect::SmokeTrailEffect(const osg::Vec3& position, float scale, float intensity)
|
||||
{
|
||||
setDefaults();
|
||||
|
||||
|
||||
_position = position;
|
||||
_scale = scale;
|
||||
_intensity = intensity;
|
||||
|
||||
_emitterDuration = 65.0;
|
||||
_defaultParticleTemplate.setLifeTime(5.0*_scale);
|
||||
|
||||
|
||||
if (_automaticSetup) buildEffect();
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ SmokeTrailEffect::SmokeTrailEffect(const SmokeTrailEffect& copy, const osg::Copy
|
||||
void SmokeTrailEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/continous_smoke.rgb";
|
||||
|
||||
_textureFileName = "Images/continous_smoke.rgb";
|
||||
_emitterDuration = 65.0;
|
||||
|
||||
// set up unit particle.
|
||||
@@ -70,7 +70,7 @@ void SmokeTrailEffect::setDefaults()
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 2.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.7f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1, 1.0f, 1.0f, 1.0f),
|
||||
osg::Vec4(1, 1.0f, 1.0f, 1.0f),
|
||||
osg::Vec4(1, 1.0f, 1.f, 0.0f)));
|
||||
|
||||
|
||||
@@ -90,12 +90,12 @@ void SmokeTrailEffect::setUpEmitterAndProgram()
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
|
||||
float radius = 0.5f*_scale;
|
||||
float radius = 0.5f*_scale;
|
||||
float density = 1.0f; // 1.0kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
@@ -153,10 +153,10 @@ void SmokeTrailEffect::setUpEmitterAndProgram()
|
||||
|
||||
// set up program.
|
||||
if (!_program)
|
||||
{
|
||||
{
|
||||
_program = new osgParticle::FluidProgram;
|
||||
}
|
||||
|
||||
|
||||
if (_program.valid())
|
||||
{
|
||||
_program->setParticleSystem(_particleSystem.get());
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user