OpenSceneGraph 3.6.5
OrbitOperator
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
19#include <osgParticle/Operator>
20#include <osgParticle/Particle>
21
22namespace osgParticle
23{
24
25
29class OrbitOperator : public Operator
30{
31public:
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
73protected:
74 virtual ~OrbitOperator() {}
75 OrbitOperator& operator=( const OrbitOperator& ) { return *this; }
76
80 float _epsilon;
82};
83
84// INLINE METHODS
85
86inline 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
Vec3f Vec3
Definition Vec3:21
The osgParticle library is a NodeKit that extends the core scene graph to support particle effects.
Definition AccelOperator:27
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
value_type length() const
Length of the vector = sqrt( vec .
Definition Vec3f:176
Operator()
Definition Operator:92
void setMagnitude(float mag)
Set the acceleration scale.
Definition OrbitOperator:50
float _epsilon
Definition OrbitOperator:80
void beginOperate(Program *prg)
Perform some initializations. Do not call this method manually.
Definition OrbitOperator:97
OrbitOperator & operator=(const OrbitOperator &)
Definition OrbitOperator:75
float _maxRadius
Definition OrbitOperator:81
virtual ~OrbitOperator()
Definition OrbitOperator:74
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition OrbitOperator:86
osg::Vec3 _xf_center
Definition OrbitOperator:78
void setEpsilon(float eps)
Set the acceleration epsilon.
Definition OrbitOperator:56
const osg::Vec3 & getCenter() const
Get the center of orbit.
Definition OrbitOperator:47
float getMagnitude() const
Get the acceleration scale.
Definition OrbitOperator:53
OrbitOperator(const OrbitOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition OrbitOperator:36
void setMaxRadius(float max)
Set max radius between the center and the particle.
Definition OrbitOperator:62
osg::Vec3 _center
Definition OrbitOperator:77
float getEpsilon() const
Get the acceleration epsilon.
Definition OrbitOperator:59
META_Object(osgParticle, OrbitOperator)
OrbitOperator()
Definition OrbitOperator:32
float getMaxRadius() const
Get max radius between the center and the particle.
Definition OrbitOperator:65
void setCenter(const osg::Vec3 &c)
Set the center of orbit.
Definition OrbitOperator:44
float _magnitude
Definition OrbitOperator:79
Implementation of a particle.
Definition Particle:47
void addVelocity(const osg::Vec3 &dv)
Add a vector to the velocity vector.
Definition Particle:493
const osg::Vec3 & getPosition() const
Get the position vector.
Definition Particle:403
@ RELATIVE_RF
Definition ParticleProcessor:42
ReferenceFrame getReferenceFrame() const
Get the reference frame.
Definition ParticleProcessor:179
osg::Vec3 transformLocalToWorld(const osg::Vec3 &P)
Transform a point from local to world coordinates (valid only during cull traversal).
Definition ParticleProcessor:305
An abstract ParticleProcessor descendant for modifying particles "on the fly" during the cull travers...
Definition Program:36

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.