Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11_v3/src/orxonox/worldentities/ExplosionPart.cc @ 11065

Last change on this file since 11065 was 11065, checked in by landauf, 8 years ago

added c++11 features to code that was added in presentationHS15

  • Property svn:eol-style set to native
File size: 7.9 KB
RevLine 
[10752]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Vedat Aydin
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29
[10937]30
[10752]31#include "ExplosionPart.h"
32#include "core/XMLPort.h"
33
34
35namespace orxonox
36{
37
[11025]38    RegisterClass(ExplosionPart);
[10752]39
[11025]40    ExplosionPart::ExplosionPart(Context* context) : MovableEntity(context)
41    {
42        RegisterObject(ExplosionPart);
43        this->bStop_ = false;
[10752]44        this->LOD_ = LODParticle::Normal;
[11025]45        this->mesh_ = "";
46        this->effect1_ = "";
47        this->effect2_ = "";
48        this->model_= new Model(this->getContext());
[11065]49        this->effect1Particle_= nullptr;
50        this->effect2Particle_= nullptr;
[11025]51        this->explosionEntity_ = new MovableEntity(this->getContext());
52        this->posOffset_ = Vector3::ZERO;
[10752]53
[10755]54
55
[11025]56    }
[10752]57
58
[11025]59    ExplosionPart::~ExplosionPart()
[10786]60    {
61        if (this->isInitialized())
62        {
63            if (this->effect1Particle_)
64            {
65                this->model_->detachOgreObject(this->effect1Particle_->getParticleSystem());
66                delete this->effect1Particle_;
67            }
68            if (this->effect2Particle_)
69            {
70                this->model_->detachOgreObject(this->effect2Particle_->getParticleSystem());
71                delete this->effect2Particle_;
72            }
73        }
74    }
75
76
[11025]77    void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)
78    {
79        SUPER(ExplosionPart, XMLPort, xmlelement, mode);
[10752]80
[11025]81        XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode).defaultValues(""); //Define mesh file, that is going to fly out
82        XMLPortParam(ExplosionPart, "minspeed", setMinSpeed, getMinSpeed, xmlelement, mode).defaultValues(50); //Minimum velocity at which parts fly out
83        XMLPortParam(ExplosionPart, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode).defaultValues(100); //Maximum velocity at which parts fly out, set both minspeed and maxspeed to 0 to have stationary effects
84        XMLPortParam(ExplosionPart, "effect1", setEffect1, getEffect1, xmlelement, mode).defaultValues(""); //particle effect 1
85        XMLPortParam(ExplosionPart, "effect2", setEffect2, getEffect2, xmlelement, mode).defaultValues(""); //particle effect 2
86        XMLPortParam(ExplosionPart, "offset", setOffset, getOffset, xmlelement, mode).defaultValues(Vector3::ZERO); //Offset of the position if you need to have an explosion off-center
87        XMLPortParam(ExplosionPart, "direction", setDirection, getDirection, xmlelement, mode).defaultValues(Vector3(1,1,1)); //general direction the parts fly in
88        XMLPortParam(ExplosionPart, "angle", setAngle, getAngle, xmlelement, mode).defaultValues(180); //defines a cone shape with direction "direction" and angle "angle" inside which the parts fly out of
89        XMLPortParam(ExplosionPart, "delay", setDelay, getDelay, xmlelement, mode).defaultValues(0); //delay to the explosion in seconds
90    }
[10752]91
92
[11025]93    void ExplosionPart::Explode()
94    {
95        this->destroyTimer_.setTimer(delay_, false, createExecutor(createFunctor(&ExplosionPart::ActuallyExplode, this)));
96    }
[10752]97
[11025]98    void ExplosionPart::stop()
99    {
100        if (this->effect1Particle_)
[10837]101            this->effect1Particle_->setEnabled(false);
102        if (this->effect2Particle_)
103            this->effect2Particle_->setEnabled(false);
104        if (this->model_)
105            this->model_->setVisible(false);
[10752]106
[10837]107        if (GameMode::isMaster())
108        {
109            this->bStop_ = true;
110            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionPart::destroy, this)));
111        }
[11025]112    }
[10810]113
[11025]114    void ExplosionPart::ActuallyExplode()
115    {
116        this->model_->setVisible(true);
[10752]117
[11025]118        //this->explosionEntity_->setSyncMode(0);
[10752]119
[11025]120        //this->model_->setSyncMode(0);
[10755]121
[10937]122
[11025]123        if(effect1_ != "")
124        {
125            this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_);
126            this->effect1Particle_->setDimensions(this->getScale());
127            this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem());
128        }
[10752]129
[11025]130        if(effect2_ != "")
131        {
132            this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_);
133            this->effect2Particle_->setDimensions(this->getScale());
134            this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem());
135        }
[10752]136
[10937]137
138
[11025]139
[10837]140        Vector3 velocityOffset = direction_.perpendicular();
141        velocityOffset.normalise();
142        Degree offsetDirection = Degree(rnd(0,360));
143        velocityOffset = Quaternion(offsetDirection, direction_.normalisedCopy()) * velocityOffset;
144        velocityOffset.normalise();
145        direction_.normalise();
146
[11029]147        Vector3 finalDirection = direction_ + sin((rnd(0, angle_))*math::pi/180)*velocityOffset;
[10837]148
[11025]149        this->explosionEntity_->setVelocity(finalDirection*rnd(minSpeed_,maxSpeed_));
[10752]150        this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
[10937]151        this->explosionEntity_->setScale(this->getScale() * 4);
[10752]152
[10937]153
[10752]154        this->explosionEntity_->attach(model_);
155
[10937]156
[10752]157        this->attach(explosionEntity_);
158
[10786]159        if (GameMode::isMaster())
160        {
[10807]161            this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this)));
[10786]162        }
[11025]163    }
[10752]164
165
166
167
[11025]168    void ExplosionPart::setMesh(const std::string& newString)
169    {
170        if(newString != "")
171        {
172            this->mesh_ = newString;
173            this->model_->setMeshSource(mesh_);
174            this->model_->setVisible(false);
175        }
176    }
[10752]177
[11025]178    void ExplosionPart::setEffect1(const std::string& newString)
179    {
180        this->effect1_ = newString;
181    }
[10752]182
[11025]183    void ExplosionPart::setEffect2(const std::string& newString)
184    {
185        this->effect2_ = newString;
186    }
[10786]187
[11025]188    void ExplosionPart::setMinSpeed(float speed)
189    {
190        this->minSpeed_ = speed;
191    }
[10786]192
[11025]193    void ExplosionPart::setMaxSpeed(float speed)
194    {
195        this->maxSpeed_ = speed;
196    }
[10786]197
[11025]198    void ExplosionPart::setOffset(Vector3 newVector)
199    {
200        this->posOffset_ = newVector;
201        this->explosionEntity_->setPosition(this->getPosition() + this->posOffset_ / this->getScale());
202    }
[10810]203
[11025]204    void ExplosionPart::setDirection(Vector3 newDirection)
205    {
206        this->direction_ = newDirection;
207    }
[10837]208
[11025]209    void ExplosionPart::setAngle(float newAngle)
210    {
211        this->angle_ = newAngle;
212    }
[10837]213
[11025]214    void ExplosionPart::setDelay(float newDelay)
215    {
216        this->delay_ = newDelay;
217    }
[10837]218
[11025]219    std::string& ExplosionPart::getMesh()
220    { return this->mesh_; }
[10752]221
[11025]222    std::string& ExplosionPart::getEffect1()
223    { return this->effect1_; }
[10752]224
[11025]225    std::string& ExplosionPart::getEffect2()
226    { return this->effect2_; }
[10752]227
[11025]228    float ExplosionPart::getMinSpeed()
229    {
230        return this->minSpeed_;
231    }
[10786]232
[11025]233    float ExplosionPart::getMaxSpeed()
234    {
235        return this->maxSpeed_;
236    }
[10786]237
[11025]238    Vector3 ExplosionPart::getOffset()
239    {
240        return this->posOffset_;
241    }
[10786]242
[11025]243    Vector3 ExplosionPart::getDirection()
244    {
245        return direction_;
246    }
[10786]247
[11025]248    float ExplosionPart::getAngle()
249    {
250        return angle_;
251    }
[10810]252
[11025]253    float ExplosionPart::getDelay()
254    {
255        return delay_;
256    }
[10837]257
258
259
[11025]260}
Note: See TracBrowser for help on using the repository browser.