Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 6, 2008, 5:31:58 PM (17 years ago)
Author:
landauf
Message:

several improvements:

  • AI works properly now - add enemies with 'createEnemy x' where x is the number of enemies to add, default is 1. You can remove AI ships with 'killEnemies'.
  • Added new explosion (with smoke)
  • Added new projectile (with trail)
  • Added new thruster emitter
  • AI ships are destroyable - they start with 100 hp, each hit makes 15 hp damage, this value is configurable in the config-file: [Projectile] damage_
  • Added AI ship spawn and explosion effects
Location:
code/trunk/src/orxonox/particle
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/particle/ParticleInterface.cc

    r1505 r1552  
    3434#include "ParticleInterface.h"
    3535
    36 // #include <OgreParticleSystem.h>
    37 // #include <Ogre.h>
    38 // #include <OIS/OIS.h>
    39 // #include <CEGUI/CEGUI.h>
    40 // #include <CEGUIRenderer.h>
     36#include <OgreParticleSystem.h>
     37#include <OgreParticleEmitter.h>
     38#include <OgreSceneManager.h>
    4139
     40#include "GraphicsEngine.h"
     41#include "util/Convert.h"
    4242
     43namespace orxonox
     44{
     45  unsigned int ParticleInterface::counter_s = 0;
     46  ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
    4347
    44 namespace orxonox {
    45   using namespace Ogre;
    46 
    47   ParticleInterface::ParticleInterface( SceneManager *sceneManager, std::string name, std::string templateName )
     48  ParticleInterface::ParticleInterface(const std::string& templateName)
    4849  {
    49     sceneManager_ = sceneManager;
    50     particleSystem_ = sceneManager->createParticleSystem(name, templateName);
    51 
    52     //Variabeln einlesen, Emitter1_ ist Referenz-Emitter
    53     velocity_ = particleSystem_->getSpeedFactor();
    54     colour_ = particleSystem_->getEmitter(0)->getColour();
    55     rate_ = particleSystem_->getEmitter(0)->getEmissionRate();
    56     distance_ = particleSystem_->getEmitter(0)->getTimeToLive();
    57 
    58     //Anzahl der Emitter
    59     numberOfEmitters_ = particleSystem_->getNumEmitters();
    60     standardizeEmitters();
     50    this->sceneNode_ = 0;
     51    this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
    6152  }
    6253
    63   ParticleInterface::~ParticleInterface(void)
     54  ParticleInterface::~ParticleInterface()
    6455  {
    65     while(particleSystem_->getNumEmitters()>0)
    66       particleSystem_->removeEmitter(particleSystem_->getNumEmitters()-1);
    67     sceneManager_->destroyParticleSystem(particleSystem_);
     56    this->particleSystem_->removeAllEmitters();
     57    GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_);
    6858  }
    6959
    70   void ParticleInterface::standardizeEmitters(void)
     60  void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
    7161  {
    72     //Abgleichen der anderen Emitter an die Variabeln
    73     for (int i=0; i < numberOfEmitters_; i++) {
    74       particleSystem_->getEmitter(i)->setColour( colour_ );
    75       particleSystem_->getEmitter(i)->setTimeToLive( distance_ );
    76       particleSystem_->getEmitter(i)->setEmissionRate( rate_ );
    77     }
    78 
     62    this->sceneNode_ = sceneNode;
     63    this->sceneNode_->attachObject(this->particleSystem_);
    7964  }
    8065
    81   void ParticleInterface::setVelocity(Real v)
     66  void ParticleInterface::detachFromSceneNode()
    8267  {
    83     velocity_ = v;
    84     //partikel anpassen
    85     particleSystem_->setSpeedFactor(v);
    86   }
    87 
    88   void ParticleInterface::setRate(float r)
    89   {
    90     rate_ = r;
    91     //partikel anpassen
    92     for (int i=0; i<numberOfEmitters_; i++) {
    93       particleSystem_->getEmitter(i)->setEmissionRate(rate_);
     68    if (this->sceneNode_)
     69    {
     70      this->sceneNode_->detachObject(this->particleSystem_);
     71      this->sceneNode_ = 0;
    9472    }
    9573  }
    9674
    97   void ParticleInterface::setDistance(Real d)
     75  Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
    9876  {
    99     distance_ = d;
    100     //partikel anpassen
    101     for (int i=0; i < numberOfEmitters_; i++) {
    102       particleSystem_->getEmitter(i)->setTimeToLive(distance_);
     77    if (this->particleSystem_->getNumEmitters() > 0)
     78    {
     79      Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
     80      this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
     81      return newemitter;
    10382    }
     83    else
     84      return 0;
     85  }
     86  Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
     87  {
     88    if (emitterNr < this->particleSystem_->getNumEmitters())
     89      return this->particleSystem_->getEmitter(emitterNr);
     90    else
     91      return 0;
     92  }
     93  void ParticleInterface::removeEmitter(unsigned int emitterNr)
     94  {
     95    if (emitterNr < this->particleSystem_->getNumEmitters())
     96      this->particleSystem_->removeEmitter(emitterNr);
     97  }
     98  void ParticleInterface::removeAllEmitters()
     99  {
     100    this->particleSystem_->removeAllEmitters();
     101  }
     102  unsigned int ParticleInterface::getNumEmitters() const
     103  {
     104    return this->particleSystem_->getNumEmitters();
    104105  }
    105106
    106   void ParticleInterface::setColour(ColourValue colour)
     107  Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
    107108  {
    108     colour_ = colour;
    109     //partikel anpassen
    110     for (int i=0; i < numberOfEmitters_; i++) {
    111       particleSystem_->getEmitter(i)->setColour(colour_);
    112     }
     109    return this->particleSystem_->addAffector(name);
     110  }
     111  Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const
     112  {
     113    if (affectorNr < this->particleSystem_->getNumAffectors())
     114      return this->particleSystem_->getAffector(affectorNr);
     115    else
     116      return 0;
     117  }
     118  void ParticleInterface::removeAffector(unsigned int affectorNr)
     119  {
     120    if (affectorNr < this->particleSystem_->getNumAffectors())
     121      this->particleSystem_->removeAffector(affectorNr);
     122  }
     123  void ParticleInterface::removeAllAffectors()
     124  {
     125    this->particleSystem_->removeAllAffectors();
     126  }
     127  unsigned int ParticleInterface::getNumAffectors() const
     128  {
     129    return this->particleSystem_->getNumAffectors();
    113130  }
    114131
    115   ParticleEmitter* ParticleInterface::getEmitter( int emitterNr )
     132  void ParticleInterface::setEnabled(bool enable)
    116133  {
    117     if ( (emitterNr >= numberOfEmitters_) || (emitterNr < 0) ) return NULL;
    118     return particleSystem_->getEmitter(emitterNr);
     134    for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
     135      this->particleSystem_->getEmitter(i)->setEnabled(enable);
    119136  }
    120137
    121   void ParticleInterface::newEmitter ()
     138  void ParticleInterface::setSpeedFactor(float factor)
    122139  {
    123     particleSystem_->addEmitter(particleSystem_->getEmitter(0)->getType());
    124     particleSystem_->getEmitter(0)->copyParametersTo( particleSystem_->getEmitter(numberOfEmitters_) );
    125     numberOfEmitters_++;
     140    this->particleSystem_->setSpeedFactor(factor);
     141  }
     142  float ParticleInterface::getSpeedFactor() const
     143  {
     144    return this->particleSystem_->getSpeedFactor();
    126145  }
    127146
    128   // TODO check if this really works
    129   Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr )
     147  bool ParticleInterface::getKeepParticlesInLocalSpace() const
    130148  {
    131     return particleSystem_->getEmitter(emitterNr)->getPosition();
     149    return this->particleSystem_->getKeepParticlesInLocalSpace();
    132150  }
    133 
    134   void ParticleInterface::setDirection ( Vector3 direction )
     151  void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
    135152  {
    136     for(int i=0; i < numberOfEmitters_; i++) {
    137       particleSystem_->getEmitter(i)->setDirection(direction);
    138     }
     153    this->particleSystem_->setKeepParticlesInLocalSpace(keep);
    139154  }
    140 
    141   void ParticleInterface::switchEnable(){
    142     bool enable=(!(particleSystem_->getEmitter(0)->getEnabled()));
    143     for(int i=0; i < numberOfEmitters_; i++) {
    144       particleSystem_->getEmitter(i)->setEnabled(enable);
    145     }
    146   }
    147 
    148155}
  • code/trunk/src/orxonox/particle/ParticleInterface.h

    r1505 r1552  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      ...
    2424 *   Co-authors:
    2525 *      ...
     
    3333
    3434#include <string>
    35 
    36 // #include "ParticleInterface.h"
    37 // #include <Ogre.h>
    38 // #include <OIS/OIS.h>
    39 // #include <CEGUI/CEGUI.h>
    40 // #include <CEGUIRenderer.h>
    41 #include <OgreParticleSystem.h>
    4235#include <OgreParticleEmitter.h>
    43 #include <OgreSceneManager.h>
    4436
    4537#include "util/Math.h"
    4638
     39#define getAllEmitters() \
     40  storeThisAsCurrentParticleInterface(); \
     41  for (unsigned int i = 0; i < ParticleInterface::getCurrentParticleInterface()->getNumEmitters(); ++i) \
     42    ParticleInterface::getCurrentParticleInterface()->getEmitter(i)
    4743
    4844namespace orxonox
    4945{
    50 
    5146  class _OrxonoxExport ParticleInterface
    5247  {
    53   public:
     48    public:
     49      ParticleInterface(const std::string& templateName);
     50      ~ParticleInterface();
    5451
    55     ParticleInterface( Ogre::SceneManager *sceneManager, std::string name, std::string templateName );
    56     ~ParticleInterface( void );
     52      inline Ogre::ParticleSystem* getParticleSystem() const
     53        { return this->particleSystem_; }
    5754
    58     inline void addToSceneNode( Ogre::SceneNode* sceneNode )
    59         { sceneNode_ = sceneNode; sceneNode_->attachObject(particleSystem_);};
    60     inline void detachFromSceneNode( void )
    61         { sceneNode_->detachObject(particleSystem_); sceneNode_ = NULL;};
     55      void addToSceneNode(Ogre::SceneNode* sceneNode);
     56      void detachFromSceneNode();
    6257
    63     Ogre::ParticleEmitter* getEmitter ( int emitterNr );
    64     void newEmitter ( void );
     58      Ogre::ParticleEmitter* createNewEmitter();
     59      Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const;
     60      void removeEmitter(unsigned int emitterNr);
     61      void removeAllEmitters();
     62      unsigned int getNumEmitters() const;
    6563
    66     Vector3 getPositionOfEmitter ( int emitterNr );
    67     inline void setPositionOfEmitter ( int emitterNr, Vector3 position )
    68         { particleSystem_->getEmitter(emitterNr)->setPosition(position); };
     64      Ogre::ParticleAffector* addAffector(const std::string& name);
     65      Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const;
     66      void removeAffector(unsigned int affectorNr);
     67      void removeAllAffectors();
     68      unsigned int getNumAffectors() const;
    6969
    70     inline Vector3 getDirection ( void )
    71         { return particleSystem_->getEmitter(0)->getDirection(); };
    72     void setDirection ( Vector3 direction );
     70      float getSpeedFactor() const;
     71      void setSpeedFactor(float factor);
     72      bool getKeepParticlesInLocalSpace() const;
     73      void setKeepParticlesInLocalSpace(bool keep);
    7374
    74     inline Real getVelocity()
    75         {return velocity_; };
    76     void setVelocity( Real v );
     75      void setEnabled(bool enable);
    7776
    78     inline float getRate()
    79       { return rate_; };
    80     void setRate( float r );
     77      inline void storeThisAsCurrentParticleInterface()
     78        { ParticleInterface::currentParticleInterface_s = this; }
     79      inline static ParticleInterface* getCurrentParticleInterface()
     80        { return ParticleInterface::currentParticleInterface_s; }
    8181
    82     inline Real getDistance()
    83         { return distance_; };
    84     void setDistance( Real d );
    85 
    86     inline ColourValue getColour( void )
    87         {return colour_;};
    88     void setColour( ColourValue colour );
    89 
    90     void switchEnable();
    91 
    92     inline Ogre::ParticleSystem* getParticleSystem()
    93         { return this->particleSystem_; };
    94 
    95   private:
    96     Ogre::SceneNode *sceneNode_;
    97     Ogre::SceneManager *sceneManager_;
    98     Ogre::ParticleSystem *particleSystem_;
    99     Real distance_;
    100     Real velocity_;
    101     float rate_;
    102     ColourValue colour_;
    103     int numberOfEmitters_;
    104 
    105     void standardizeEmitters();
     82    private:
     83      static ParticleInterface* currentParticleInterface_s;
     84      static unsigned int counter_s;
     85      Ogre::SceneNode* sceneNode_;
     86      Ogre::ParticleSystem* particleSystem_;
    10687  };
    107 
    10888}
    10989
Note: See TracChangeset for help on using the changeset viewer.