ForceOperator
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_FORCEOPERATOR
#define OSGPARTICLE_FORCEOPERATOR 1
#include <osgParticle/ModularProgram>
#include <osgParticle/Operator>
#include <osgParticle/Particle>
#include <osg/CopyOp>
#include <osg/Object>
#include <osg/Vec3>
namespace osgParticle
{
class ForceOperator: public Operator {
public:
inline ForceOperator();
inline ForceOperator(const ForceOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgParticle, ForceOperator);
inline const osg::Vec3& getForce() const;
inline void setForce(const osg::Vec3& f);
inline void operate(Particle* P, double dt);
inline void beginOperate(Program *prg);
protected:
virtual ~ForceOperator() {};
ForceOperator& operator=(const ForceOperator&) { return *this; }
private:
osg::Vec3 _force;
osg::Vec3 _xf_force;
};
// INLINE FUNCTIONS
inline ForceOperator::ForceOperator()
: Operator(), _force(0, 0, 0)
{
}
inline ForceOperator::ForceOperator(const ForceOperator& copy, const osg::CopyOp& copyop)
: Operator(copy, copyop), _force(copy._force)
{
}
inline const osg::Vec3& ForceOperator::getForce() const
{
return _force;
}
inline void ForceOperator::setForce(const osg::Vec3& v)
{
_force = v;
}
inline void ForceOperator::operate(Particle* P, double dt)
{
P->addVelocity(_xf_force * (P->getMassInv() * dt));
}
inline void ForceOperator::beginOperate(Program *prg)
{
if (prg->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
_xf_force = prg->rotateLocalToWorld(_force);
} else {
_xf_force = _force;
}
}
}
#endif
CopyOp
ModularProgram
Object
Operator
Particle
Vec3
osgParticle::ForceOperator::beginOperate
void beginOperate(Program *prg)
Perform some initialization. Do not call this method manually.
Definition ForceOperator:88
osgParticle::ForceOperator::operate
void operate(Particle *P, double dt)
Apply the force to a particle. Do not call this method manually.
Definition ForceOperator:83
osgParticle::ForceOperator::ForceOperator
ForceOperator()
Definition ForceOperator:63
osgParticle::ForceOperator::getForce
const osg::Vec3 & getForce() const
Get the force vector.
Definition ForceOperator:73
osgParticle::ForceOperator::~ForceOperator
virtual ~ForceOperator()
Definition ForceOperator:53
osgParticle::ForceOperator::setForce
void setForce(const osg::Vec3 &f)
Set the force vector.
Definition ForceOperator:78
osgParticle::ForceOperator::META_Object
META_Object(osgParticle, ForceOperator)
osgParticle::ForceOperator::operator=
ForceOperator & operator=(const ForceOperator &)
Definition ForceOperator:54
osgParticle::Operator::Operator
Operator()
Definition Operator:92
osgParticle::ParticleProcessor::RELATIVE_RF
@ RELATIVE_RF
Definition ParticleProcessor:42
osgParticle::ParticleProcessor::getReferenceFrame
ReferenceFrame getReferenceFrame() const
Get the reference frame.
Definition ParticleProcessor:179
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::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::getMassInv
float getMassInv() const
Get 1 / getMass().
Definition Particle:547
osgParticle::Program
Definition osgParticle/Program:36
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osgParticle
Definition AccelOperator:27
osg::Vec3
Vec3f Vec3
Definition Vec3:21