OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SinkOperator.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_SINKOPERATOR
16 #define OSGPARTICLE_SINKOPERATOR
17 
18 #include <osgParticle/Particle>
19 #include <osgParticle/DomainOperator>
20 
21 namespace osgParticle
22 {
23 
24 
29 {
30 public:
31  enum SinkTarget { SINK_POSITION, SINK_VELOCITY, SINK_ANGULAR_VELOCITY };
32  enum SinkStrategy { SINK_INSIDE, SINK_OUTSIDE };
33 
35  : DomainOperator(), _sinkTarget(SINK_POSITION), _sinkStrategy(SINK_INSIDE)
36  {}
37 
39  : DomainOperator(copy, copyop), _sinkTarget(copy._sinkTarget), _sinkStrategy(copy._sinkStrategy)
40  {}
41 
43 
45  void setSinkTarget( SinkTarget so ) { _sinkTarget = so; }
46 
48  SinkTarget getSinkTarget() const { return _sinkTarget; }
49 
51  void setSinkStrategy( SinkStrategy ss ) { _sinkStrategy = ss; }
52 
54  SinkStrategy getSinkStrategy() const { return _sinkStrategy; }
55 
57  void beginOperate( Program* prg );
58 
59 protected:
60  virtual ~SinkOperator() {}
61  SinkOperator& operator=( const SinkOperator& ) { return *this; }
62 
63  virtual void handlePoint( const Domain& domain, Particle* P, double dt );
64  virtual void handleLineSegment( const Domain& domain, Particle* P, double dt );
65  virtual void handleTriangle( const Domain& domain, Particle* P, double dt );
66  virtual void handleRectangle( const Domain& domain, Particle* P, double dt );
67  virtual void handlePlane( const Domain& domain, Particle* P, double dt );
68  virtual void handleSphere( const Domain& domain, Particle* P, double dt );
69  virtual void handleBox( const Domain& domain, Particle* P, double dt );
70  virtual void handleDisk( const Domain& domain, Particle* P, double dt );
71 
72  inline const osg::Vec3& getValue( Particle* P );
73  inline void kill( Particle* P, bool insideDomain );
74 
77 };
78 
79 // INLINE METHODS
80 
82 {
83  switch ( _sinkTarget )
84  {
85  case SINK_VELOCITY: return P->getVelocity();
86  case SINK_ANGULAR_VELOCITY: return P->getAngularVelocity();
87  case SINK_POSITION: default: return P->getPosition();
88  }
89 }
90 
91 inline void SinkOperator::kill( Particle* P, bool insideDomain )
92 {
93  if ( !((_sinkStrategy==SINK_INSIDE) ^ insideDomain) )
94  P->kill();
95 }
96 
97 
98 }
99 
100 #endif
const osg::Vec3 & getValue(Particle *P)
Definition: SinkOperator.h:81
const osg::Vec3 & getAngularVelocity() const
Get the rotational velocity vector.
Definition: Particle.h:437
SinkStrategy getSinkStrategy() const
Get the sink strategy.
Definition: SinkOperator.h:54
#define OSGPARTICLE_EXPORT
Definition: Export.h:40
const osg::Vec3 & getPosition() const
Get the position vector.
Definition: Particle.h:417
SinkStrategy _sinkStrategy
Definition: SinkOperator.h:76
#define META_Object(library, name)
Definition: Object.h:42
void setSinkStrategy(SinkStrategy ss)
Set the sink strategy.
Definition: SinkOperator.h:51
void kill(Particle *P, bool insideDomain)
Definition: SinkOperator.h:91
SinkOperator(const SinkOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: SinkOperator.h:38
void setSinkTarget(SinkTarget so)
Set the sink strategy.
Definition: SinkOperator.h:45
SinkOperator & operator=(const SinkOperator &)
Definition: SinkOperator.h:61
const osg::Vec3 & getVelocity() const
Definition: Particle.h:422
SinkTarget getSinkTarget() const
Get the sink strategy.
Definition: SinkOperator.h:48