Added SmokeTrailEffect which renders created particles as single quad or line
strip, in the case of the quad strip the strip is aligned to the be orthogonal with the eye point.
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <osg/Polytope>
|
||||
#include <osg/ShadowVolumeOccluder>
|
||||
#include <osg/Referenced>
|
||||
#include <osg/Viewport>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -328,7 +328,10 @@ class OSG_EXPORT CullingSet : public Referenced
|
||||
|
||||
void popOccludersCurrentMask(NodePath& nodePath);
|
||||
|
||||
static osg::Vec4 computePixelSizeVector(const Viewport& W, const Matrix& P, const Matrix& M);
|
||||
|
||||
virtual ~CullingSet();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -35,12 +35,10 @@ namespace osgParticle
|
||||
/// Create a new particle from the specified template (or the default one if <CODE>ptemplate</CODE> is null).
|
||||
virtual Particle* createParticle(const Particle* ptemplate);
|
||||
|
||||
/// Destroy the i-th particle.
|
||||
virtual void destroyParticle(int i);
|
||||
/// Reuse the i-th particle.
|
||||
virtual void reuseParticle(int i);
|
||||
|
||||
/// Update the particles. Don't call this directly, use a <CODE>ConnectedParticleSystemUpdater</CODE> instead.
|
||||
virtual void update(double dt);
|
||||
|
||||
/// Draw the connected particles as either a line or a quad strip, depending upon viewing distance. .
|
||||
virtual void drawImplementation(osg::State& state) const;
|
||||
|
||||
protected:
|
||||
@@ -49,8 +47,8 @@ namespace osgParticle
|
||||
|
||||
ConnectedParticleSystem& operator=(const ConnectedParticleSystem&) { return *this; }
|
||||
|
||||
Particle* _startParticle;
|
||||
Particle* _lastParticleCreated;
|
||||
int _startParticle;
|
||||
int _lastParticleCreated;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
75
include/osgParticle/ConstantRateCounter
Normal file
75
include/osgParticle/ConstantRateCounter
Normal file
@@ -0,0 +1,75 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 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
|
||||
* (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
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGPARTICLE_CONSTANTRATECOUNTER
|
||||
#define OSGPARTICLE_CONSTANTRATECOUNTER 1
|
||||
|
||||
#include <osgParticle/Counter>
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/Math>
|
||||
|
||||
namespace osgParticle
|
||||
{
|
||||
|
||||
class ConstantRateCounter: public Counter {
|
||||
public:
|
||||
ConstantRateCounter():
|
||||
Counter(),
|
||||
_minimumNumberOfParticlesToCreate(0),
|
||||
_numberOfParticlesPerSecondToCreate(0)
|
||||
{
|
||||
}
|
||||
|
||||
ConstantRateCounter(const ConstantRateCounter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
|
||||
Counter(copy, copyop),
|
||||
_minimumNumberOfParticlesToCreate(copy._minimumNumberOfParticlesToCreate),
|
||||
_numberOfParticlesPerSecondToCreate(copy._numberOfParticlesPerSecondToCreate)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
META_Object(osgParticle, ConstantRateCounter);
|
||||
|
||||
void setMinimumNumberOfParticlesToCreate(int minNumToCreate) { _minimumNumberOfParticlesToCreate = minNumToCreate; }
|
||||
int getMinimumNumberOfParticlesToCreate() const { return _minimumNumberOfParticlesToCreate; }
|
||||
|
||||
void setNumberOfParticlesPerSecondToCreate(double numPerSecond) { _numberOfParticlesPerSecondToCreate = numPerSecond; }
|
||||
double getNumberOfParticlesPerSecondToCreate() const { return _numberOfParticlesPerSecondToCreate; }
|
||||
|
||||
/// Return the number of particles to be created in this frame
|
||||
virtual int numParticlesToCreate(double dt) const
|
||||
{
|
||||
double v = (dt*_numberOfParticlesPerSecondToCreate);
|
||||
int i = (int)(v);
|
||||
_carryOver += (v-(double)i);
|
||||
if (_carryOver>1.0)
|
||||
{
|
||||
++i;
|
||||
_carryOver -= 1.0;
|
||||
}
|
||||
return osg::maximum(_minimumNumberOfParticlesToCreate, i);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~ConstantRateCounter() {}
|
||||
|
||||
int _minimumNumberOfParticlesToCreate;
|
||||
double _numberOfParticlesPerSecondToCreate;
|
||||
mutable double _carryOver;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -28,6 +28,9 @@
|
||||
namespace osgParticle
|
||||
{
|
||||
|
||||
// forward declare so we can reference it
|
||||
class ParticleSystem;
|
||||
|
||||
/** Implementation of a <B>particle</B>.
|
||||
Objects of this class are particles, they have some graphical properties
|
||||
and some physical properties. Particles are created by emitters and then placed
|
||||
@@ -44,6 +47,11 @@ namespace osgParticle
|
||||
*/
|
||||
class OSGPARTICLE_EXPORT Particle {
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
INVALID_INDEX = -1
|
||||
};
|
||||
|
||||
/**
|
||||
Shape of particles.
|
||||
@@ -125,6 +133,18 @@ namespace osgParticle
|
||||
|
||||
/// Get the previous angle vector.
|
||||
inline const osg::Vec3& getPreviousAngle() const;
|
||||
|
||||
/// Get the current color
|
||||
inline const osg::Vec4& getCurrentColor() const { return _current_color; }
|
||||
|
||||
/// Get the current alpha
|
||||
inline float getCurrentAlpha() const { return _current_alpha; }
|
||||
|
||||
/// Get the s texture coordinate of the bottom left of the particle
|
||||
inline const float getSTexCoord() const { return _s_coord; }
|
||||
|
||||
/// Get the t texture coordinate of the bottom left of the particle
|
||||
inline float getTCoord() const { return _t_coord; }
|
||||
|
||||
/** Kill the particle on next update
|
||||
NOTE: after calling this function, the <CODE>isAlive()</CODE> method will still
|
||||
@@ -216,10 +236,26 @@ namespace osgParticle
|
||||
/// Get the current (interpolated) polygon size. Valid only after the first call to update().
|
||||
inline float getCurrentSize() const;
|
||||
|
||||
// Specify how the particle texture is tiled
|
||||
/// Specify how the particle texture is tiled
|
||||
inline void setTextureTile(int sTile, int tTile, int numTiles = 0);
|
||||
|
||||
private:
|
||||
/// Set the previous particle
|
||||
inline void setPreviousParticle(int previous) { _previousParticle = previous; }
|
||||
|
||||
/// Get the previous particle
|
||||
inline int getPreviousParticle() const { return _previousParticle; }
|
||||
|
||||
/// Set the next particle
|
||||
inline void setNextParticle(int next) { _nextParticle = next; }
|
||||
|
||||
/// Get the const next particle
|
||||
inline int getNextParticle() const { return _nextParticle; }
|
||||
|
||||
/// Method for initializing a particles texture coords as part of a connected particle system.
|
||||
void setUpTexCoordsAsPartOfConnectedParticleSystem(ParticleSystem* ps);
|
||||
|
||||
protected:
|
||||
|
||||
Shape _shape;
|
||||
|
||||
rangef _sr;
|
||||
@@ -259,8 +295,8 @@ namespace osgParticle
|
||||
float _t_coord;
|
||||
|
||||
// previous and next Particles are only used in ConnectedParticleSystems
|
||||
Particle* _previousParticle;
|
||||
Particle* _nextParticle;
|
||||
int _previousParticle;
|
||||
int _nextParticle;
|
||||
};
|
||||
|
||||
// INLINE FUNCTIONS
|
||||
|
||||
@@ -123,6 +123,9 @@ namespace osgParticle
|
||||
/// Destroy the i-th particle.
|
||||
inline virtual void destroyParticle(int i);
|
||||
|
||||
/// Reuse the i-th particle.
|
||||
inline virtual void reuseParticle(int i) { _deadparts.push(&(_particles[i])); }
|
||||
|
||||
/// Get the last frame number.
|
||||
inline int getLastFrameNumber() const;
|
||||
|
||||
@@ -170,7 +173,6 @@ namespace osgParticle
|
||||
inline void update_bounds(const osg::Vec3& p, float r);
|
||||
void single_pass_render(osg::State& state, const osg::Matrix& modelview) const;
|
||||
|
||||
private:
|
||||
typedef std::vector<Particle> Particle_vector;
|
||||
typedef std::stack<Particle*> Death_stack;
|
||||
|
||||
|
||||
52
include/osgParticle/SmokeTrailEffect
Normal file
52
include/osgParticle/SmokeTrailEffect
Normal file
@@ -0,0 +1,52 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 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
|
||||
* (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
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGPARTICLE_SMOKETRAILEFFECT
|
||||
#define OSGPARTICLE_SMOKETRAILEFFECT
|
||||
|
||||
#include <osgParticle/ParticleEffect>
|
||||
#include <osgParticle/ModularEmitter>
|
||||
#include <osgParticle/FluidProgram>
|
||||
|
||||
namespace osgParticle
|
||||
{
|
||||
|
||||
class OSGPARTICLE_EXPORT SmokeTrailEffect : public ParticleEffect
|
||||
{
|
||||
public:
|
||||
|
||||
SmokeTrailEffect(const osg::Vec3& position=osg::Vec3(0.0f,0.0f,0.0f), float scale=1.0f, float intensity=1.0f);
|
||||
|
||||
SmokeTrailEffect(const SmokeTrailEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Node(osgParticle,SmokeTrailEffect);
|
||||
|
||||
virtual void setDefaults();
|
||||
|
||||
virtual void setUpEmitterAndProgram();
|
||||
|
||||
virtual Emitter* getEmitter() { return _emitter.get(); }
|
||||
virtual const Emitter* getEmitter() const { return _emitter.get(); }
|
||||
|
||||
virtual Program* getProgram() { return _program.get(); }
|
||||
virtual const Program* getProgram() const { return _program.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<ModularEmitter> _emitter;
|
||||
osg::ref_ptr<FluidProgram> _program;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user