AngularDampingOperator
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_ANGULARDAMPINGOPERATOR
#define OSGPARTICLE_ANGULARDAMPINGOPERATOR
#include <osgParticle/Operator>
#include <osgParticle/Particle>
namespace osgParticle
{
class AngularDampingOperator : public Operator
{
public:
AngularDampingOperator() : Operator(), _cutoffLow(0.0f), _cutoffHigh(FLT_MAX)
{}
AngularDampingOperator( const AngularDampingOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY )
: Operator(copy, copyop), _damping(copy._damping),
_cutoffLow(copy._cutoffLow), _cutoffHigh(copy._cutoffHigh)
{}
META_Object( osgParticle, AngularDampingOperator );
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 ~AngularDampingOperator() {}
AngularDampingOperator& operator=( const AngularDampingOperator& ) { return *this; }
osg::Vec3 _damping;
float _cutoffLow;
float _cutoffHigh;
};
// INLINE METHODS
inline void AngularDampingOperator::operate( Particle* P, double dt )
{
const osg::Vec3& vel = P->getAngularVelocity();
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->setAngularVelocity( newvel );
}
}
}
#endif
Operator
Particle
osgParticle::AngularDampingOperator::AngularDampingOperator
AngularDampingOperator(const AngularDampingOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition AngularDampingOperator:34
osgParticle::AngularDampingOperator::getCutoffHigh
float getCutoffHigh() const
Definition AngularDampingOperator:62
osgParticle::AngularDampingOperator::AngularDampingOperator
AngularDampingOperator()
Definition AngularDampingOperator:31
osgParticle::AngularDampingOperator::_cutoffHigh
float _cutoffHigh
Definition AngularDampingOperator:73
osgParticle::AngularDampingOperator::setDamping
void setDamping(float x, float y, float z)
Set the damping factors.
Definition AngularDampingOperator:42
osgParticle::AngularDampingOperator::setCutoffLow
void setCutoffLow(float low)
Definition AngularDampingOperator:56
osgParticle::AngularDampingOperator::setDamping
void setDamping(float x)
Set the damping factors to one value.
Definition AngularDampingOperator:46
osgParticle::AngularDampingOperator::getCutoffLow
float getCutoffLow() const
Definition AngularDampingOperator:61
osgParticle::AngularDampingOperator::_cutoffLow
float _cutoffLow
Definition AngularDampingOperator:72
osgParticle::AngularDampingOperator::~AngularDampingOperator
virtual ~AngularDampingOperator()
Definition AngularDampingOperator:68
osgParticle::AngularDampingOperator::getDamping
void getDamping(float &x, float &y, float &z) const
Get the damping factors.
Definition AngularDampingOperator:49
osgParticle::AngularDampingOperator::operate
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition AngularDampingOperator:78
osgParticle::AngularDampingOperator::setCutoffHigh
void setCutoffHigh(float low)
Definition AngularDampingOperator:57
osgParticle::AngularDampingOperator::operator=
AngularDampingOperator & operator=(const AngularDampingOperator &)
Definition AngularDampingOperator:69
osgParticle::AngularDampingOperator::getCutoff
void getCutoff(float &low, float &high) const
Get the velocity cutoff factors.
Definition AngularDampingOperator:60
osgParticle::AngularDampingOperator::setCutoff
void setCutoff(float low, float high)
Set the velocity cutoff factors.
Definition AngularDampingOperator:55
osgParticle::AngularDampingOperator::META_Object
META_Object(osgParticle, AngularDampingOperator)
osgParticle::AngularDampingOperator::setDamping
void setDamping(const osg::Vec3 &damping)
Definition AngularDampingOperator:43
osgParticle::AngularDampingOperator::_damping
osg::Vec3 _damping
Definition AngularDampingOperator:71
osgParticle::AngularDampingOperator::getDamping
const osg::Vec3 & getDamping() const
Definition AngularDampingOperator:52
osgParticle::Operator::Operator
Operator()
Definition Operator:92
osgParticle::Particle
Definition Particle:47
osgParticle::Particle::getAngularVelocity
const osg::Vec3 & getAngularVelocity() const
Get the rotational velocity vector.
Definition Particle:423
osgParticle::Particle::setAngularVelocity
void setAngularVelocity(const osg::Vec3 &v)
Definition Particle:520
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