Merged changed to osgParticle from Marco Jez, the changes are (quoted from
email from Marco) "Most relevant news: 1) particle systems now have the "freezeOnCull" property set to false by default. Since it is an optimization, and using it may cause some unwanted behaviors if not handled properly, it makes more sense to turn it off by default. 2) new "LINE" shape mode which uses GL_LINES to draw line segments that point to the direction of motion. 3) particles can now have a rotation angle and angular velocity. 4) new AngularAccelOperator applies angular acceleration to particles. 5) particle processors such as emitters and programs can have a "start", "end" and "reset" time coordinate. For example, an emitter may be instructed to start emitting particles only after a certain time, stop after another amount of time and then start again. Update (2) is from Gideon May. Updates (3) to (5) are from Douglas A. Pouk."
This commit is contained in:
99
include/osgParticle/AngularAccelOperator
Normal file
99
include/osgParticle/AngularAccelOperator
Normal file
@@ -0,0 +1,99 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
//osgParticle - Copyright (C) 2002 Marco Jez
|
||||
|
||||
#ifndef OSGPARTICLE_ANGULARACCELOPERATOR_
|
||||
#define OSGPARTICLE_ANGULARACCELOPERATOR_ 1
|
||||
|
||||
#include <osgParticle/ModularProgram>
|
||||
#include <osgParticle/Operator>
|
||||
#include <osgParticle/Particle>
|
||||
|
||||
#include <osg/CopyOp>
|
||||
#include <osg/Object>
|
||||
#include <osg/Vec3>
|
||||
|
||||
namespace osgParticle
|
||||
{
|
||||
|
||||
/** An operator class that applies a constant angular acceleration to
|
||||
* the particles.
|
||||
*/
|
||||
class AngularAccelOperator: public Operator {
|
||||
public:
|
||||
inline AngularAccelOperator();
|
||||
inline AngularAccelOperator(const AngularAccelOperator ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgParticle, AngularAccelOperator);
|
||||
|
||||
/// Get the angular acceleration vector.
|
||||
inline const osg::Vec3 &getAngularAcceleration() const;
|
||||
|
||||
/// Set the angular acceleration vector.
|
||||
inline void setAngularAcceleration(const osg::Vec3 &v);
|
||||
|
||||
/// Apply the angular acceleration to a particle. Do not call this method manually.
|
||||
inline void operate(Particle *P, double dt);
|
||||
|
||||
/// Perform some initializations. Do not call this method manually.
|
||||
inline void beginOperate(Program *prg);
|
||||
|
||||
protected:
|
||||
virtual ~AngularAccelOperator() {}
|
||||
AngularAccelOperator &operator=(const AngularAccelOperator &) { return *this; }
|
||||
|
||||
private:
|
||||
osg::Vec3 angular_accel_;
|
||||
osg::Vec3 xf_angular_accel_;
|
||||
};
|
||||
|
||||
// INLINE FUNCTIONS
|
||||
|
||||
inline AngularAccelOperator::AngularAccelOperator()
|
||||
: Operator(), angular_accel_(0, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
inline AngularAccelOperator::AngularAccelOperator(const AngularAccelOperator ©, const osg::CopyOp ©op)
|
||||
: Operator(copy, copyop), angular_accel_(copy.angular_accel_)
|
||||
{
|
||||
}
|
||||
|
||||
inline const osg::Vec3 &AngularAccelOperator::getAngularAcceleration() const
|
||||
{
|
||||
return angular_accel_;
|
||||
}
|
||||
|
||||
inline void AngularAccelOperator::setAngularAcceleration(const osg::Vec3 &v)
|
||||
{
|
||||
angular_accel_ = v;
|
||||
}
|
||||
|
||||
inline void AngularAccelOperator::operate(Particle *P, double dt)
|
||||
{
|
||||
P->addAngularVelocity(xf_angular_accel_ * dt);
|
||||
}
|
||||
|
||||
inline void AngularAccelOperator::beginOperate(Program *prg)
|
||||
{
|
||||
if (prg->getReferenceFrame() == ModularProgram::RELATIVE_TO_PARENTS) {
|
||||
xf_angular_accel_ = prg->rotateLocalToWorld(angular_accel_);
|
||||
} else {
|
||||
xf_angular_accel_ = angular_accel_;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -45,11 +45,16 @@ namespace osgParticle
|
||||
class OSGPARTICLE_EXPORT Particle {
|
||||
public:
|
||||
|
||||
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
|
||||
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
|
||||
};
|
||||
|
||||
Particle();
|
||||
@@ -112,6 +117,15 @@ 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;
|
||||
|
||||
/** Kill the particle on next update
|
||||
NOTE: after calling this function, the <CODE>isAlive()</CODE> method will still
|
||||
return true until the particle is updated again.
|
||||
@@ -164,6 +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);
|
||||
|
||||
/** 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,
|
||||
@@ -206,6 +235,10 @@ namespace osgParticle
|
||||
osg::Vec3 position_;
|
||||
osg::Vec3 velocity_;
|
||||
|
||||
osg::Vec3 prev_angle_;
|
||||
osg::Vec3 angle_;
|
||||
osg::Vec3 angular_vel_;
|
||||
|
||||
double t0_;
|
||||
|
||||
float current_size_;
|
||||
@@ -295,6 +328,21 @@ 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 void Particle::kill()
|
||||
{
|
||||
mustdie_ = true;
|
||||
@@ -345,9 +393,9 @@ namespace osgParticle
|
||||
velocity_ = v;
|
||||
}
|
||||
|
||||
inline void Particle::addVelocity(const osg::Vec3 &v)
|
||||
inline void Particle::addVelocity(const osg::Vec3 &dv)
|
||||
{
|
||||
velocity_ += v;
|
||||
velocity_ += dv;
|
||||
}
|
||||
|
||||
inline void Particle::transformPositionVelocity(const osg::Matrix &xform)
|
||||
@@ -362,6 +410,33 @@ namespace osgParticle
|
||||
velocity_ = p1 - position_;
|
||||
}
|
||||
|
||||
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_;
|
||||
}
|
||||
|
||||
inline float Particle::getMass() const
|
||||
{
|
||||
return mass_;
|
||||
@@ -388,6 +463,9 @@ namespace osgParticle
|
||||
case QUAD:
|
||||
glBegin(GL_QUADS);
|
||||
break;
|
||||
case LINE:
|
||||
glBegin(GL_LINES);
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
@@ -398,6 +476,7 @@ namespace osgParticle
|
||||
{
|
||||
case POINT:
|
||||
case QUAD:
|
||||
case LINE:
|
||||
glEnd();
|
||||
break;
|
||||
default: ;
|
||||
|
||||
@@ -72,6 +72,36 @@ namespace osgParticle
|
||||
/// Set the destination particle system.
|
||||
inline void setParticleSystem(ParticleSystem *ps);
|
||||
|
||||
/// Set the endless flag of this processor.
|
||||
inline void setEndless(bool type);
|
||||
|
||||
/// Check whether this processor is endless.
|
||||
inline bool isEndless() const;
|
||||
|
||||
/// Set the lifetime of this processor.
|
||||
inline void setLifeTime(double t);
|
||||
|
||||
/// Get the lifetime of this processor.
|
||||
inline double getLifeTime() const;
|
||||
|
||||
/// Set the start time of this processor.
|
||||
inline void setStartTime(double t);
|
||||
|
||||
/// Get the start time of this processor.
|
||||
inline double getStartTime() const;
|
||||
|
||||
/// Set the current time of this processor.
|
||||
inline void setCurrentTime(double t);
|
||||
|
||||
/// Get the current time of this processor.
|
||||
inline double getCurrentTime() const;
|
||||
|
||||
/// Set the reset time of this processor. A value of 0 disables reset.
|
||||
inline void setResetTime(double t);
|
||||
|
||||
/// Get the reset time of this processor.
|
||||
inline double getResetTime() const;
|
||||
|
||||
void traverse(osg::NodeVisitor &nv);
|
||||
|
||||
/// Get the current local-to-world transformation matrix (valid only during cull traversal).
|
||||
@@ -110,6 +140,13 @@ namespace osgParticle
|
||||
osg::Matrix ltw_matrix_;
|
||||
osg::Matrix wtl_matrix_;
|
||||
osg::NodeVisitor *current_nodevisitor_;
|
||||
|
||||
bool endless_;
|
||||
|
||||
double lifeTime_;
|
||||
double startTime_;
|
||||
double currentTime_;
|
||||
double resetTime_;
|
||||
};
|
||||
|
||||
// INLINE FUNCTIONS
|
||||
@@ -132,7 +169,10 @@ namespace osgParticle
|
||||
inline void ParticleProcessor::setEnabled(bool v)
|
||||
{
|
||||
enabled_ = v;
|
||||
if (enabled_) t0_ = -1;
|
||||
if (enabled_) {
|
||||
t0_ = -1;
|
||||
currentTime_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline ParticleSystem *ParticleProcessor::getParticleSystem()
|
||||
@@ -149,6 +189,56 @@ namespace osgParticle
|
||||
{
|
||||
ps_ = ps;
|
||||
}
|
||||
|
||||
inline void ParticleProcessor::setEndless(bool type)
|
||||
{
|
||||
endless_ = type;
|
||||
}
|
||||
|
||||
inline bool ParticleProcessor::isEndless() const
|
||||
{
|
||||
return endless_;
|
||||
}
|
||||
|
||||
inline void ParticleProcessor::setLifeTime(double t)
|
||||
{
|
||||
lifeTime_ = t;
|
||||
endless_ = false;
|
||||
}
|
||||
|
||||
inline double ParticleProcessor::getLifeTime() const
|
||||
{
|
||||
return lifeTime_;
|
||||
}
|
||||
|
||||
inline void ParticleProcessor::setStartTime(double t)
|
||||
{
|
||||
startTime_ = t;
|
||||
}
|
||||
|
||||
inline double ParticleProcessor::getStartTime() const
|
||||
{
|
||||
return startTime_;
|
||||
}
|
||||
inline void ParticleProcessor::setCurrentTime(double t)
|
||||
{
|
||||
currentTime_ = t;
|
||||
}
|
||||
|
||||
inline double ParticleProcessor::getCurrentTime() const
|
||||
{
|
||||
return currentTime_;
|
||||
}
|
||||
|
||||
inline void ParticleProcessor::setResetTime(double t)
|
||||
{
|
||||
resetTime_ = t;
|
||||
}
|
||||
|
||||
inline double ParticleProcessor::getResetTime() const
|
||||
{
|
||||
return resetTime_;
|
||||
}
|
||||
|
||||
inline bool ParticleProcessor::computeBound() const
|
||||
{
|
||||
|
||||
@@ -297,8 +297,8 @@ namespace osgParticle
|
||||
if (!bounds_computed_) {
|
||||
_bbox = def_bbox_;
|
||||
} else {
|
||||
_bbox._min = bmin_;
|
||||
_bbox._max = bmax_;
|
||||
_bbox._min = bmin_;
|
||||
_bbox._max = bmax_;
|
||||
}
|
||||
_bbox_computed = true;
|
||||
return true;
|
||||
|
||||
@@ -67,6 +67,15 @@ namespace osgParticle
|
||||
/// Set the range of possible values for initial speed of particles.
|
||||
inline void setInitialSpeedRange(float r1, float r2);
|
||||
|
||||
/// Get the range of possible values for initial rotational speed of particles.
|
||||
inline const rangev3 &getInitialRotationalSpeedRange() const;
|
||||
|
||||
/// Set the range of possible values for initial rotational speed of particles.
|
||||
inline void setInitialRotationalSpeedRange(const rangev3 &r);
|
||||
|
||||
/// Set the range of possible values for initial rotational speed of particles.
|
||||
inline void setInitialRotationalSpeedRange(const osg::Vec3 &r1, const osg::Vec3 &r2);
|
||||
|
||||
/// Shoot a particle. Do not call this method manually.
|
||||
inline void shoot(Particle *P) const;
|
||||
|
||||
@@ -78,6 +87,7 @@ namespace osgParticle
|
||||
rangef theta_range_;
|
||||
rangef phi_range_;
|
||||
rangef speed_range_;
|
||||
rangev3 rot_speed_range_;
|
||||
};
|
||||
|
||||
// INLINE FUNCTIONS
|
||||
@@ -86,7 +96,8 @@ namespace osgParticle
|
||||
: Shooter(),
|
||||
theta_range_(0, 0.5f*osg::PI_4),
|
||||
phi_range_(0, 2*osg::PI),
|
||||
speed_range_(10, 10)
|
||||
speed_range_(10, 10),
|
||||
rot_speed_range_(osg::Vec3(0,0,0), osg::Vec3(0,0,0))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -94,7 +105,8 @@ namespace osgParticle
|
||||
: Shooter(copy, copyop),
|
||||
theta_range_(copy.theta_range_),
|
||||
phi_range_(copy.phi_range_),
|
||||
speed_range_(copy.speed_range_)
|
||||
speed_range_(copy.speed_range_),
|
||||
rot_speed_range_(copy.rot_speed_range_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -113,6 +125,11 @@ namespace osgParticle
|
||||
return speed_range_;
|
||||
}
|
||||
|
||||
inline const rangev3 &RadialShooter::getInitialRotationalSpeedRange() const
|
||||
{
|
||||
return rot_speed_range_;
|
||||
}
|
||||
|
||||
inline void RadialShooter::setThetaRange(const rangef &r)
|
||||
{
|
||||
theta_range_ = r;
|
||||
@@ -146,17 +163,31 @@ namespace osgParticle
|
||||
speed_range_.maximum = r2;
|
||||
}
|
||||
|
||||
inline void RadialShooter::setInitialRotationalSpeedRange(const rangev3 &r)
|
||||
{
|
||||
rot_speed_range_ = r;
|
||||
}
|
||||
|
||||
inline void RadialShooter::setInitialRotationalSpeedRange(const osg::Vec3 &r1, const osg::Vec3 &r2)
|
||||
{
|
||||
rot_speed_range_.minimum = r1;
|
||||
rot_speed_range_.maximum = r2;
|
||||
}
|
||||
|
||||
inline void RadialShooter::shoot(Particle *P) const
|
||||
{
|
||||
float theta = theta_range_.get_random();
|
||||
float phi = phi_range_.get_random();
|
||||
float speed = speed_range_.get_random();
|
||||
osg::Vec3 rot_speed = rot_speed_range_.get_random();
|
||||
|
||||
P->setVelocity(osg::Vec3(
|
||||
speed * sinf(theta) * cosf(phi),
|
||||
speed * sinf(theta) * sinf(phi),
|
||||
speed * cosf(theta)
|
||||
));
|
||||
|
||||
P->setAngularVelocity(rot_speed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user