ParticleProcessor
Go to the documentation of this file.
/* -*-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
* (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_PARTICLEPROCESSOR
#define OSGPARTICLE_PARTICLEPROCESSOR 1
#include <osgParticle/Export>
#include <osgParticle/ParticleSystem>
#include <osg/ref_ptr>
#include <osg/Object>
#include <osg/Transform>
#include <osg/NodeVisitor>
#include <osg/CopyOp>
#include <osg/Vec3>
#include <osg/Matrix>
namespace osgParticle
{
class OSGPARTICLE_EXPORT ParticleProcessor: public osg::Node {
public:
enum ReferenceFrame {
RELATIVE_RF,
ABSOLUTE_RF
};
ParticleProcessor();
ParticleProcessor(const ParticleProcessor& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
virtual const char* libraryName() const { return "osgParticle"; }
virtual const char* className() const { return "ParticleProcessor"; }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ParticleProcessor*>(obj) != 0; }
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
inline ReferenceFrame getReferenceFrame() const;
inline void setReferenceFrame(ReferenceFrame rf);
bool getEnabled() const { return _enabled; }
inline bool isEnabled() const;
inline void setEnabled(bool v);
inline ParticleSystem* getParticleSystem();
inline const ParticleSystem* getParticleSystem() const;
virtual void setParticleSystem(ParticleSystem* ps);
inline void setEndless(bool type);
bool getEndless() const { return _endless; }
inline bool isEndless() const;
inline void setLifeTime(double t);
inline double getLifeTime() const;
inline void setStartTime(double t);
inline double getStartTime() const;
inline void setCurrentTime(double t);
inline double getCurrentTime() const;
inline void setResetTime(double t);
inline double getResetTime() const;
inline bool isAlive() const;
void traverse(osg::NodeVisitor& nv);
inline const osg::Matrix& getLocalToWorldMatrix();
inline const osg::Matrix& getWorldToLocalMatrix();
inline const osg::Matrix& getPreviousLocalToWorldMatrix();
inline const osg::Matrix& getPreviousWorldToLocalMatrix();
inline osg::Vec3 transformLocalToWorld(const osg::Vec3& P);
inline osg::Vec3 rotateLocalToWorld(const osg::Vec3& P);
inline osg::Vec3 transformWorldToLocal(const osg::Vec3& P);
inline osg::Vec3 rotateWorldToLocal(const osg::Vec3& P);
virtual osg::BoundingSphere computeBound() const;
protected:
virtual ~ParticleProcessor() {}
ParticleProcessor& operator=(const ParticleProcessor&) { return *this; }
virtual void process(double dt) = 0;
ReferenceFrame _rf;
bool _enabled;
double _t0;
osg::ref_ptr<ParticleSystem> _ps;
bool _first_ltw_compute;
bool _need_ltw_matrix;
bool _first_wtl_compute;
bool _need_wtl_matrix;
osg::Matrix _ltw_matrix;
osg::Matrix _wtl_matrix;
osg::Matrix _previous_ltw_matrix;
osg::Matrix _previous_wtl_matrix;
osg::NodeVisitor* _current_nodevisitor;
bool _endless;
double _lifeTime;
double _startTime;
double _currentTime;
double _resetTime;
//added- 1/17/06- bgandere@nps.edu
//a var to keep from doing multiple updates
unsigned int _frameNumber;
};
// INLINE FUNCTIONS
inline ParticleProcessor::ReferenceFrame ParticleProcessor::getReferenceFrame() const
{
return _rf;
}
inline void ParticleProcessor::setReferenceFrame(ReferenceFrame rf)
{
_rf = rf;
}
inline bool ParticleProcessor::isEnabled() const
{
return _enabled;
}
inline void ParticleProcessor::setEnabled(bool v)
{
_enabled = v;
if (_enabled)
{
_currentTime = 0;
}
}
inline ParticleSystem* ParticleProcessor::getParticleSystem()
{
return _ps.get();
}
inline const ParticleSystem* ParticleProcessor::getParticleSystem() const
{
return _ps.get();
}
inline void ParticleProcessor::setEndless(bool type)
{
_endless = type;
}
inline bool ParticleProcessor::isEndless() const
{
return _endless;
}
inline void ParticleProcessor::setLifeTime(double t)
{
_lifeTime = t;
}
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 const osg::Matrix& ParticleProcessor::getLocalToWorldMatrix()
{
if (_need_ltw_matrix) {
_previous_ltw_matrix = _ltw_matrix;
_ltw_matrix = osg::computeLocalToWorld(_current_nodevisitor->getNodePath());
if (_first_ltw_compute)
{
_previous_ltw_matrix = _ltw_matrix;
_first_ltw_compute = false;
}
_need_ltw_matrix = false;
}
return _ltw_matrix;
}
inline const osg::Matrix& ParticleProcessor::getWorldToLocalMatrix()
{
if (_need_wtl_matrix) {
_previous_wtl_matrix = _wtl_matrix;
_wtl_matrix = osg::computeWorldToLocal(_current_nodevisitor->getNodePath());
if (_first_wtl_compute)
{
_previous_wtl_matrix = _wtl_matrix;
_first_wtl_compute = false;
}
_need_wtl_matrix = false;
}
return _wtl_matrix;
}
inline const osg::Matrix& ParticleProcessor::getPreviousLocalToWorldMatrix()
{
if (_need_ltw_matrix) getLocalToWorldMatrix();
return _previous_ltw_matrix;
}
inline const osg::Matrix& ParticleProcessor::getPreviousWorldToLocalMatrix()
{
if (_need_wtl_matrix) getWorldToLocalMatrix();
return _previous_wtl_matrix;
}
inline osg::Vec3 ParticleProcessor::transformLocalToWorld(const osg::Vec3& P)
{
return getLocalToWorldMatrix().preMult(P);
}
inline osg::Vec3 ParticleProcessor::transformWorldToLocal(const osg::Vec3& P)
{
return getWorldToLocalMatrix().preMult(P);
}
inline osg::Vec3 ParticleProcessor::rotateLocalToWorld(const osg::Vec3& P)
{
return getLocalToWorldMatrix().preMult(P) -
getLocalToWorldMatrix().preMult(osg::Vec3(0, 0, 0));
}
inline osg::Vec3 ParticleProcessor::rotateWorldToLocal(const osg::Vec3& P)
{
return getWorldToLocalMatrix().preMult(P) -
getWorldToLocalMatrix().preMult(osg::Vec3(0, 0, 0));
}
inline bool ParticleProcessor::isAlive() const
{
return _currentTime < (_lifeTime + _startTime);
}
}
#endif
CopyOp
Matrix
NodeVisitor
Object
ParticleSystem
Transform
Vec3
osgParticle::ParticleProcessor::rotateWorldToLocal
osg::Vec3 rotateWorldToLocal(const osg::Vec3 &P)
Transform a vector from world to local coordinates, discarding translation (valid only during cull tr...
Definition ParticleProcessor:321
osgParticle::ParticleProcessor::getLifeTime
double getLifeTime() const
Get the lifetime of this processor.
Definition ParticleProcessor:229
osgParticle::ParticleProcessor::ReferenceFrame
ReferenceFrame
Definition ParticleProcessor:41
osgParticle::ParticleProcessor::RELATIVE_RF
@ RELATIVE_RF
Definition ParticleProcessor:42
osgParticle::ParticleProcessor::ABSOLUTE_RF
@ ABSOLUTE_RF
Definition ParticleProcessor:43
osgParticle::ParticleProcessor::setStartTime
void setStartTime(double t)
Set the start time of this processor.
Definition ParticleProcessor:234
osgParticle::ParticleProcessor::className
virtual const char * className() const
Definition ParticleProcessor:50
osgParticle::ParticleProcessor::ParticleProcessor
ParticleProcessor(const ParticleProcessor &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgParticle::ParticleProcessor::isEndless
bool isEndless() const
Definition ParticleProcessor:219
osgParticle::ParticleProcessor::getWorldToLocalMatrix
const osg::Matrix & getWorldToLocalMatrix()
Get the current world-to-local transformation matrix (valid only during cull traversal).
Definition ParticleProcessor:278
osgParticle::ParticleProcessor::getLocalToWorldMatrix
const osg::Matrix & getLocalToWorldMatrix()
Get the current local-to-world transformation matrix (valid only during cull traversal).
Definition ParticleProcessor:263
osgParticle::ParticleProcessor::setParticleSystem
virtual void setParticleSystem(ParticleSystem *ps)
Set the destination particle system.
osgParticle::ParticleProcessor::getReferenceFrame
ReferenceFrame getReferenceFrame() const
Get the reference frame.
Definition ParticleProcessor:179
osgParticle::ParticleProcessor::getStartTime
double getStartTime() const
Get the start time of this processor.
Definition ParticleProcessor:239
osgParticle::ParticleProcessor::getEndless
bool getEndless() const
Check whether this processor is endless.
Definition ParticleProcessor:80
osgParticle::ParticleProcessor::_resetTime
double _resetTime
Definition ParticleProcessor:170
osgParticle::ParticleProcessor::_wtl_matrix
osg::Matrix _wtl_matrix
Definition ParticleProcessor:160
osgParticle::ParticleProcessor::setEndless
void setEndless(bool type)
Set the endless flag of this processor.
Definition ParticleProcessor:214
osgParticle::ParticleProcessor::setResetTime
void setResetTime(double t)
Set the reset time of this processor. A value of 0 disables reset.
Definition ParticleProcessor:253
osgParticle::ParticleProcessor::getPreviousLocalToWorldMatrix
const osg::Matrix & getPreviousLocalToWorldMatrix()
Get the previous local-to-world transformation matrix (valid only during cull traversal).
Definition ParticleProcessor:293
osgParticle::ParticleProcessor::accept
virtual void accept(osg::NodeVisitor &nv)
Definition ParticleProcessor:52
osgParticle::ParticleProcessor::_lifeTime
double _lifeTime
Definition ParticleProcessor:167
osgParticle::ParticleProcessor::transformWorldToLocal
osg::Vec3 transformWorldToLocal(const osg::Vec3 &P)
Transform a point from world to local coordinates (valid only during cull traversal).
Definition ParticleProcessor:310
osgParticle::ParticleProcessor::_endless
bool _endless
Definition ParticleProcessor:165
osgParticle::ParticleProcessor::operator=
ParticleProcessor & operator=(const ParticleProcessor &)
Definition ParticleProcessor:147
osgParticle::ParticleProcessor::_first_wtl_compute
bool _first_wtl_compute
Definition ParticleProcessor:157
osgParticle::ParticleProcessor::getParticleSystem
ParticleSystem * getParticleSystem()
Get a pointer to the destination particle system.
Definition ParticleProcessor:203
osgParticle::ParticleProcessor::isAlive
bool isAlive() const
Definition ParticleProcessor:327
osgParticle::ParticleProcessor::setEnabled
void setEnabled(bool v)
Set whether this processor is enabled or not.
Definition ParticleProcessor:194
osgParticle::ParticleProcessor::setReferenceFrame
void setReferenceFrame(ReferenceFrame rf)
Set the reference frame.
Definition ParticleProcessor:184
osgParticle::ParticleProcessor::getCurrentTime
double getCurrentTime() const
Get the current time of this processor.
Definition ParticleProcessor:248
osgParticle::ParticleProcessor::process
virtual void process(double dt)=0
osgParticle::ParticleProcessor::libraryName
virtual const char * libraryName() const
Definition ParticleProcessor:49
osgParticle::ParticleProcessor::_t0
double _t0
Definition ParticleProcessor:153
osgParticle::ParticleProcessor::_startTime
double _startTime
Definition ParticleProcessor:168
osgParticle::ParticleProcessor::getEnabled
bool getEnabled() const
Get whether this processor is enabled or not.
Definition ParticleProcessor:61
osgParticle::ParticleProcessor::rotateLocalToWorld
osg::Vec3 rotateLocalToWorld(const osg::Vec3 &P)
Transform a vector from local to world coordinates, discarding translation (valid only during cull tr...
Definition ParticleProcessor:315
osgParticle::ParticleProcessor::_rf
ReferenceFrame _rf
Definition ParticleProcessor:151
osgParticle::ParticleProcessor::setLifeTime
void setLifeTime(double t)
Set the lifetime of this processor.
Definition ParticleProcessor:224
osgParticle::ParticleProcessor::_ps
osg::ref_ptr< ParticleSystem > _ps
Definition ParticleProcessor:154
osgParticle::ParticleProcessor::getResetTime
double getResetTime() const
Get the reset time of this processor.
Definition ParticleProcessor:258
osgParticle::ParticleProcessor::computeBound
virtual osg::BoundingSphere computeBound() const
osgParticle::ParticleProcessor::_first_ltw_compute
bool _first_ltw_compute
Definition ParticleProcessor:155
osgParticle::ParticleProcessor::_previous_wtl_matrix
osg::Matrix _previous_wtl_matrix
Definition ParticleProcessor:162
osgParticle::ParticleProcessor::~ParticleProcessor
virtual ~ParticleProcessor()
Definition ParticleProcessor:146
osgParticle::ParticleProcessor::_frameNumber
unsigned int _frameNumber
Definition ParticleProcessor:174
osgParticle::ParticleProcessor::_previous_ltw_matrix
osg::Matrix _previous_ltw_matrix
Definition ParticleProcessor:161
osgParticle::ParticleProcessor::setCurrentTime
void setCurrentTime(double t)
Set the current time of this processor.
Definition ParticleProcessor:243
osgParticle::ParticleProcessor::_current_nodevisitor
osg::NodeVisitor * _current_nodevisitor
Definition ParticleProcessor:163
osgParticle::ParticleProcessor::_need_wtl_matrix
bool _need_wtl_matrix
Definition ParticleProcessor:158
osgParticle::ParticleProcessor::_enabled
bool _enabled
Definition ParticleProcessor:152
osgParticle::ParticleProcessor::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition ParticleProcessor:51
osgParticle::ParticleProcessor::ParticleProcessor
ParticleProcessor()
osgParticle::ParticleProcessor::traverse
void traverse(osg::NodeVisitor &nv)
osgParticle::ParticleProcessor::getPreviousWorldToLocalMatrix
const osg::Matrix & getPreviousWorldToLocalMatrix()
Get the previous world-to-local transformation matrix (valid only during cull traversal).
Definition ParticleProcessor:299
osgParticle::ParticleProcessor::_need_ltw_matrix
bool _need_ltw_matrix
Definition ParticleProcessor:156
osgParticle::ParticleProcessor::_ltw_matrix
osg::Matrix _ltw_matrix
Definition ParticleProcessor:159
osgParticle::ParticleProcessor::_currentTime
double _currentTime
Definition ParticleProcessor:169
osgParticle::ParticleProcessor::isEnabled
bool isEnabled() const
Definition ParticleProcessor:189
osgParticle::ParticleProcessor::transformLocalToWorld
osg::Vec3 transformLocalToWorld(const osg::Vec3 &P)
Transform a point from local to world coordinates (valid only during cull traversal).
Definition ParticleProcessor:305
osgParticle::ParticleSystem
Definition ParticleSystem:54
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Matrixd::preMult
Vec3f preMult(const Vec3f &v) const
Definition Matrixd:618
osg::NodeVisitor
Definition NodeVisitor:82
osg::NodeVisitor::apply
virtual void apply(Drawable &drawable)
osg::NodeVisitor::pushOntoNodePath
void pushOntoNodePath(Node *node)
Definition NodeVisitor:287
osg::NodeVisitor::validNodeMask
bool validNodeMask(const osg::Node &node) const
Definition NodeVisitor:221
osg::NodeVisitor::popFromNodePath
void popFromNodePath()
Definition NodeVisitor:293
osg::Node
Definition Node:72
osg::Object
Definition Object:61
osg::ref_ptr
Definition ref_ptr:32
osgParticle
Definition AccelOperator:27
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::computeLocalToWorld
OSG_EXPORT Matrix computeLocalToWorld(const NodePath &nodePath, bool ignoreCameras=true)
osg::computeWorldToLocal
OSG_EXPORT Matrix computeWorldToLocal(const NodePath &nodePath, bool ignoreCameras=true)
Export
OSGPARTICLE_EXPORT
#define OSGPARTICLE_EXPORT
Definition osgParticle/Export:40
ref_ptr