DampingOperator
Go to the documentation of this file.
/* -*-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
* (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.
*/
// Written by Wang Rui, (C) 2010
#ifndef OSGPARTICLE_DAMPINGOPERATOR
#define OSGPARTICLE_DAMPINGOPERATOR
#include <osgParticle/Operator>
#include <osgParticle/Particle>
namespace osgParticle
{
class DampingOperator : public Operator
{
public:
DampingOperator() : Operator(), _cutoffLow(0.0f), _cutoffHigh(FLT_MAX)
{ _damping.set(1.0f, 1.0f, 1.0f); }
DampingOperator( const DampingOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY )
: Operator(copy, copyop), _damping(copy._damping),
_cutoffLow(copy._cutoffLow), _cutoffHigh(copy._cutoffHigh)
{}
META_Object( osgParticle, DampingOperator );
void setDamping( float x, float y, float z ) { _damping.set(x, y, z); }
void setDamping( const osg::Vec3& damping ) { _damping = damping; }
void setDamping( float x ) { _damping.set(x, x, x); }
void getDamping( float& x, float& y, float& z ) const
{ x = _damping.x(); y = _damping.y(); z = _damping.z(); }
const osg::Vec3& getDamping() const { return _damping; }
void setCutoff( float low, float high ) { _cutoffLow = low; _cutoffHigh = high; }
void setCutoffLow( float low ) { _cutoffLow = low; }
void setCutoffHigh( float low ) { _cutoffHigh = low; }
void getCutoff( float& low, float& high ) const { low = _cutoffLow; high = _cutoffHigh; }
float getCutoffLow() const { return _cutoffLow; }
float getCutoffHigh() const { return _cutoffHigh; }
inline void operate( Particle* P, double dt );
protected:
virtual ~DampingOperator() {}
DampingOperator& operator=( const DampingOperator& ) { return *this; }
osg::Vec3 _damping;
float _cutoffLow;
float _cutoffHigh;
};
// INLINE METHODS
inline void DampingOperator::operate( Particle* P, double dt )
{
const osg::Vec3& vel = P->getVelocity();
float length2 = vel.length2();
if ( length2>=_cutoffLow && length2<=_cutoffHigh )
{
osg::Vec3 newvel( vel.x() * (1.0f - (1.0f - _damping.x()) * dt),
vel.y() * (1.0f - (1.0f - _damping.y()) * dt),
vel.z() * (1.0f - (1.0f - _damping.z()) * dt) );
P->setVelocity( newvel );
}
}
}
#endif
Operator
Particle
osgParticle::DampingOperator::setCutoffHigh
void setCutoffHigh(float low)
Definition DampingOperator:57
osgParticle::DampingOperator::setDamping
void setDamping(const osg::Vec3 &damping)
Definition DampingOperator:43
osgParticle::DampingOperator::META_Object
META_Object(osgParticle, DampingOperator)
osgParticle::DampingOperator::setCutoff
void setCutoff(float low, float high)
Set the velocity cutoff factors.
Definition DampingOperator:55
osgParticle::DampingOperator::~DampingOperator
virtual ~DampingOperator()
Definition DampingOperator:68
osgParticle::DampingOperator::setDamping
void setDamping(float x, float y, float z)
Set the damping factors.
Definition DampingOperator:42
osgParticle::DampingOperator::getCutoffHigh
float getCutoffHigh() const
Definition DampingOperator:62
osgParticle::DampingOperator::getDamping
void getDamping(float &x, float &y, float &z) const
Get the damping factors.
Definition DampingOperator:49
osgParticle::DampingOperator::_cutoffHigh
float _cutoffHigh
Definition DampingOperator:73
osgParticle::DampingOperator::getDamping
const osg::Vec3 & getDamping() const
Definition DampingOperator:52
osgParticle::DampingOperator::_cutoffLow
float _cutoffLow
Definition DampingOperator:72
osgParticle::DampingOperator::operate
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition DampingOperator:78
osgParticle::DampingOperator::_damping
osg::Vec3 _damping
Definition DampingOperator:71
osgParticle::DampingOperator::setCutoffLow
void setCutoffLow(float low)
Definition DampingOperator:56
osgParticle::DampingOperator::getCutoffLow
float getCutoffLow() const
Definition DampingOperator:61
osgParticle::DampingOperator::DampingOperator
DampingOperator(const DampingOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition DampingOperator:34
osgParticle::DampingOperator::DampingOperator
DampingOperator()
Definition DampingOperator:31
osgParticle::DampingOperator::operator=
DampingOperator & operator=(const DampingOperator &)
Definition DampingOperator:69
osgParticle::DampingOperator::getCutoff
void getCutoff(float &low, float &high) const
Get the velocity cutoff factors.
Definition DampingOperator:60
osgParticle::DampingOperator::setDamping
void setDamping(float x)
Set the damping factors to one value.
Definition DampingOperator:46
osgParticle::Operator::Operator
Operator()
Definition Operator:92
osgParticle::Particle
Definition Particle:47
osgParticle::Particle::getVelocity
const osg::Vec3 & getVelocity() const
Definition Particle:408
osgParticle::Particle::setVelocity
void setVelocity(const osg::Vec3 &v)
Definition Particle:488
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Vec3f::z
value_type & z()
Definition Vec3f:82
osg::Vec3f::y
value_type & y()
Definition Vec3f:81
osg::Vec3f::x
value_type & x()
Definition Vec3f:80
osg::Vec3f::length2
value_type length2() const
Definition Vec3f:182
osgParticle
Definition AccelOperator:27
osg::Vec3
Vec3f Vec3
Definition Vec3:21