RigsofRods
Soft-body Physics Simulation
FireExtinguisherAffector.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5 
6  For more information, see http://www.rigsofrods.org/
7 
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifdef USE_ANGELSCRIPT
22 
24 
25 #include "Application.h"
26 
27 #include <OgreParticleSystem.h>
28 #include <OgreParticle.h>
29 #include <OgreStringConverter.h>
30 #include <OgreParticleSystemManager.h>
31 #include <OgreParticle.h>
32 
34 
35 
36 namespace Ogre {
37 
38 // Instantiate statics
39 FireExtinguisherAffector::CmdEffectiveness FireExtinguisherAffector::msEffectivenessCmd;
40 
41 //-----------------------------------------------------------------------
43  : ParticleAffector(psys)
44 {
45  mType = "FireExtinguisher";
46 
47  // defaults
48  mEffectiveness = 1.0;
49  mEfaf = 0;
50 
51  // Set up parameters
52  if (createParamDictionary("FireExtinguisherAffector"))
53  {
54  addBaseParameters();
55  // Add extra paramaters
56  ParamDictionary* dict = getParamDictionary();
57  dict->addParameter(ParameterDef("effectiveness",
58  "How effective is your fire extinguisher? Anything higher than one is more effective than water while everything lower than one is less effective than water.",
59  PT_REAL), &msEffectivenessCmd);
60  }
61 
62  // get fire affector factory
63  ParticleSystemManager::ParticleAffectorFactoryIterator pafi = ParticleSystemManager::getSingleton().getAffectorFactoryIterator();
64  ParticleAffectorFactory *paf;
65 
66  while(pafi.hasMoreElements())
67  {
68  paf = pafi.getNext();
69  if ( paf->getName() == "ExtinguishableFire" )
70  {
72  break;
73  }
74  }
75  if (!mEfaf) LOG("ERROR: Couldn't find an ExtinguishableFireAffectorFactory instance. Was it registered in the content manager?");
76 }
77 //-----------------------------------------------------------------------
78 void FireExtinguisherAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
79 {
82 
83  while(affIt.hasMoreElements())
84  {
85  fire = (ExtinguishableFireAffector*)affIt.getNext();
86 
87  if (fire->isTemplate())
88  continue;
89 
90  Real squaredRadius = Math::Pow(fire->getRadius(), 2);
91  Vector3 middlePoint = fire->getAbsoluteMiddlePoint();
92 
93  ParticleIterator pi = pSystem->_getIterator();
94  Particle *p;
95  int fireHits = 0;
96  while (!pi.end())
97  {
98  p = pi.getNext();
99 
100  if ( middlePoint.squaredDistance(p->mPosition) < squaredRadius )
101  {
102  // This particle is inside the fire, dispose of it in the next update
103  p->mTimeToLive = 0;
104  ++fireHits;
105  }
106  }
107  if (fireHits>0)
108  {
109  Real intensity = fire->reduceIntensity(fireHits*mEffectiveness);
110  if (intensity<0) delete fire->getParticleSystem();
111  }
112  }
113 }
114 //-----------------------------------------------------------------------
116 {
117  mEffectiveness = effectiveness;
118 }
119 //-----------------------------------------------------------------------
121 {
122  return mEffectiveness;
123 }
124 
125 //-----------------------------------------------------------------------
126 //-----------------------------------------------------------------------
127 // Command objects
128 //-----------------------------------------------------------------------
129 //-----------------------------------------------------------------------
131 {
132  return StringConverter::toString(
133  static_cast<const FireExtinguisherAffector*>(target)->getEffectiveness() );
134 
135 }
136 void FireExtinguisherAffector::CmdEffectiveness::doSet(void* target, const String& val)
137 {
138  static_cast<FireExtinguisherAffector*>(target)->setEffectiveness(
139  StringConverter::parseReal(val));
140 }
141 
142 } // namespace Ogre
143 
144 
145 #endif //USE_ANGELSCRIPT
146 
Ogre::FireExtinguisherAffector::getEffectiveness
Real getEffectiveness(void) const
Gets the bounce value of the deflection.
Definition: FireExtinguisherAffector.cpp:120
Ogre::FireExtinguisherAffector::mEffectiveness
Real mEffectiveness
effectiveness factor (1 means as effective as water, everything higher is more effective while anythi...
Definition: FireExtinguisherAffector.h:77
Ogre::ExtinguishableFireAffectorFactory::affectorIterator
VectorIterator< vector< ParticleAffector * >::type > affectorIterator
Definition: ExtinguishableFireAffectorFactory.h:52
Ogre::ExtinguishableFireAffectorFactory::getAffectorIterator
affectorIterator getAffectorIterator()
Allow external access to the mFactories iterator.
Definition: ExtinguishableFireAffectorFactory.h:55
Ogre::ExtinguishableFireAffector::getRadius
Real getRadius(void) const
Gets the radius for the interaction with the FireExtiniguisher affector.
Definition: ExtinguishableFireAffector.cpp:179
Ogre::FireExtinguisherAffector::mEfaf
ExtinguishableFireAffectorFactory * mEfaf
Definition: FireExtinguisherAffector.h:74
Ogre::ExtinguishableFireAffector::getAbsoluteMiddlePoint
Vector3 getAbsoluteMiddlePoint(void) const
Definition: ExtinguishableFireAffector.cpp:157
Ogre::FireExtinguisherAffector::FireExtinguisherAffector
FireExtinguisherAffector(ParticleSystem *psys)
Default constructor.
Definition: FireExtinguisherAffector.cpp:42
Ogre::FireExtinguisherAffector
This class defines a ParticleAffector which deflects particles.
Definition: FireExtinguisherAffector.h:46
Ogre::FireExtinguisherAffector::setEffectiveness
void setEffectiveness(Real effectiveness)
Sets the bounce value of the deflection.
Definition: FireExtinguisherAffector.cpp:115
Ogre::FireExtinguisherAffector::_affectParticles
void _affectParticles(ParticleSystem *pSystem, Real timeElapsed)
See ParticleAffector.
Definition: FireExtinguisherAffector.cpp:78
Ogre::ExtinguishableFireAffector::reduceIntensity
Real reduceIntensity(Real amount)
Definition: ExtinguishableFireAffector.cpp:252
Ogre::ExtinguishableFireAffector::getParticleSystem
ParticleSystem * getParticleSystem()
Definition: ExtinguishableFireAffector.h:130
Application.h
Central state/object manager and communications hub.
Ogre::FireExtinguisherAffector::CmdEffectiveness::doGet
String doGet(const void *target) const
Definition: FireExtinguisherAffector.cpp:130
Ogre::ExtinguishableFireAffector
This class defines a ParticleAffector which deflects particles.
Definition: ExtinguishableFireAffector.h:45
Ogre::ExtinguishableFireAffector::isTemplate
bool isTemplate() const
Definition: ExtinguishableFireAffector.cpp:248
ExtinguishableFireAffectorFactory.h
Ogre::ExtinguishableFireAffectorFactory
Factory class for DeflectorPlaneAffector.
Definition: ExtinguishableFireAffectorFactory.h:37
Ogre::FireExtinguisherAffector::msEffectivenessCmd
static CmdEffectiveness msEffectivenessCmd
Command objects.
Definition: FireExtinguisherAffector.h:70
Ogre
Definition: ExtinguishableFireAffector.cpp:35
FireExtinguisherAffector.h
Ogre::FireExtinguisherAffector::CmdEffectiveness::doSet
void doSet(void *target, const String &val)
Definition: FireExtinguisherAffector.cpp:136