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_ACCELOPERATOR
16#define OSGPARTICLE_ACCELOPERATOR 1
18#include <osgParticle/ModularProgram>
19#include <osgParticle/Operator>
20#include <osgParticle/Particle>
29 /** An operator class that applies a constant acceleration to the particles.
31 class AccelOperator: public Operator {
33 inline AccelOperator();
34 inline AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
36 META_Object(osgParticle, AccelOperator);
38 /// Get the acceleration vector.
39 inline const osg::Vec3& getAcceleration() const;
41 /// Set the acceleration vector.
42 inline void setAcceleration(const osg::Vec3& v);
44 /** Quickly set the acceleration vector to the gravity on earth (0, 0, -9.81).
45 The acceleration will be multiplied by the <CODE>scale</CODE> parameter.
47 inline void setToGravity(float scale = 1);
49 /// Apply the acceleration to a particle. Do not call this method manually.
50 inline void operate(Particle* P, double dt);
52 /// Perform some initializations. Do not call this method manually.
53 inline void beginOperate(Program *prg);
56 virtual ~AccelOperator() {}
57 AccelOperator &operator=(const AccelOperator &) { return *this; }
66 inline AccelOperator::AccelOperator()
67 : Operator(), _accel(0, 0, 0)
71 inline AccelOperator::AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop)
72 : Operator(copy, copyop), _accel(copy._accel)
76 inline const osg::Vec3& AccelOperator::getAcceleration() const
81 inline void AccelOperator::setAcceleration(const osg::Vec3& v)
86 inline void AccelOperator::setToGravity(float scale)
88 _accel.set(0, 0, -9.80665f * scale);
91 inline void AccelOperator::operate(Particle* P, double dt)
93 P->addVelocity(_xf_accel * dt);
96 inline void AccelOperator::beginOperate(Program *prg)
98 if (prg->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
99 _xf_accel = prg->rotateLocalToWorld(_accel);