OrbitOperator
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_ORBITOPERATOR
#define OSGPARTICLE_ORBITOPERATOR
#include <osgParticle/ModularProgram>
#include <osgParticle/Operator>
#include <osgParticle/Particle>
namespace osgParticle
{
class OrbitOperator : public Operator
{
public:
OrbitOperator()
: Operator(), _magnitude(1.0f), _epsilon(1e-3), _maxRadius(FLT_MAX)
{}
OrbitOperator( const OrbitOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY )
: Operator(copy, copyop), _center(copy._center), _magnitude(copy._magnitude),
_epsilon(copy._epsilon), _maxRadius(copy._maxRadius)
{}
META_Object( osgParticle, OrbitOperator );
void setCenter( const osg::Vec3& c ) { _center = c; }
const osg::Vec3& getCenter() const { return _center; }
void setMagnitude( float mag ) { _magnitude = mag; }
float getMagnitude() const { return _magnitude; }
void setEpsilon( float eps ) { _epsilon = eps; }
float getEpsilon() const { return _epsilon; }
void setMaxRadius( float max ) { _maxRadius = max; }
float getMaxRadius() const { return _maxRadius; }
inline void operate( Particle* P, double dt );
inline void beginOperate( Program* prg );
protected:
virtual ~OrbitOperator() {}
OrbitOperator& operator=( const OrbitOperator& ) { return *this; }
osg::Vec3 _center;
osg::Vec3 _xf_center;
float _magnitude;
float _epsilon;
float _maxRadius;
};
// INLINE METHODS
inline void OrbitOperator::operate( Particle* P, double dt )
{
osg::Vec3 dir = _xf_center - P->getPosition();
float length = dir.length();
if ( length<_maxRadius )
{
P->addVelocity( dir * ((_magnitude * dt) /
(length * (_epsilon+length*length))) );
}
}
inline void OrbitOperator::beginOperate( Program* prg )
{
if ( prg->getReferenceFrame()==ModularProgram::RELATIVE_RF )
{
_xf_center = prg->transformLocalToWorld(_center);
}
else
{
_xf_center = _center;
}
}
}
#endif
ModularProgram
Operator
Particle
osgParticle::Operator::Operator
Operator()
Definition Operator:92
osgParticle::OrbitOperator::setMagnitude
void setMagnitude(float mag)
Set the acceleration scale.
Definition OrbitOperator:50
osgParticle::OrbitOperator::_epsilon
float _epsilon
Definition OrbitOperator:80
osgParticle::OrbitOperator::beginOperate
void beginOperate(Program *prg)
Perform some initializations. Do not call this method manually.
Definition OrbitOperator:97
osgParticle::OrbitOperator::operator=
OrbitOperator & operator=(const OrbitOperator &)
Definition OrbitOperator:75
osgParticle::OrbitOperator::_maxRadius
float _maxRadius
Definition OrbitOperator:81
osgParticle::OrbitOperator::~OrbitOperator
virtual ~OrbitOperator()
Definition OrbitOperator:74
osgParticle::OrbitOperator::operate
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition OrbitOperator:86
osgParticle::OrbitOperator::_xf_center
osg::Vec3 _xf_center
Definition OrbitOperator:78
osgParticle::OrbitOperator::setEpsilon
void setEpsilon(float eps)
Set the acceleration epsilon.
Definition OrbitOperator:56
osgParticle::OrbitOperator::getCenter
const osg::Vec3 & getCenter() const
Get the center of orbit.
Definition OrbitOperator:47
osgParticle::OrbitOperator::getMagnitude
float getMagnitude() const
Get the acceleration scale.
Definition OrbitOperator:53
osgParticle::OrbitOperator::OrbitOperator
OrbitOperator(const OrbitOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition OrbitOperator:36
osgParticle::OrbitOperator::setMaxRadius
void setMaxRadius(float max)
Set max radius between the center and the particle.
Definition OrbitOperator:62
osgParticle::OrbitOperator::_center
osg::Vec3 _center
Definition OrbitOperator:77
osgParticle::OrbitOperator::getEpsilon
float getEpsilon() const
Get the acceleration epsilon.
Definition OrbitOperator:59
osgParticle::OrbitOperator::META_Object
META_Object(osgParticle, OrbitOperator)
osgParticle::OrbitOperator::OrbitOperator
OrbitOperator()
Definition OrbitOperator:32
osgParticle::OrbitOperator::getMaxRadius
float getMaxRadius() const
Get max radius between the center and the particle.
Definition OrbitOperator:65
osgParticle::OrbitOperator::setCenter
void setCenter(const osg::Vec3 &c)
Set the center of orbit.
Definition OrbitOperator:44
osgParticle::OrbitOperator::_magnitude
float _magnitude
Definition OrbitOperator:79
osgParticle::ParticleProcessor::RELATIVE_RF
@ RELATIVE_RF
Definition ParticleProcessor:42
osgParticle::ParticleProcessor::getReferenceFrame
ReferenceFrame getReferenceFrame() const
Get the reference frame.
Definition ParticleProcessor:179
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::Particle
Definition Particle:47
osgParticle::Particle::addVelocity
void addVelocity(const osg::Vec3 &dv)
Add a vector to the velocity vector.
Definition Particle:493
osgParticle::Particle::getPosition
const osg::Vec3 & getPosition() const
Get the position vector.
Definition Particle:403
osgParticle::Program
Definition osgParticle/Program:36
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Vec3f::length
value_type length() const
Definition Vec3f:176
osgParticle
Definition AccelOperator:27
osg::Vec3
Vec3f Vec3
Definition Vec3:21