00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023 #ifndef H_SPK_EMITTER
00024 #define H_SPK_EMITTER
00025
00026 #include "Core/SPK_DEF.h"
00027 #include "Core/SPK_Registerable.h"
00028 #include "Core/SPK_Transformable.h"
00029 #include "Core/SPK_Zone.h"
00030 #include "Core/SPK_Particle.h"
00031
00032
00033 namespace SPK
00034 {
00035 class Group;
00036 class Particle;
00037
00038
00053 class SPK_PREFIX Emitter : public Registerable, public Transformable
00054 {
00055 friend class Group;
00056
00057 public :
00058
00060
00062
00064 Emitter();
00065
00067
00069
00071 virtual ~Emitter() {}
00072
00074
00076
00086 void setActive(bool active);
00087
00098 void setTank(int tank);
00099
00108 void changeTank(int deltaTank);
00109
00119 void setFlow(float flow);
00120
00129 void changeFlow(float deltaFlow);
00130
00142 void setForce(float min,float max);
00143
00152 void setZone(Zone* zone,bool full = true);
00153
00155
00157
00163 bool isActive() const;
00164
00169 int getTank() const;
00170
00175 float getFlow() const;
00176
00181 float getForceMin() const;
00182
00187 float getForceMax() const;
00188
00193 Zone* getZone() const;
00194
00199 bool isFullZone() const;
00200
00209 bool isSleeping() const;
00210
00212
00214
00226 void emit(Particle& particle) const;
00227
00236 void generateVelocity(Particle& particle) const;
00237
00238 virtual Registerable* findByName(const std::string& name);
00239
00240 protected :
00241
00242 virtual void registerChildren(bool registerAll);
00243 virtual void copyChildren(const Registerable& object,bool createBase);
00244 virtual void destroyChildren(bool keepChildren);
00245
00246 virtual void propagateUpdateTransform();
00247
00248 private :
00249
00250 Zone* zone;
00251 bool full;
00252
00253 bool active;
00254
00255 int tank;
00256 float flow;
00257
00258 float forceMin;
00259 float forceMax;
00260
00261 mutable float fraction;
00262
00263 static Zone& getDefaultZone();
00264
00265 unsigned int updateNumber(float deltaTime);
00266
00268
00270
00282 virtual void generateVelocity(Particle& particle,float speed) const = 0;
00283 };
00284
00285
00286 inline void Emitter::setActive(bool active)
00287 {
00288 this->active = active;
00289 }
00290
00291 inline void Emitter::setTank(int tank)
00292 {
00293 this->tank = tank;
00294 }
00295
00296 inline void Emitter::setFlow(float flow)
00297 {
00298 this->flow = flow;
00299 }
00300
00301 inline void Emitter::setForce(float min,float max)
00302 {
00303 forceMin = min;
00304 forceMax = max;
00305 }
00306
00307 inline bool Emitter::isActive() const
00308 {
00309 return active;
00310 }
00311
00312 inline int Emitter::getTank() const
00313 {
00314 return tank;
00315 }
00316
00317 inline float Emitter::getFlow() const
00318 {
00319 return flow;
00320 }
00321
00322 inline float Emitter::getForceMin() const
00323 {
00324 return forceMin;
00325 }
00326
00327 inline float Emitter::getForceMax() const
00328 {
00329 return forceMax;
00330 }
00331
00332 inline Zone* Emitter::getZone() const
00333 {
00334 return zone;
00335 }
00336
00337 inline bool Emitter::isFullZone() const
00338 {
00339 return full;
00340 }
00341
00342 inline bool Emitter::isSleeping() const
00343 {
00344 return ((tank == 0)||(flow == 0.0f));
00345 }
00346
00347 inline void Emitter::emit(Particle& particle) const
00348 {
00349 zone->generatePosition(particle,full);
00350 generateVelocity(particle);
00351 }
00352
00353 inline void Emitter::generateVelocity(Particle& particle) const
00354 {
00355 generateVelocity(particle,random(forceMin,forceMax) / particle.getParamCurrentValue(PARAM_MASS));
00356 }
00357
00358 inline void Emitter::propagateUpdateTransform()
00359 {
00360 zone->updateTransform(this);
00361 }
00362 }
00363
00364 #endif