OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OrbitOperator.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 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 // Written by Wang Rui, (C) 2010
14 
15 #ifndef OSGPARTICLE_ORBITOPERATOR
16 #define OSGPARTICLE_ORBITOPERATOR
17 
18 #include <osgParticle/ModularProgram>
19 #include <osgParticle/Operator>
20 #include <osgParticle/Particle>
21 
22 namespace osgParticle
23 {
24 
25 
29 class OrbitOperator : public Operator
30 {
31 public:
33  : Operator(), _magnitude(1.0f), _epsilon(1e-3), _maxRadius(FLT_MAX)
34  {}
35 
37  : Operator(copy, copyop), _center(copy._center), _magnitude(copy._magnitude),
39  {}
40 
42 
44  void setCenter( const osg::Vec3& c ) { _center = c; }
45 
47  const osg::Vec3& getCenter() const { return _center; }
48 
50  void setMagnitude( float mag ) { _magnitude = mag; }
51 
53  float getMagnitude() const { return _magnitude; }
54 
56  void setEpsilon( float eps ) { _epsilon = eps; }
57 
59  float getEpsilon() const { return _epsilon; }
60 
62  void setMaxRadius( float max ) { _maxRadius = max; }
63 
65  float getMaxRadius() const { return _maxRadius; }
66 
68  inline void operate( Particle* P, double dt );
69 
71  inline void beginOperate( Program* prg );
72 
73 protected:
74  virtual ~OrbitOperator() {}
75  OrbitOperator& operator=( const OrbitOperator& ) { return *this; }
76 
79  float _magnitude;
80  float _epsilon;
81  float _maxRadius;
82 };
83 
84 // INLINE METHODS
85 
86 inline void OrbitOperator::operate( Particle* P, double dt )
87 {
88  osg::Vec3 dir = _xf_center - P->getPosition();
89  float length = dir.length();
90  if ( length<_maxRadius )
91  {
92  P->addVelocity( dir * ((_magnitude * dt) /
93  (length * (_epsilon+length*length))) );
94  }
95 }
96 
98 {
100  {
102  }
103  else
104  {
106  }
107 }
108 
109 
110 }
111 
112 #endif
OrbitOperator(const OrbitOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: OrbitOperator.h:36
void setCenter(const osg::Vec3 &c)
Set the center of orbit.
Definition: OrbitOperator.h:44
void setMagnitude(float mag)
Set the acceleration scale.
Definition: OrbitOperator.h:50
const osg::Vec3 & getPosition() const
Get the position vector.
Definition: Particle.h:417
ReferenceFrame getReferenceFrame() const
Get the reference frame.
META_Object(osgParticle, OrbitOperator)
float getEpsilon() const
Get the acceleration epsilon.
Definition: OrbitOperator.h:59
float getMagnitude() const
Get the acceleration scale.
Definition: OrbitOperator.h:53
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition: OrbitOperator.h:86
OrbitOperator & operator=(const OrbitOperator &)
Definition: OrbitOperator.h:75
void setMaxRadius(float max)
Set max radius between the center and the particle.
Definition: OrbitOperator.h:62
float getMaxRadius() const
Get max radius between the center and the particle.
Definition: OrbitOperator.h:65
const osg::Vec3 & getCenter() const
Get the center of orbit.
Definition: OrbitOperator.h:47
void setEpsilon(float eps)
Set the acceleration epsilon.
Definition: OrbitOperator.h:56
void addVelocity(const osg::Vec3 &dv)
Add a vector to the velocity vector.
Definition: Particle.h:507
void beginOperate(Program *prg)
Perform some initializations. Do not call this method manually.
Definition: OrbitOperator.h:97
value_type length() const
Definition: Vec3f.h:176
osg::Vec3 transformLocalToWorld(const osg::Vec3 &P)
Transform a point from local to world coordinates (valid only during cull traversal).