Improved ParticleEffects

This commit is contained in:
Robert Osfield
2005-04-04 07:54:52 +00:00
parent e4580f2028
commit 22e446dbc9
25 changed files with 917 additions and 289 deletions

View File

@@ -0,0 +1,52 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_EXPLOSIONDEBRIEFFECT
#define OSGPARTICLE_EXPLOSIONDEBRIEFFECT
#include <osgParticle/ParticleEffect>
#include <osgParticle/ModularEmitter>
#include <osgParticle/FluidProgram>
namespace osgParticle
{
class OSGPARTICLE_EXPORT ExplosionDebriEffect : public ParticleEffect
{
public:
ExplosionDebriEffect(const osg::Vec3& position=osg::Vec3(0.0f,0.0f,0.0f), float scale=1.0f, float intensity=1.0f);
ExplosionDebriEffect(const ExplosionDebriEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Node(osgParticle,ExplosionDebriEffect);
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

View File

@@ -16,7 +16,7 @@
#include <osgParticle/ParticleEffect>
#include <osgParticle/ModularEmitter>
#include <osgParticle/ModularProgram>
#include <osgParticle/FluidProgram>
namespace osgParticle
{
@@ -34,7 +34,7 @@ namespace osgParticle
virtual void setDefaults();
virtual void setUpEmitterAndProgram();
virtual Emitter* getEmitter() { return _emitter.get(); }
virtual const Emitter* getEmitter() const { return _emitter.get(); }
@@ -44,7 +44,7 @@ namespace osgParticle
protected:
osg::ref_ptr<ModularEmitter> _emitter;
osg::ref_ptr<ModularProgram> _program;
osg::ref_ptr<FluidProgram> _program;
};
}

View File

@@ -16,7 +16,7 @@
#include <osgParticle/ParticleEffect>
#include <osgParticle/ModularEmitter>
#include <osgParticle/ModularProgram>
#include <osgParticle/FluidProgram>
namespace osgParticle
{
@@ -44,7 +44,7 @@ namespace osgParticle
protected:
osg::ref_ptr<ModularEmitter> _emitter;
osg::ref_ptr<ModularProgram> _program;
osg::ref_ptr<FluidProgram> _program;
};

View File

@@ -40,24 +40,30 @@ namespace osgParticle
FluidFrictionOperator(const FluidFrictionOperator &copy, const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgParticle, FluidFrictionOperator);
/// Get the density of the fluid.
inline float getFluidDensity() const;
/// Set the density of the fluid.
inline void setFluidDensity(float d);
/// Get the viscosity of the fluid.
inline float getFluidViscosity() const;
/// Get the density of the fluid.
inline float getFluidDensity() const;
/// Set the viscosity of the fluid.
inline void setFluidViscosity(float v);
/// Get the overriden radius value.
inline float getOverrideRadius() const;
/// Get the viscosity of the fluid.
inline float getFluidViscosity() const;
/// Set the wind vector.
inline void setWind(const osg::Vec3& wind) { _wind = wind; }
/// Get the wind vector.
inline const osg::Vec3& getWind() const { return _wind; }
/// Set the overriden radius value (pass 0 if you want to use particle's radius).
inline void setOverrideRadius(float r);
/// Get the overriden radius value.
inline float getOverrideRadius() const;
/// Set the fluid parameters as for air (20<32>C temperature).
inline void setFluidToAir();
@@ -76,11 +82,12 @@ namespace osgParticle
FluidFrictionOperator &operator=(const FluidFrictionOperator &) { return *this; }
private:
float A_;
float B_;
float density_;
float viscosity_;
float ovr_rad_;
float A_;
float B_;
float density_;
float viscosity_;
float ovr_rad_;
osg::Vec3 _wind;
Program *current_program_;
};

View File

@@ -46,15 +46,15 @@ namespace osgParticle
public:
/**
Shape of particles.
NOTE: the LINE shape should be used in conjunction with FIXED alignment mode (see ParticleSystem).
*/
enum Shape {
Shape of particles.
NOTE: the LINE shape should be used in conjunction with FIXED alignment mode (see ParticleSystem).
*/
enum Shape {
POINT, // uses GL_POINTS as primitive
QUAD, // uses GL_QUADS as primitive
QUAD_TRIANGLESTRIP, // uses GL_TRIANGLE_STRIP as primitive, but each particle needs a glBegin/glEnd pair
HEXAGON, // may save some filling time, but uses more triangles
LINE // uses GL_LINES to draw line segments that point to the direction of motion
LINE // uses GL_LINES to draw line segments that point to the direction of motion
};
Particle();
@@ -117,14 +117,14 @@ namespace osgParticle
/// Get the previous position (the position before last update).
inline const osg::Vec3 &getPreviousPosition() const;
/// Get the angle vector.
inline const osg::Vec3 &getAngle() const;
/// Get the rotational velocity vector.
inline const osg::Vec3 &getAngularVelocity() const;
/// Get the previous angle vector.
inline const osg::Vec3 &getPreviousAngle() const;
/// Get the angle vector.
inline const osg::Vec3 &getAngle() const;
/// Get the rotational velocity vector.
inline const osg::Vec3 &getAngularVelocity() const;
/// Get the previous angle vector.
inline const osg::Vec3 &getPreviousAngle() const;
/** Kill the particle on next update
NOTE: after calling this function, the <CODE>isAlive()</CODE> method will still
@@ -178,21 +178,21 @@ namespace osgParticle
/// Transform position and velocity vectors by a matrix.
inline void transformPositionVelocity(const osg::Matrix &xform);
/// Set the angle vector.
inline void setAngle(const osg::Vec3 &a);
/**
Set the angular velocity vector.
Components x, y and z are angles of rotation around the respective axis (in radians).
*/
inline void setAngularVelocity(const osg::Vec3 &v);
/// Add a vector to the angular velocity vector.
inline void addAngularVelocity(const osg::Vec3 &dv);
/// Transform angle and angularVelocity vectors by a matrix.
inline void transformAngleVelocity(const osg::Matrix &xform);
/// Set the angle vector.
inline void setAngle(const osg::Vec3 &a);
/**
Set the angular velocity vector.
Components x, y and z are angles of rotation around the respective axis (in radians).
*/
inline void setAngularVelocity(const osg::Vec3 &v);
/// Add a vector to the angular velocity vector.
inline void addAngularVelocity(const osg::Vec3 &dv);
/// Transform angle and angularVelocity vectors by a matrix.
inline void transformAngleVelocity(const osg::Matrix &xform);
/** Update the particle (don't call this method manually).
This method is called automatically by <CODE>ParticleSystem::update()</CODE>; it
updates the graphical properties of the particle for the current time,
@@ -240,7 +240,7 @@ namespace osgParticle
osg::Vec3 prev_angle_;
osg::Vec3 angle_;
osg::Vec3 angular_vel_;
osg::Vec3 angular_vel_;
double t0_;
@@ -338,20 +338,20 @@ namespace osgParticle
return prev_pos_;
}
inline const osg::Vec3 &Particle::getAngle() const
{
return angle_;
}
inline const osg::Vec3 &Particle::getAngularVelocity() const
{
return angular_vel_;
}
inline const osg::Vec3 &Particle::getPreviousAngle() const
{
return prev_angle_;
}
inline const osg::Vec3 &Particle::getAngle() const
{
return angle_;
}
inline const osg::Vec3 &Particle::getAngularVelocity() const
{
return angular_vel_;
}
inline const osg::Vec3 &Particle::getPreviousAngle() const
{
return prev_angle_;
}
inline void Particle::kill()
{
@@ -422,30 +422,30 @@ namespace osgParticle
inline void Particle::setAngle(const osg::Vec3 &a)
{
angle_ = a;
}
inline void Particle::setAngularVelocity(const osg::Vec3 &v)
{
angular_vel_ = v;
}
inline void Particle::addAngularVelocity(const osg::Vec3 &dv)
{
angular_vel_ += dv;
}
inline void Particle::transformAngleVelocity(const osg::Matrix &xform)
{
// this should be optimized!
osg::Vec3 a1 = angle_ + angular_vel_;
angle_ = xform.preMult(angle_);
a1 = xform.preMult(a1);
angular_vel_ = a1 - angle_;
}
angle_ = a;
}
inline void Particle::setAngularVelocity(const osg::Vec3 &v)
{
angular_vel_ = v;
}
inline void Particle::addAngularVelocity(const osg::Vec3 &dv)
{
angular_vel_ += dv;
}
inline void Particle::transformAngleVelocity(const osg::Matrix &xform)
{
// this should be optimized!
osg::Vec3 a1 = angle_ + angular_vel_;
angle_ = xform.preMult(angle_);
a1 = xform.preMult(a1);
angular_vel_ = a1 - angle_;
}
inline float Particle::getMass() const
{
@@ -473,9 +473,9 @@ namespace osgParticle
case QUAD:
glBegin(GL_QUADS);
break;
case LINE:
glBegin(GL_LINES);
break;
case LINE:
glBegin(GL_LINES);
break;
default: ;
}
}
@@ -486,7 +486,7 @@ namespace osgParticle
{
case POINT:
case QUAD:
case LINE:
case LINE:
glEnd();
break;
default: ;
@@ -499,18 +499,18 @@ namespace osgParticle
}
inline void Particle::setTextureTile(int sTile, int tTile, int numTiles)
{
s_tile_ = 1.0f / static_cast<float>(sTile);
t_tile_ = 1.0f / static_cast<float>(tTile);
if (numTiles <= 0)
{
num_tile_ = sTile * tTile;
}
else
{
num_tile_ = numTiles;
}
}
{
s_tile_ = 1.0f / static_cast<float>(sTile);
t_tile_ = 1.0f / static_cast<float>(tTile);
if (numTiles <= 0)
{
num_tile_ = sTile * tTile;
}
else
{
num_tile_ = numTiles;
}
}
}

View File

@@ -25,11 +25,13 @@ namespace osgParticle
public:
ParticleEffect():
_useLocalParticleSystem(true),
_scale(1.0f),
_intensity(1.0f),
_startTime(0.0),
_duration(1.0),
_direction(0.0f,0.0f,1.0f)
_emitterDuration(1.0),
_particleDuration(1.0),
_wind(0.0f,0.0f,0.0f)
{}
ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
@@ -40,6 +42,9 @@ namespace osgParticle
virtual bool isSameKindAs(const osg::Object *obj) const { return dynamic_cast<const ParticleEffect*>(obj) != 0; }
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
void setUseLocalParticleSystem(bool local);
bool getUseLocalParticleSystem() const { return _useLocalParticleSystem; }
void setPosition(const osg::Vec3& position);
const osg::Vec3& getPosition() const { return _position; }
@@ -52,9 +57,17 @@ namespace osgParticle
void setStartTime(double startTime);
double getStartTime() const { return _startTime; }
void setDuration(double duration);
double getDuration() const { return _duration; }
void setEmitterDuration(double duration);
double getEmitterDuration() const { return _emitterDuration; }
void setParticleDuration(double duration);
double getParticleDuration() const { return _particleDuration; }
void setWind(const osg::Vec3& wind);
const osg::Vec3& getWind() const { return _wind; }
/// Get whether all particles are dead
bool areAllParticlesDead() const { return _particleSystem.valid()?_particleSystem->areAllParticlesDead():true; }
virtual Emitter* getEmitter() = 0;
virtual const Emitter* getEmitter() const = 0;
@@ -62,8 +75,9 @@ namespace osgParticle
virtual Program* getProgram() = 0;
virtual const Program* getProgram() const = 0;
virtual ParticleSystem* getParticleSystem() { return _particleSystem.get(); }
virtual const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); }
void setParticleSystem(ParticleSystem* ps);
inline ParticleSystem* getParticleSystem() { return _particleSystem.get(); }
inline const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); }
virtual void setDefaults();
@@ -74,13 +88,15 @@ namespace osgParticle
protected:
osg::ref_ptr<ParticleSystem> _particleSystem;
bool _useLocalParticleSystem;
osg::Vec3 _position;
float _scale;
float _intensity;
double _startTime;
double _duration;
osg::Vec3 _direction;
double _emitterDuration;
double _particleDuration;
osg::Vec3 _wind;
};
}

View File

@@ -107,6 +107,9 @@ namespace osgParticle
/// Get the number of dead particles.
inline int numDeadParticles() const;
/// Get whether all particles are dead
inline bool areAllParticlesDead() const { return numDeadParticles()==numParticles(); }
/// Get a pointer to the i-th particle.
inline Particle *getParticle(int i);

View File

@@ -16,7 +16,7 @@
#include <osgParticle/ParticleEffect>
#include <osgParticle/ModularEmitter>
#include <osgParticle/ModularProgram>
#include <osgParticle/FluidProgram>
namespace osgParticle
{
@@ -34,7 +34,7 @@ namespace osgParticle
virtual void setDefaults();
virtual void setUpEmitterAndProgram();
virtual Emitter* getEmitter() { return _emitter.get(); }
virtual const Emitter* getEmitter() const { return _emitter.get(); }
@@ -44,7 +44,7 @@ namespace osgParticle
protected:
osg::ref_ptr<ModularEmitter> _emitter;
osg::ref_ptr<ModularProgram> _program;
osg::ref_ptr<FluidProgram> _program;
};
}

View File

@@ -63,8 +63,11 @@ class OSGUTIL_EXPORT Hit
float getRatio() const { return _ratio; }
const osg::LineSegment* getOriginalLineSegment() const { return _originalLineSegment.get(); }
const osg::LineSegment* getLocalLineSegment() const { return _localLineSegment.get(); }
osg::NodePath& getNodePath() { return _nodePath; }
const osg::NodePath& getNodePath() const { return _nodePath; }
osg::Geode* getGeode() { return _geode.get(); }
const osg::Geode* getGeode() const { return _geode.get(); }
osg::Drawable* getDrawable() { return _drawable.get(); }
const osg::Drawable* getDrawable() const { return _drawable.get(); }
const osg::RefMatrix* getMatrix() const { return _matrix.get(); }
const osg::RefMatrix* getInverseMatrix() const { return _inverse.get(); }