AccelOperator
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_ACCELOPERATOR
#define OSGPARTICLE_ACCELOPERATOR 1
#include <osgParticle/ModularProgram>
#include <osgParticle/Operator>
#include <osgParticle/Particle>
#include <osg/CopyOp>
#include <osg/Object>
#include <osg/Vec3>
namespace osgParticle
{
class AccelOperator: public Operator {
public:
inline AccelOperator();
inline AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgParticle, AccelOperator);
inline const osg::Vec3& getAcceleration() const;
inline void setAcceleration(const osg::Vec3& v);
inline void setToGravity(float scale = 1);
inline void operate(Particle* P, double dt);
inline void beginOperate(Program *prg);
protected:
virtual ~AccelOperator() {}
AccelOperator &operator=(const AccelOperator &) { return *this; }
private:
osg::Vec3 _accel;
osg::Vec3 _xf_accel;
};
// INLINE FUNCTIONS
inline AccelOperator::AccelOperator()
: Operator(), _accel(0, 0, 0)
{
}
inline AccelOperator::AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop)
: Operator(copy, copyop), _accel(copy._accel)
{
}
inline const osg::Vec3& AccelOperator::getAcceleration() const
{
return _accel;
}
inline void AccelOperator::setAcceleration(const osg::Vec3& v)
{
_accel = v;
}
inline void AccelOperator::setToGravity(float scale)
{
_accel.set(0, 0, -9.80665f * scale);
}
inline void AccelOperator::operate(Particle* P, double dt)
{
P->addVelocity(_xf_accel * dt);
}
inline void AccelOperator::beginOperate(Program *prg)
{
if (prg->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
_xf_accel = prg->rotateLocalToWorld(_accel);
} else {
_xf_accel = _accel;
}
}
}
#endif
CopyOp
ModularProgram
Object
Operator
Particle
Vec3
osgParticle::AccelOperator::beginOperate
void beginOperate(Program *prg)
Perform some initializations. Do not call this method manually.
Definition AccelOperator:96
osgParticle::AccelOperator::setToGravity
void setToGravity(float scale=1)
Definition AccelOperator:86
osgParticle::AccelOperator::operator=
AccelOperator & operator=(const AccelOperator &)
Definition AccelOperator:57
osgParticle::AccelOperator::AccelOperator
AccelOperator()
Definition AccelOperator:66
osgParticle::AccelOperator::operate
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition AccelOperator:91
osgParticle::AccelOperator::getAcceleration
const osg::Vec3 & getAcceleration() const
Get the acceleration vector.
Definition AccelOperator:76
osgParticle::AccelOperator::setAcceleration
void setAcceleration(const osg::Vec3 &v)
Set the acceleration vector.
Definition AccelOperator:81
osgParticle::AccelOperator::META_Object
META_Object(osgParticle, AccelOperator)
osgParticle::AccelOperator::~AccelOperator
virtual ~AccelOperator()
Definition AccelOperator:56
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::Program
Definition osgParticle/Program:36
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Vec3f::set
void set(value_type x, value_type y, value_type z)
Definition Vec3f:67
osgParticle
Definition AccelOperator:27
osg::Vec3
Vec3f Vec3
Definition Vec3:21