Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4726 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Jun 28, 2005, 10:33:14 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more loading procedures, fixed small bugs in loadparam

Location:
orxonox/trunk/src/lib/particles
Files:
5 edited

Legend:

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

    r4725 r4726  
    3030CREATE_FACTORY(ParticleEmitter);
    3131
    32 
    3332/**
    3433   \brief standard constructor
     
    3736                  float velocity)
    3837{
    39   this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter");
    40   this->type = EMITTER_DOT;
    41   this->emitterSize = 1.0;
     38  this->init();
     39
    4240  this->direction = direction;
    43   this->setInheritSpeed(0);
    4441  this->setSpread(angle);
    4542  this->setEmissionRate(emissionRate);
     
    5552ParticleEmitter::ParticleEmitter(const TiXmlElement* root)
    5653{
    57    this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter");
    58 
    59    this->saveTime = 0.0;
     54  this->init();
    6055
    6156   if (root)
     
    7671
    7772/**
     73  \brief initializes default values of a ParitcleEmitter
     74*/
     75void ParticleEmitter::init()
     76{
     77  this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter");
     78
     79  this->type = PARTICLE_EMITTER_DEFAULT_TYPE;
     80  this->emitterSize = PARTICLE_EMITTER_DEFAULT_SIZE;
     81  this->setInheritSpeed(PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED);
     82  this->setEmissionRate(PARTICLE_EMITTER_DEFAULT_EMISSION_RATE);
     83  this->setSize(PARTICLE_EMITTER_DEFAULT_SIZE);
     84
     85  this->saveTime = 0.0;
     86}
     87
     88/**
    7889   \brief loads a ParticleEmitter from a XML-element
    7990   \param root the XML-element to load from
     
    103114  LoadParam<ParticleEmitter>(root, "spread", this, &ParticleEmitter::setSpread)
    104115    .describe("The angle the particles are emitted from (angle, deviation)");
     116
     117
     118  LoadParam<ParticleEmitter>(root, "emission-direction", this, &ParticleEmitter::setDirection);
    105119}
    106120
  • orxonox/trunk/src/lib/particles/particle_emitter.h

    r4690 r4726  
    1212class ParticleSystem;
    1313class TiXmlElement;
     14
     15// Default values
     16#define PARTICLE_EMITTER_DEFAULT_SIZE              1.0
     17#define PARTICLE_EMITTER_DEFAULT_EMISSION_RATE     50
     18#define PARTICLE_EMITTER_DEFAULT_TYPE              EMITTER_DOT
     19#define PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED     0.0
     20#define PARTICLE_EMITTER_DEFAULT_SPREAD            M_PI
    1421
    1522//! The form of the Emitter to emit from
     
    3138  virtual ~ParticleEmitter(void);
    3239
     40  void init();
    3341  void loadParams(const TiXmlElement* root);
    3442
     
    4755  void setEmissionVelocity(float velocity, float randomVelocity = 0.0);
    4856  void setEmissionMomentum(float momentum, float randomMomentum = 0.0);
     57
     58  void setDirection(float x, float y, float z) { this->direction = Vector(x,y,z); }; //!< todo this should be done via PNODE
    4959
    5060  /** \returns the type of the emitter */
  • orxonox/trunk/src/lib/particles/particle_engine.cc

    r4639 r4726  
    2424#include "debug.h"
    2525#include "stdlibincl.h"
     26#include "load_param.h"
    2627
    2728using namespace std;
     
    8283
    8384/**
     85  \brief loads the ParticleEngines settings and connections between particles and emitters
     86  \param root the XML-element to load this from.
     87 */
     88void ParticleEngine::loadParams(const TiXmlElement* root)
     89{
     90  const TiXmlElement* element = root->FirstChildElement();
     91  while( element != NULL)
     92  {
     93    LoadParam<ParticleEngine>(element, "connect", this, &ParticleEngine::addConnection, true)
     94        .describe("connects an Emitter to a System (emitterName, systemName)");
     95    element = element->NextSiblingElement();
     96  }
     97}
     98
     99
     100
     101/**
    84102   \brief Adds a System to the System list.
    85103
     
    99117{
    100118  this->emitterList->add(emitter);
     119}
     120
     121/**
     122  \brief Connects a ParticleSystem to a ParticleSystem thus emitting Particles.
     123  \param emitter the Emitter to connect to the System
     124  \param system the System to connect to the Emitter
     125*/
     126void ParticleEngine::addConnection(const char* emitter, const char* system)
     127{
     128  ParticleEmitter* tmpEmit = this->getEmitterByName(emitter);
     129  ParticleSystem* tmpSys = this->getSystemByName(system);
     130
     131  if (tmpEmit != NULL && tmpSys != NULL)
     132    this->addConnection(tmpEmit, tmpSys);
     133  else
     134  {
     135    if (tmpEmit == NULL)
     136      PRINTF(2)("Emitter %s not found in the List of emitters, not connecting to %s\n", emitter, system);
     137    if (tmpEmit == NULL)
     138      PRINTF(2)("System %s not found in the List of emitters, not connecting to %s\n", system, emitter);
     139  }
    101140}
    102141
  • orxonox/trunk/src/lib/particles/particle_engine.h

    r4677 r4726  
    88
    99#include "base_object.h"
     10
    1011#include "particle_system.h"
    1112#include "particle_emitter.h"
     13
     14#include "tinyxml.h"
    1215
    1316// FORWARD DEFINITION
     
    3437  inline static ParticleEngine* getInstance(void) { if (!singletonRef) singletonRef = new ParticleEngine();  return singletonRef; };
    3538
     39  void loadParams(const TiXmlElement* root);
     40
    3641  void tick(float dt);
    3742  void draw(void) const;
     
    4045  void addEmitter(ParticleEmitter* emitter);
    4146  void addConnection(ParticleEmitter* emitter, ParticleSystem* system);
     47  void addConnection(const char* emitter, const char* system);
     48
    4249
    4350  bool removeSystem(ParticleSystem* system);
  • orxonox/trunk/src/lib/particles/particle_system.cc

    r4725 r4726  
    127127
    128128  LoadParam<ParticleSystem>(root, "type", this, &ParticleSystem::setType)
    129       .describe("sets the type of the Particles, (DOT, SPARK, SPRITE or MODEL)");
    130 
    131   LoadParam<ParticleSystem>(root, "model", this, &ParticleSystem::setModel)
    132       .describe("sets a model to be loaded on top of this System (also sets type to Model)");
     129      .describe("sets the type of the Particles, (dot, spark, sprite or model)");
    133130
    134131  // PER-PARTICLE-ATTRIBUTES:
     
    149146void ParticleSystem::setType(const char* particleType)
    150147{
    151   if (strcmp(particleType, "DOTS"))
     148  if (!strcmp(particleType, "dot"))
    152149    this->setType(PARTICLE_DOT);
    153   else if (strcmp(particleType, "SPARKS"))
     150  else if(!strcmp(particleType, "spark"))
    154151    this->setType(PARTICLE_SPARK);
    155   else if (strcmp(particleType, "MODELS"))
     152  else if(!strcmp(particleType, "model"))
    156153    this->setType(PARTICLE_MODEL);
    157154  else // if (strcmp(particleType, "SPRITE"))
     
    187184      //  material->setTransparency(.5);
    188185        break;
    189       case PARTICLE_MODEL:
    190         if (!this->model)
    191         {
    192           PRINTF(2)("Model not loaded yet, please do this through ParticleSystem::loadModel()");
    193           this->setType(PARTICLE_SPRITE);
    194         }
    195         break;
    196     }
     186  }
    197187}
    198188
     
    207197{
    208198  this->material = material;
    209 }
    210 
    211 /**
    212  * sets a Model to the Particles
    213  * @param modelName the Name of the Model to load
    214  */
    215 void ParticleSystem::setModel(const char* modelName)
    216 {
    217   if (this->model)
    218     ResourceManager::getInstance()->unload(this->model);
    219   if (modelName)
    220   {
    221     this->model = (Model*)ResourceManager::getInstance()->load(modelName, OBJ, RP_LEVEL);
    222     this->setType(PARTICLE_MODEL);
    223   }
    224   else
    225   {
    226     this->model = NULL;
    227     this->setType(PARTICLE_SPRITE);
    228   }
    229199}
    230200
     
    505475          drawPart = drawPart->next;
    506476        }
     477        else
     478          printf("no model loaded onto ParticleSystem-%s\n", this->getName());
    507479      }
    508480      break;
     
    595567void ParticleSystem::debug(void) const
    596568{
    597   PRINT(0)("  ParticleSystem %s\n", this->getName());
     569  PRINT(0)("  ParticleSystem %s, type: ", this->getName());
     570  {
     571      if (this->particleType == PARTICLE_MODEL)
     572        PRINT(0)("model");
     573      else if (this->particleType == PARTICLE_SPRITE)
     574        PRINT(0)("sprite");
     575      else if (this->particleType == PARTICLE_DOT)
     576        PRINT(0)("dot");
     577      else if (this->particleType == PARTICLE_SPARK)
     578        PRINT(0)("spark");
     579
     580      PRINT(0)("\n");
     581  }
     582
    598583  PRINT(0)("  ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount);
    599584  if (deadList)
Note: See TracChangeset for help on using the changeset viewer.