Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6823 in orxonox.OLD for trunk/src/lib/particles


Ignore:
Timestamp:
Jan 29, 2006, 2:20:46 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: BoxEmitter

Location:
trunk/src/lib/particles
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/Makefile.am

    r6822 r6823  
    77                        particle_emitter.cc \
    88                        dot_emitter.cc \
     9                        box_emitter.cc \
    910                        \
    1011                        particle_system.cc \
     
    2021                        particle_emitter.h \
    2122                        dot_emitter.h \
     23                        box_emitter.h \
    2224                        \
    2325                        particle_system.h \
  • trunk/src/lib/particles/box_emitter.cc

    r6822 r6823  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1717
    18 #include "dot_emitter.h"
     18#include "box_emitter.h"
    1919
    2020#include "particle_system.h"
     
    2828
    2929
    30 CREATE_FACTORY(DotEmitter, CL_DOT_EMITTER);
     30CREATE_FACTORY(BoxEmitter, CL_BOX_EMITTER);
    3131
    3232/**
    3333 *  standard constructor
    3434*/
    35 DotEmitter::DotEmitter(const Vector& direction, float angle, float emissionRate,
    36                        float velocity)
    37   : ParticleEmitter(direction, angle, emissionRate, velocity)
     35BoxEmitter::BoxEmitter(const Vector& size)
    3836{
    3937  this->init();
     38  this->setSize(size);
    4039}
    4140
    4241/**
    43  *  constructs and loads a DotEmitter from a XML-element
     42 *  constructs and loads a BoxEmitter from a XML-element
    4443 * @param root the XML-element to load from
    4544*/
    46 DotEmitter::DotEmitter(const TiXmlElement* root)
    47   : ParticleEmitter()
     45BoxEmitter::BoxEmitter(const TiXmlElement* root)
     46    : ParticleEmitter()
    4847{
    4948  this->init();
    5049
    51    if (root != NULL)
    52      this->loadParams(root);
     50  if (root != NULL)
     51    this->loadParams(root);
    5352}
    5453
     
    5857   removes the EmitterSystem from the ParticleEngine
    5958*/
    60 DotEmitter::~DotEmitter ()
     59BoxEmitter::~BoxEmitter ()
    6160{
    6261  this->setSystem(NULL);
     
    6665  @brief initializes default values of a ParitcleEmitter
    6766*/
    68 void DotEmitter::init()
     67void BoxEmitter::init()
    6968{
    70   this->setClassID(CL_DOT_EMITTER, "DotEmitter");
     69  this->setClassID(CL_BOX_EMITTER, "BoxEmitter");
     70  this->setSize(1.0f,1.0f,1.0f);
    7171}
    7272
    73 void DotEmitter::emitParticles(unsigned int count) const
     73void BoxEmitter::loadParams(const TiXmlElement* root)
     74{
     75  ParticleEmitter::loadParams(root);
     76
     77  LoadParam(root, "size", this, BoxEmitter, setSize)
     78  .describe("The Size of the BoxEmitter: x, y, z")
     79  .defaultValues(3, 1.0f,1.0f,1.0f);
     80}
     81
     82void BoxEmitter::emitParticles(unsigned int count) const
    7483{
    7584  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
     
    8291    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
    8392
     93    Vector extension = Vector(((float)rand()/RAND_MAX -.5)*this->size.x,
     94                              ((float)rand()/RAND_MAX -.5) *this->size.y,
     95                              ((float)rand()/RAND_MAX -.5) * this->size.z);
     96
     97
    8498    // ROTATIONAL CALCULATION (this must not be done for all types of particles.)
    8599    randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
     
    88102    Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);
    89103
    90     this->getSystem()->addParticle(this->getAbsCoor(), velocityV, orient, moment);
     104    this->getSystem()->addParticle(this->getAbsCoor() + extension, velocityV, orient, moment);
    91105
    92106  }
  • trunk/src/lib/particles/box_emitter.h

    r6822 r6823  
    11/*!
    2  * @file dot_emitter.h
    3  *  Definition of a DotEmitter
     2 * @file box_emitter.h
     3 *  Definition of a BoxEmitter
    44 */
    55
    6 #ifndef _DOT_EMITTER_H
    7 #define _DOT_EMITTER_H
     6#ifndef _BOX_EMITTER_H
     7#define _BOX_EMITTER_H
    88
    99#include "particle_emitter.h"
    1010
    11 // Default values
    12 #define DOT_EMITTER_DEFAULT_SIZE              1.0
    13 
    1411//! A class to handle an Emitter.
    15 class DotEmitter : public ParticleEmitter
     12class BoxEmitter : public ParticleEmitter
    1613{
    1714  friend class ParticleSystem;
    1815public:
    19   DotEmitter(const Vector& direction, float angle = .5,
    20              float emissionRate = 1.0, float velocity = 1.0);
    21   DotEmitter(const TiXmlElement* root);
    22   virtual ~DotEmitter();
     16  BoxEmitter(const Vector& size);
     17  BoxEmitter(const TiXmlElement* root);
     18  virtual ~BoxEmitter();
    2319
     20  virtual void loadParams(const TiXmlElement* root);
    2421
    25   /* controlling the emitter: interface */
    26   void tick(float dt);
     22  void setSize(float x, float y, float z);
     23  void setSize(const Vector& size) { this->setSize(size.x, size.y, size.z); };
    2724
    2825  virtual void emitParticles(unsigned int count) const;
     
    3229
    3330private:
    34   Vector          emitterSize;       //!< The size of the emitter (not for EMITTER_DOT).
    35 
     31  Vector      size;
    3632};
    3733
    38 #endif /* _DOT_EMITTER_H */
     34#endif /* _BOX_EMITTER_H */
  • trunk/src/lib/particles/dot_emitter.h

    r6822 r6823  
    88
    99#include "particle_emitter.h"
    10 
    11 // Default values
    12 #define DOT_EMITTER_DEFAULT_SIZE              1.0
    1310
    1411//! A class to handle an Emitter.
     
    2320
    2421
    25   /* controlling the emitter: interface */
    26   void tick(float dt);
    27 
    2822  virtual void emitParticles(unsigned int count) const;
    2923
    3024private:
    3125  void init();
    32 
    33 private:
    34   Vector          emitterSize;       //!< The size of the emitter (not for EMITTER_DOT).
    35 
    3626};
    3727
  • trunk/src/lib/particles/particle_system.cc

    r6757 r6823  
    140140  {
    141141    BaseObject* emitter = Factory::fabricate(element);
    142     if (emitter->isA(CL_PARTICLE_EMITTER))
    143       this->addEmitter(dynamic_cast<ParticleEmitter*>(emitter));
     142    if (emitter != NULL)
     143    {
     144      if (emitter->isA(CL_PARTICLE_EMITTER))
     145        this->addEmitter(dynamic_cast<ParticleEmitter*>(emitter));
     146      else
     147      {
     148        PRINTF(2)("Tried to load an Element of type '%s' that should be a ParticleEmitter onto '%s::%s'.\n",
     149                  emitter->getClassName(), this->getClassName(), this->getName());
     150        delete emitter;
     151      }
     152    }
    144153    else
    145154    {
    146       PRINTF(2)("Tried to load an Element of type '%s' that should be a ParticleEmitter onto '%s::%s'.\n",
    147                 emitter->getClassName(), this->getClassName(), this->getName());
    148       delete emitter;
     155      PRINTF(2)("Could not Generate Emitter for system %s::%s (wrong type in XML-format)\n", this->getClassName(), getName());
    149156    }
    150157  }
Note: See TracChangeset for help on using the changeset viewer.