Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/explosionChunksHS15/src/orxonox/worldentities/ExplosionPart.cc @ 10930

Last change on this file since 10930 was 10837, checked in by vaydin, 10 years ago

fixed position offset, added definable direction for the meshes to fly in, added size, added delay

File size: 6.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
30#include "ExplosionPart.h"
31#include "core/XMLPort.h"
32
33
34namespace orxonox
35{
36
37        RegisterClass(ExplosionPart);
38
39        ExplosionPart::ExplosionPart(Context* context) : MovableEntity(context)
40        {
41                RegisterObject(ExplosionPart);
42                this->bStop_ = false;
43        this->LOD_ = LODParticle::Normal;
44                this->mesh_ = "";
[10786]45                this->effect1_ = "";
46                this->effect2_ = "";
[10752]47                this->model_= new Model(this->getContext());
[10786]48                this->effect1Particle_= NULL;
49                this->effect2Particle_= NULL;
[10752]50                this->explosionEntity_ = new MovableEntity(this->getContext());
[10810]51                this->posOffset_ = Vector3::ZERO;
[10752]52
[10755]53
54
[10752]55        }
56
57
[10786]58        ExplosionPart::~ExplosionPart()
59    {
60        if (this->isInitialized())
61        {
62            if (this->effect1Particle_)
63            {
64                this->model_->detachOgreObject(this->effect1Particle_->getParticleSystem());
65                delete this->effect1Particle_;
66            }
67            if (this->effect2Particle_)
68            {
69                this->model_->detachOgreObject(this->effect2Particle_->getParticleSystem());
70                delete this->effect2Particle_;
71            }
72        }
73    }
74
75
[10752]76        void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)
77        {
78                SUPER(ExplosionPart, XMLPort, xmlelement, mode);
79
[10786]80                XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode).defaultValues("");
81                XMLPortParam(ExplosionPart, "minspeed", setMinSpeed, getMinSpeed, xmlelement, mode).defaultValues(50);
82                XMLPortParam(ExplosionPart, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode).defaultValues(100);
83                XMLPortParam(ExplosionPart, "effect1", setEffect1, getEffect1, xmlelement, mode).defaultValues("");
84                XMLPortParam(ExplosionPart, "effect2", setEffect2, getEffect2, xmlelement, mode).defaultValues("");
[10810]85                XMLPortParam(ExplosionPart, "offset", setOffset, getOffset, xmlelement, mode).defaultValues(Vector3::ZERO);
[10837]86                XMLPortParam(ExplosionPart, "direction", setDirection, getDirection, xmlelement, mode).defaultValues(Vector3(1,1,1));
87                XMLPortParam(ExplosionPart, "angle", setAngle, getAngle, xmlelement, mode).defaultValues(180);
88                XMLPortParam(ExplosionPart, "size", setSize, getSize, xmlelement, mode).defaultValues(4);
89                XMLPortParam(ExplosionPart, "delay", setDelay, getDelay, xmlelement, mode).defaultValues(0);
[10752]90        }
91
92
93        void ExplosionPart::Explode()
94        {
[10837]95                this->destroyTimer_.setTimer(delay_, false, createExecutor(createFunctor(&ExplosionPart::ActuallyExplode, this)));
96        }
[10752]97
[10837]98        void ExplosionPart::stop()
99        {
100                if (this->effect1Particle_)
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        }
112        }
[10810]113
[10837]114        void ExplosionPart::ActuallyExplode()
115        {
[10755]116                this->model_->setVisible(true);
[10752]117
[10755]118                //this->explosionEntity_->setSyncMode(0);
[10752]119
[10755]120                //this->model_->setSyncMode(0);
121
[10786]122                if(effect1_ != "")
123                {
124                        this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_);
125                        this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem());
126                }
[10752]127
[10786]128                if(effect2_ != "")
129                {
130                        this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_);
131                        this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem());
[10837]132                }
[10752]133
[10837]134               
135        Vector3 velocityOffset = direction_.perpendicular();
136        velocityOffset.normalise();
137        Degree offsetDirection = Degree(rnd(0,360));
138        velocityOffset = Quaternion(offsetDirection, direction_.normalisedCopy()) * velocityOffset;
139        velocityOffset.normalise();
140        direction_.normalise();
141
142        Vector3 finalDirection = direction_ + sin((rnd(0, angle_))*M_PI/180)*velocityOffset;
143
144                this->explosionEntity_->setVelocity(finalDirection*rnd(minSpeed_,maxSpeed_));
[10752]145        this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
[10837]146        this->explosionEntity_->setScale(size_);
[10752]147
148        this->explosionEntity_->attach(model_);
149
150        this->attach(explosionEntity_);
151
[10786]152        if (GameMode::isMaster())
153        {
[10807]154            this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this)));
[10786]155        }
[10752]156        }
157
158
159
160
161        void ExplosionPart::setMesh(const std::string& newString)
162        {
[10786]163                if(newString != "")
164                {
165                        this->mesh_ = newString;
166                        this->model_->setMeshSource(mesh_);
167                        this->model_->setVisible(false);
168                }
[10752]169        }
170
[10786]171        void ExplosionPart::setEffect1(const std::string& newString)
[10752]172        {
[10786]173                this->effect1_ = newString;
[10752]174        }
175
[10786]176        void ExplosionPart::setEffect2(const std::string& newString)
177        {
178                this->effect2_ = newString;
179        }
180
181        void ExplosionPart::setMinSpeed(float speed)
182        {
183                this->minSpeed_ = speed;
184        }
185
186        void ExplosionPart::setMaxSpeed(float speed)
187        {
188                this->maxSpeed_ = speed;
189        }
190
[10810]191        void ExplosionPart::setOffset(Vector3 newVector)
192        {
193                this->posOffset_ = newVector;
[10837]194                this->explosionEntity_->setPosition(this->getPosition() + this->posOffset_);
[10810]195        }
196
[10837]197        void ExplosionPart::setDirection(Vector3 newDirection)
198        {
199                this->direction_ = newDirection;
200        }
201
202        void ExplosionPart::setAngle(float newAngle)
203        {
204                this->angle_ = newAngle;
205        }
206
207        void ExplosionPart::setSize(float newSize)
208        {
209                this->size_ = newSize;
210        }
211
212        void ExplosionPart::setDelay(float newDelay)
213        {
214                this->delay_ = newDelay;
215        }
216
[10752]217        std::string& ExplosionPart::getMesh()
218        { return this->mesh_; }
219
[10786]220        std::string& ExplosionPart::getEffect1()
221        { return this->effect1_; }
[10752]222
[10786]223        std::string& ExplosionPart::getEffect2()
224        { return this->effect2_; }
[10752]225
[10786]226        float ExplosionPart::getMinSpeed()
227        {
228                return this->minSpeed_;
229        }
230
231        float ExplosionPart::getMaxSpeed()
232        {
233                return this->maxSpeed_;
234        }
235
[10810]236        Vector3 ExplosionPart::getOffset()
237        {
238                return this->posOffset_;
239        }
[10786]240
[10837]241        Vector3 ExplosionPart::getDirection()
242        {
243                return direction_;
244        }
[10786]245
[10837]246        float ExplosionPart::getAngle()
247        {
248                return angle_;
249        }
[10810]250
[10837]251        float ExplosionPart::getSize()
252        {
253                return size_;
254        }
255
256        float ExplosionPart::getDelay()
257        {
258                return delay_;
259        }
260
261
262
[10752]263}
Note: See TracBrowser for help on using the repository browser.