OpenSceneGraph 3.6.5
ExplosionOperator
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_EXPLOSIONOPERATOR
16#define OSGPARTICLE_EXPLOSIONOPERATOR
17
19#include <osgParticle/Operator>
20#include <osgParticle/Particle>
21
22namespace osgParticle
23{
24
25
30{
31public:
33 : Operator(), _radius(1.0f),
34 _magnitude(1.0f), _epsilon(1e-3), _sigma(1.0f),
35 _inexp(0.0f), _outexp(0.0f)
36 {}
37
39 : Operator(copy, copyop), _center(copy._center), _radius(copy._radius),
41 _inexp(copy._inexp), _outexp(copy._outexp)
42 {}
43
45
47 void setCenter( const osg::Vec3& c ) { _center = c; }
48
50 const osg::Vec3& getCenter() const { return _center; }
51
53 void setRadius( float r ) { _radius = r; }
54
56 float getRadius() const { return _radius; }
57
59 void setMagnitude( float mag ) { _magnitude = mag; }
60
62 float getMagnitude() const { return _magnitude; }
63
65 void setEpsilon( float eps ) { _epsilon = eps; }
66
68 float getEpsilon() const { return _epsilon; }
69
71 void setSigma( float s ) { _sigma = s; }
72
74 float getSigma() const { return _sigma; }
75
77 inline void operate( Particle* P, double dt );
78
80 inline void beginOperate( Program* prg );
81
82protected:
83 virtual ~ExplosionOperator() {}
84 ExplosionOperator& operator=( const ExplosionOperator& ) { return *this; }
85
88 float _radius;
90 float _epsilon;
91 float _sigma;
92 float _inexp;
93 float _outexp;
94};
95
96// INLINE METHODS
97
98inline void ExplosionOperator::operate( Particle* P, double dt )
99{
100 osg::Vec3 dir = P->getPosition() - _xf_center;
101 float length = dir.length();
102 float distanceFromWave2 = (_radius - length) * (_radius - length);
103 float Gd = exp(distanceFromWave2 * _inexp) * _outexp;
104 float factor = (_magnitude * dt) / (length * (_epsilon+length*length));
105 P->addVelocity( dir * (Gd * factor) );
106}
107
109{
111 {
113 }
114 else
115 {
117 }
118
119 float oneOverSigma = (_sigma!=0.0f ? (1.0f / _sigma) : 1.0f);
120 _inexp = -0.5f * oneOverSigma * oneOverSigma;
121 _outexp = oneOverSigma / sqrt(osg::PI * 2.0f);
122}
123
124
125}
126
127#endif
Vec3f Vec3
Definition Vec3:21
const double PI
Definition Math:30
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
void setEpsilon(float eps)
Set the acceleration epsilon.
Definition ExplosionOperator:65
osg::Vec3 _xf_center
Definition ExplosionOperator:87
osg::Vec3 _center
Definition ExplosionOperator:86
void beginOperate(Program *prg)
Perform some initializations. Do not call this method manually.
Definition ExplosionOperator:108
float _radius
Definition ExplosionOperator:88
void setCenter(const osg::Vec3 &c)
Set the center of shock wave.
Definition ExplosionOperator:47
void setMagnitude(float mag)
Set the acceleration scale.
Definition ExplosionOperator:59
float _inexp
Definition ExplosionOperator:92
float _magnitude
Definition ExplosionOperator:89
const osg::Vec3 & getCenter() const
Get the center of shock wave.
Definition ExplosionOperator:50
virtual ~ExplosionOperator()
Definition ExplosionOperator:83
void setRadius(float r)
Set the radius of wave peak.
Definition ExplosionOperator:53
ExplosionOperator()
Definition ExplosionOperator:32
META_Object(osgParticle, ExplosionOperator)
void setSigma(float s)
Set broadness of the strength of the wave.
Definition ExplosionOperator:71
float _outexp
Definition ExplosionOperator:93
float getSigma() const
Get broadness of the strength of the wave.
Definition ExplosionOperator:74
float getRadius() const
Get the radius of wave peak.
Definition ExplosionOperator:56
float _sigma
Definition ExplosionOperator:91
ExplosionOperator & operator=(const ExplosionOperator &)
Definition ExplosionOperator:84
ExplosionOperator(const ExplosionOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition ExplosionOperator:38
float getEpsilon() const
Get the acceleration epsilon.
Definition ExplosionOperator:68
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition ExplosionOperator:98
float getMagnitude() const
Get the acceleration scale.
Definition ExplosionOperator:62
float _epsilon
Definition ExplosionOperator:90
Operator()
Definition Operator:92
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 Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.