Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6822 in orxonox.OLD for trunk/src/lib/particles/particle_emitter.cc


Ignore:
Timestamp:
Jan 29, 2006, 1:57:03 AM (18 years ago)
Author:
bensch
Message:

trunk: ParticleEmitters now splitted into SubClasses.
Also fixed a little Boeg in the ClassID

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/particle_emitter.cc

    r6627 r6822  
    2121
    2222#include "load_param.h"
    23 #include "factory.h"
    2423#include "debug.h"
    2524#include "stdlibincl.h"
     
    2726using namespace std;
    2827
    29 
    30 CREATE_FACTORY(ParticleEmitter, CL_PARTICLE_EMITTER);
    31 
    3228/**
    3329 *  standard constructor
     
    3632                  float velocity)
    3733{
    38   this->init();
    39 
     34  this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter");
     35
     36  this->system = NULL;
     37
     38  this->setInheritSpeed(PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED);
     39  this->setEmissionMomentum(0);
    4040  this->direction = direction;
    4141  this->setSpread(angle);
    4242  this->setEmissionRate(emissionRate);
    4343  this->setEmissionVelocity(velocity);
    44 }
    45 
    46 /**
    47  *  constructs and loads a ParticleEmitter from a XML-element
    48  * @param root the XML-element to load from
    49 */
    50 ParticleEmitter::ParticleEmitter(const TiXmlElement* root)
    51 {
    52   this->init();
    53 
    54    if (root != NULL)
    55      this->loadParams(root);
     44
     45  this->saveTime = 0.0;
    5646}
    5747
     
    6454{
    6555  this->setSystem(NULL);
    66 }
    67 
    68 /**
    69   @brief initializes default values of a ParitcleEmitter
    70 */
    71 void ParticleEmitter::init()
    72 {
    73   this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter");
    74 
    75   this->type = PARTICLE_EMITTER_DEFAULT_TYPE;
    76   this->emitterSize = PARTICLE_EMITTER_DEFAULT_SIZE;
    77   this->setInheritSpeed(PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED);
    78   this->setEmissionRate(PARTICLE_EMITTER_DEFAULT_EMISSION_RATE);
    79   this->setSize(PARTICLE_EMITTER_DEFAULT_SIZE);
    80   this->setEmissionMomentum(0);
    81   this->setEmissionVelocity(1.0);
    82   this->setSpread(M_PI);
    83 
    84   this->system = NULL;
    85 
    86   this->saveTime = 0.0;
    8756}
    8857
     
    9463{
    9564  PNode::loadParams(root);
    96 
    97   LoadParam(root, "type", this, ParticleEmitter, setType)
    98     .describe("What type of emitter is this [dot, plane, cube, sphere].");
    99 
    100   LoadParam(root, "size", this, ParticleEmitter, setSize)
    101     .describe("How big the emitter is (no effect on dot-emitters)");
    10265
    10366  LoadParam(root, "rate", this, ParticleEmitter, setEmissionRate)
     
    139102void ParticleEmitter::stop() {}
    140103
    141 
    142 
    143 
    144 
    145 /**
    146  * @param type the new Type of this emitter
    147 */
    148 void ParticleEmitter::setType(EMITTER_TYPE type)
    149 {
    150   this->type = type;
    151 }
    152 
    153 /**
    154  *  sets the type of emitter
    155  * @param type the type as a const char*
    156    dot: EMITTER_DOT, plane: EMITTER_PLANE, cube: EMITTER_CUBE, sphere, EMITTER_SPHERE;
    157 */
    158 void ParticleEmitter::setType(const char* type)
    159 {
    160   if (!strcmp(type, "plane"))
    161     this->setType(EMITTER_PLANE);
    162   else if (!strcmp(type, "cube"))
    163     this->setType(EMITTER_CUBE);
    164   else if (!strcmp(type, "sphere"))
    165     this->setType(EMITTER_SPHERE);
    166   else
    167     this->setType(EMITTER_DOT);
    168 }
    169 
    170 const char* ParticleEmitter::getTypeC() const
    171 {
    172   if (this->type == EMITTER_PLANE)
    173     return "EMITTER_PLANE";
    174   else if (this->type == EMITTER_CUBE)
    175     return "EMITTER_CUBE";
    176   else if (this->type == EMITTER_SPHERE)
    177     return "EMITTER_SPHERE";
    178   else
    179     return "EMITTER_DOT";
    180 }
    181 
    182 /**
    183  *  sets a new size to the emitter
    184 */
    185 void ParticleEmitter::setSize(float emitterSize)
    186 {
    187   if (emitterSize > 0.0)
    188     this->emitterSize = emitterSize;
    189   else
    190     emitterSize = 0.0;
    191 }
    192104
    193105/**
     
    280192    PRINTF(5)("emitting %f particles, saving %f seconds for the next timestep\n", count, this->saveTime);
    281193
    282     if (likely(count > 0))
     194    if (likely(count > 0.0f))
    283195    {
    284       Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
     196      this->emitParticles((unsigned int)count);
     197
     198/*      Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
    285199      for (int i = 0; i < (int)count; i++)
    286200      {
     
    294208        Vector extension; // the Vector for different fields.
    295209
    296         if (this->type & EMITTER_PLANE)
    297         {
    298           extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5));
    299           extension = this->getAbsDir().apply(extension);
    300         }
    301         else if (this->type & EMITTER_CUBE)
    302         {
    303           extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize;
    304         }
     210//         if (this->type & EMITTER_PLANE)
     211//         {
     212//           extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5));
     213//           extension = this->getAbsDir().apply(extension);
     214//         }
     215//         else if (this->type & EMITTER_CUBE)
     216//         {
     217//           extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize;
     218//         }
    305219
    306220
     
    312226
    313227        this->system->addParticle(this->getAbsCoor() + extension - equalSpread, velocityV, orient, moment);
    314       }
     228      } */
    315229    }
    316230  }
     
    322236void ParticleEmitter::debug() const
    323237{
    324   PRINT(0)(" Emitter %s\n", this->getName());
     238  PRINT(0)(" ParticleEmitter %s::%s\n", this->getClassName(), this->getName());
    325239  PRINT(0)("  EmissionRate: %f, Speed: %f, SpreadAngle: %f\n", this->getEmissionRate(), this->getEmissionVelocity(), this->getSpread());
    326   PRINT(0)("  Size %f, Type: %s\n", this->getSize(), this->getTypeC());
    327 }
     240}
Note: See TracChangeset for help on using the changeset viewer.