Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 9, 2015, 3:51:17 PM (8 years ago)
Author:
vaydin
Message:

added ability to attach second particle effect to explosionpart, added ability to define range of velocity of explosionpart

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/explosionChunksHS15/src/orxonox/worldentities/ExplosionPart.cc

    r10755 r10786  
    4343        this->LOD_ = LODParticle::Normal;
    4444                this->mesh_ = "";
    45                 this->effect_ = "";
     45                this->effect1_ = "";
     46                this->effect2_ = "";
    4647                this->model_= new Model(this->getContext());
    47                 this->particleInterface_= NULL;
     48                this->effect1Particle_= NULL;
     49                this->effect2Particle_= NULL;
    4850                this->explosionEntity_ = new MovableEntity(this->getContext());
    4951
     
    5355
    5456
     57        ExplosionPart::~ExplosionPart()
     58    {
     59        if (this->isInitialized())
     60        {
     61            if (this->effect1Particle_)
     62            {
     63                this->model_->detachOgreObject(this->effect1Particle_->getParticleSystem());
     64                delete this->effect1Particle_;
     65            }
     66            if (this->effect2Particle_)
     67            {
     68                this->model_->detachOgreObject(this->effect2Particle_->getParticleSystem());
     69                delete this->effect2Particle_;
     70            }
     71        }
     72    }
     73
     74
    5575        void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5676        {
    5777                SUPER(ExplosionPart, XMLPort, xmlelement, mode);
    5878
    59                 XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode);
    60                 XMLPortParam(ExplosionPart, "effect", setEffect, getEffect, xmlelement, mode);
     79                XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode).defaultValues("");
     80                XMLPortParam(ExplosionPart, "minspeed", setMinSpeed, getMinSpeed, xmlelement, mode).defaultValues(50);
     81                XMLPortParam(ExplosionPart, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode).defaultValues(100);
     82                XMLPortParam(ExplosionPart, "effect1", setEffect1, getEffect1, xmlelement, mode).defaultValues("");
     83                XMLPortParam(ExplosionPart, "effect2", setEffect2, getEffect2, xmlelement, mode).defaultValues("");
    6184
    6285
     
    6891                orxout() << "Explode" << endl;
    6992
    70                 orxout() << getMesh() << endl;
    71                 orxout() << getEffect() << endl;
    7293
    7394                this->model_->setVisible(true);
     
    7798                //this->model_->setSyncMode(0);
    7899
    79                 this->particleInterface_ = new ParticleInterface(this->getScene()->getSceneManager(), effect_, this->LOD_);
     100                if(effect1_ != "")
     101                {
     102                        this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_);
     103                        this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem());
     104                }
    80105
    81                 this->model_->attachOgreObject(this->particleInterface_->getParticleSystem());
     106                if(effect2_ != "")
     107                {
     108                        this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_);
     109                        this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem());
     110                }       
    82111
    83                
    84 
    85                 this->explosionEntity_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
     112                this->explosionEntity_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(minSpeed_,maxSpeed_));
    86113        this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
    87114        this->explosionEntity_->setScale(4);
     
    91118        this->attach(explosionEntity_);
    92119
     120        if (GameMode::isMaster())
     121        {
     122            this->destroyTimer_.setTimer(rnd(2, 3), false, createExecutor(createFunctor(&ExplosionPart::stop, this)));
     123        }
     124
     125        }
     126
     127        void ExplosionPart::stop()
     128        {
     129                if (this->effect1Particle_)
     130            this->effect1Particle_->setEnabled(false);
     131        if (this->effect2Particle_)
     132            this->effect2Particle_->setEnabled(false);
     133        if (this->model_)
     134            this->model_->setVisible(false);
     135
     136        if (GameMode::isMaster())
     137        {
     138            this->bStop_ = true;
     139            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionPart::destroy, this)));
     140        }
    93141        }
    94142
     
    98146        void ExplosionPart::setMesh(const std::string& newString)
    99147        {
    100                 this->mesh_ = newString;
    101                 this->model_->setMeshSource(mesh_);
    102                 this->model_->setVisible(false);
    103                 orxout() << newString << endl;
     148                if(newString != "")
     149                {
     150                        this->mesh_ = newString;
     151                        this->model_->setMeshSource(mesh_);
     152                        this->model_->setVisible(false);
     153                }
    104154        }
    105155
    106         void ExplosionPart::setEffect(const std::string& newString)
     156        void ExplosionPart::setEffect1(const std::string& newString)
    107157        {
    108                 this->effect_ = newString;
     158                this->effect1_ = newString;
     159        }
     160
     161        void ExplosionPart::setEffect2(const std::string& newString)
     162        {
     163                this->effect2_ = newString;
     164        }
     165
     166        void ExplosionPart::setMinSpeed(float speed)
     167        {
     168                this->minSpeed_ = speed;
     169        }
     170
     171        void ExplosionPart::setMaxSpeed(float speed)
     172        {
     173                this->maxSpeed_ = speed;
    109174        }
    110175
     
    112177        { return this->mesh_; }
    113178
    114         std::string& ExplosionPart::getEffect()
    115         { return this->effect_; }
     179        std::string& ExplosionPart::getEffect1()
     180        { return this->effect1_; }
     181
     182        std::string& ExplosionPart::getEffect2()
     183        { return this->effect2_; }
     184
     185        float ExplosionPart::getMinSpeed()
     186        {
     187                return this->minSpeed_;
     188        }
     189
     190        float ExplosionPart::getMaxSpeed()
     191        {
     192                return this->maxSpeed_;
     193        }
     194
    116195
    117196
Note: See TracChangeset for help on using the changeset viewer.