OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ForceOperator.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
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.
7  *
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.
12 */
13 //osgParticle - Copyright (C) 2002 Marco Jez
14 
15 #ifndef OSGPARTICLE_FORCEOPERATOR
16 #define OSGPARTICLE_FORCEOPERATOR 1
17 
18 #include <osgParticle/ModularProgram>
19 #include <osgParticle/Operator>
20 #include <osgParticle/Particle>
21 
22 #include <osg/CopyOp>
23 #include <osg/Object>
24 #include <osg/Vec3>
25 
26 namespace osgParticle
27 {
28 
33  class ForceOperator: public Operator {
34  public:
35  inline ForceOperator();
36  inline ForceOperator(const ForceOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
37 
39 
41  inline const osg::Vec3& getForce() const;
42 
44  inline void setForce(const osg::Vec3& f);
45 
47  inline void operate(Particle* P, double dt);
48 
50  inline void beginOperate(Program *prg);
51 
52  protected:
53  virtual ~ForceOperator() {};
54  ForceOperator& operator=(const ForceOperator&) { return *this; }
55 
56  private:
57  osg::Vec3 _force;
58  osg::Vec3 _xf_force;
59  };
60 
61  // INLINE FUNCTIONS
62 
64  : Operator(), _force(0, 0, 0)
65  {
66  }
67 
68  inline ForceOperator::ForceOperator(const ForceOperator& copy, const osg::CopyOp& copyop)
69  : Operator(copy, copyop), _force(copy._force)
70  {
71  }
72 
73  inline const osg::Vec3& ForceOperator::getForce() const
74  {
75  return _force;
76  }
77 
78  inline void ForceOperator::setForce(const osg::Vec3& v)
79  {
80  _force = v;
81  }
82 
83  inline void ForceOperator::operate(Particle* P, double dt)
84  {
85  P->addVelocity(_xf_force * (P->getMassInv() * dt));
86  }
87 
89  {
91  _xf_force = prg->rotateLocalToWorld(_force);
92  } else {
93  _xf_force = _force;
94  }
95  }
96 }
97 
98 #endif
float getMassInv() const
Get 1 / getMass().
Definition: Particle.h:561
void beginOperate(Program *prg)
Perform some initialization. Do not call this method manually.
Definition: ForceOperator.h:88
META_Object(osgParticle, ForceOperator)
osg::Vec3 rotateLocalToWorld(const osg::Vec3 &P)
Transform a vector from local to world coordinates, discarding translation (valid only during cull tr...
void setForce(const osg::Vec3 &f)
Set the force vector.
Definition: ForceOperator.h:78
ReferenceFrame getReferenceFrame() const
Get the reference frame.
const osg::Vec3 & getForce() const
Get the force vector.
Definition: ForceOperator.h:73
ForceOperator & operator=(const ForceOperator &)
Definition: ForceOperator.h:54
void addVelocity(const osg::Vec3 &dv)
Add a vector to the velocity vector.
Definition: Particle.h:507
void operate(Particle *P, double dt)
Apply the force to a particle. Do not call this method manually.
Definition: ForceOperator.h:83