1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13//osgParticle - Copyright (C) 2002 Marco Jez
15#ifndef OSGPARTICLE_FORCEOPERATOR
16#define OSGPARTICLE_FORCEOPERATOR 1
18#include <osgParticle/ModularProgram>
19#include <osgParticle/Operator>
20#include <osgParticle/Particle>
29 /** An operator that applies a constant force to the particles.
30 * Remember that if the mass of particles is expressed in kg and the lengths are
31 * expressed in meters, then the force should be expressed in Newtons.
33 class ForceOperator: public Operator {
35 inline ForceOperator();
36 inline ForceOperator(const ForceOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
38 META_Object(osgParticle, ForceOperator);
40 /// Get the force vector.
41 inline const osg::Vec3& getForce() const;
43 /// Set the force vector.
44 inline void setForce(const osg::Vec3& f);
46 /// Apply the force to a particle. Do not call this method manually.
47 inline void operate(Particle* P, double dt);
49 /// Perform some initialization. Do not call this method manually.
50 inline void beginOperate(Program *prg);
53 virtual ~ForceOperator() {};
54 ForceOperator& operator=(const ForceOperator&) { return *this; }
63 inline ForceOperator::ForceOperator()
64 : Operator(), _force(0, 0, 0)
68 inline ForceOperator::ForceOperator(const ForceOperator& copy, const osg::CopyOp& copyop)
69 : Operator(copy, copyop), _force(copy._force)
73 inline const osg::Vec3& ForceOperator::getForce() const
78 inline void ForceOperator::setForce(const osg::Vec3& v)
83 inline void ForceOperator::operate(Particle* P, double dt)
85 P->addVelocity(_xf_force * (P->getMassInv() * dt));
88 inline void ForceOperator::beginOperate(Program *prg)
90 if (prg->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
91 _xf_force = prg->rotateLocalToWorld(_force);