OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticleProcessor.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_PARTICLEPROCESSOR
16 #define OSGPARTICLE_PARTICLEPROCESSOR 1
17 
18 #include <osgParticle/Export>
19 #include <osgParticle/ParticleSystem>
20 
21 #include <osg/ref_ptr>
22 #include <osg/Object>
23 #include <osg/Transform>
24 #include <osg/NodeVisitor>
25 #include <osg/CopyOp>
26 #include <osg/Vec3>
27 #include <osg/Matrix>
28 
29 namespace osgParticle
30 {
31 
39  public:
40 
43  ABSOLUTE_RF
44  };
45 
48 
49  virtual const char* libraryName() const { return "osgParticle"; }
50  virtual const char* className() const { return "ParticleProcessor"; }
51  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ParticleProcessor*>(obj) != 0; }
52  virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
53 
55  inline ReferenceFrame getReferenceFrame() const;
56 
58  inline void setReferenceFrame(ReferenceFrame rf);
59 
61  bool getEnabled() const { return _enabled; }
62  inline bool isEnabled() const;
63 
65  inline void setEnabled(bool v);
66 
68  inline ParticleSystem* getParticleSystem();
69 
71  inline const ParticleSystem* getParticleSystem() const;
72 
74  inline void setParticleSystem(ParticleSystem* ps);
75 
77  inline void setEndless(bool type);
78 
80  bool getEndless() const { return _endless; }
81  inline bool isEndless() const;
82 
84  inline void setLifeTime(double t);
85 
87  inline double getLifeTime() const;
88 
90  inline void setStartTime(double t);
91 
93  inline double getStartTime() const;
94 
96  inline void setCurrentTime(double t);
97 
99  inline double getCurrentTime() const;
100 
102  inline void setResetTime(double t);
103 
105  inline double getResetTime() const;
106 
114  inline bool isAlive() const;
115 
116  void traverse(osg::NodeVisitor& nv);
117 
119  inline const osg::Matrix& getLocalToWorldMatrix();
120 
122  inline const osg::Matrix& getWorldToLocalMatrix();
123 
125  inline const osg::Matrix& getPreviousLocalToWorldMatrix();
126 
128  inline const osg::Matrix& getPreviousWorldToLocalMatrix();
129 
130 
132  inline osg::Vec3 transformLocalToWorld(const osg::Vec3& P);
133 
135  inline osg::Vec3 rotateLocalToWorld(const osg::Vec3& P);
136 
138  inline osg::Vec3 transformWorldToLocal(const osg::Vec3& P);
139 
141  inline osg::Vec3 rotateWorldToLocal(const osg::Vec3& P);
142 
143  virtual osg::BoundingSphere computeBound() const;
144 
145  protected:
146  virtual ~ParticleProcessor() {}
147  ParticleProcessor& operator=(const ParticleProcessor&) { return *this; }
148 
149  virtual void process(double dt) = 0;
150 
151  private:
152  ReferenceFrame _rf;
153  bool _enabled;
154  double _t0;
156  bool _first_ltw_compute;
157  bool _need_ltw_matrix;
158  bool _first_wtl_compute;
159  bool _need_wtl_matrix;
160  osg::Matrix _ltw_matrix;
161  osg::Matrix _wtl_matrix;
162  osg::Matrix _previous_ltw_matrix;
163  osg::Matrix _previous_wtl_matrix;
164  osg::NodeVisitor* _current_nodevisitor;
165 
166  bool _endless;
167 
168  double _lifeTime;
169  double _startTime;
170  double _currentTime;
171  double _resetTime;
172 
173  //added- 1/17/06- bgandere@nps.edu
174  //a var to keep from doing multiple updates
175  unsigned int _frameNumber;
176  };
177 
178  // INLINE FUNCTIONS
179 
181  {
182  return _rf;
183  }
184 
186  {
187  _rf = rf;
188  }
189 
190  inline bool ParticleProcessor::isEnabled() const
191  {
192  return _enabled;
193  }
194 
195  inline void ParticleProcessor::setEnabled(bool v)
196  {
197  _enabled = v;
198  if (_enabled)
199  {
200  _currentTime = 0;
201  }
202  }
203 
205  {
206  return _ps.get();
207  }
208 
210  {
211  return _ps.get();
212  }
213 
215  {
216  _ps = ps;
217  }
218 
220  {
221  _endless = type;
222  }
223 
224  inline bool ParticleProcessor::isEndless() const
225  {
226  return _endless;
227  }
228 
229  inline void ParticleProcessor::setLifeTime(double t)
230  {
231  _lifeTime = t;
232  }
233 
234  inline double ParticleProcessor::getLifeTime() const
235  {
236  return _lifeTime;
237  }
238 
239  inline void ParticleProcessor::setStartTime(double t)
240  {
241  _startTime = t;
242  }
243 
244  inline double ParticleProcessor::getStartTime() const
245  {
246  return _startTime;
247  }
248  inline void ParticleProcessor::setCurrentTime(double t)
249  {
250  _currentTime = t;
251  }
252 
253  inline double ParticleProcessor::getCurrentTime() const
254  {
255  return _currentTime;
256  }
257 
258  inline void ParticleProcessor::setResetTime(double t)
259  {
260  _resetTime = t;
261  }
262 
263  inline double ParticleProcessor::getResetTime() const
264  {
265  return _resetTime;
266  }
267 
269  {
270  if (_need_ltw_matrix) {
271  _previous_ltw_matrix = _ltw_matrix;
272  _ltw_matrix = osg::computeLocalToWorld(_current_nodevisitor->getNodePath());
273  if (_first_ltw_compute)
274  {
275  _previous_ltw_matrix = _ltw_matrix;
276  _first_ltw_compute = false;
277  }
278  _need_ltw_matrix = false;
279  }
280  return _ltw_matrix;
281  }
282 
284  {
285  if (_need_wtl_matrix) {
286  _previous_wtl_matrix = _wtl_matrix;
287  _wtl_matrix = osg::computeWorldToLocal(_current_nodevisitor->getNodePath());
288  if (_first_wtl_compute)
289  {
290  _previous_wtl_matrix = _wtl_matrix;
291  _first_wtl_compute = false;
292  }
293  _need_wtl_matrix = false;
294  }
295  return _wtl_matrix;
296  }
297 
299  {
300  if (_need_ltw_matrix) getLocalToWorldMatrix();
301  return _previous_ltw_matrix;
302  }
303 
305  {
306  if (_need_wtl_matrix) getWorldToLocalMatrix();
307  return _previous_wtl_matrix;
308  }
309 
311  {
312  return getLocalToWorldMatrix().preMult(P);
313  }
314 
316  {
317  return getWorldToLocalMatrix().preMult(P);
318  }
319 
321  {
322  return getLocalToWorldMatrix().preMult(P) -
324  }
325 
327  {
328  return getWorldToLocalMatrix().preMult(P) -
330  }
331 
332  inline bool ParticleProcessor::isAlive() const
333  {
334  return _currentTime < (_lifeTime + _startTime);
335  }
336 
337 }
338 
339 
340 #endif
void setResetTime(double t)
Set the reset time of this processor. A value of 0 disables reset.
virtual void accept(osg::NodeVisitor &nv)
const osg::Matrix & getPreviousWorldToLocalMatrix()
Get the previous world-to-local transformation matrix (valid only during cull traversal).
ParticleProcessor & operator=(const ParticleProcessor &)
OSG_EXPORT Matrix computeWorldToLocal(const NodePath &nodePath, bool ignoreCameras=true)
void popFromNodePath()
Definition: NodeVisitor.h:204
void setLifeTime(double t)
Set the lifetime of this processor.
bool validNodeMask(const osg::Node &node) const
Definition: NodeVisitor.h:166
ParticleSystem * getParticleSystem()
Get a pointer to the destination particle system.
const osg::Matrix & getWorldToLocalMatrix()
Get the current world-to-local transformation matrix (valid only during cull traversal).
const osg::Matrix & getPreviousLocalToWorldMatrix()
Get the previous local-to-world transformation matrix (valid only during cull traversal).
osg::Vec3 transformWorldToLocal(const osg::Vec3 &P)
Transform a point from world to local coordinates (valid only during cull traversal).
void setReferenceFrame(ReferenceFrame rf)
Set the reference frame.
virtual bool isSameKindAs(const osg::Object *obj) const
void setStartTime(double t)
Set the start time of this processor.
osg::Vec3 rotateLocalToWorld(const osg::Vec3 &P)
Transform a vector from local to world coordinates, discarding translation (valid only during cull tr...
virtual const char * className() const
osg::Vec3 rotateWorldToLocal(const osg::Vec3 &P)
Transform a vector from world to local coordinates, discarding translation (valid only during cull tr...
#define OSGPARTICLE_EXPORT
Definition: Export.h:40
ReferenceFrame getReferenceFrame() const
Get the reference frame.
virtual void apply(Drawable &drawable)
NodePath & getNodePath()
Definition: NodeVisitor.h:208
void setEnabled(bool v)
Set whether this processor is enabled or not.
double getLifeTime() const
Get the lifetime of this processor.
double getCurrentTime() const
Get the current time of this processor.
const osg::Matrix & getLocalToWorldMatrix()
Get the current local-to-world transformation matrix (valid only during cull traversal).
OSG_EXPORT Matrix computeLocalToWorld(const NodePath &nodePath, bool ignoreCameras=true)
Vec3f preMult(const Vec3f &v) const
Definition: Matrixd.h:612
bool getEnabled() const
Get whether this processor is enabled or not.
void pushOntoNodePath(Node *node)
Definition: NodeVisitor.h:198
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: GLU.h:71
void setEndless(bool type)
Set the endless flag of this processor.
bool getEndless() const
Check whether this processor is endless.
double getResetTime() const
Get the reset time of this processor.
Definition: Node.h:71
virtual const char * libraryName() const
osg::Vec3 transformLocalToWorld(const osg::Vec3 &P)
Transform a point from local to world coordinates (valid only during cull traversal).
double getStartTime() const
Get the start time of this processor.
void setCurrentTime(double t)
Set the current time of this processor.
void setParticleSystem(ParticleSystem *ps)
Set the destination particle system.