Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10810 was 10810, checked in by vaydin, 8 years ago

added offset option for explosion

File size: 5.5 KB
Line 
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_ = "";
45                this->effect1_ = "";
46                this->effect2_ = "";
47                this->model_= new Model(this->getContext());
48                this->effect1Particle_= NULL;
49                this->effect2Particle_= NULL;
50                this->explosionEntity_ = new MovableEntity(this->getContext());
51                this->posOffset_ = Vector3::ZERO;
52
53
54
55        }
56
57
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
76        void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)
77        {
78                SUPER(ExplosionPart, XMLPort, xmlelement, mode);
79
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("");
85                XMLPortParam(ExplosionPart, "offset", setOffset, getOffset, xmlelement, mode).defaultValues(Vector3::ZERO);
86
87
88        }
89
90
91        void ExplosionPart::Explode()
92        {
93                orxout() << "Explode" << endl;
94
95
96
97                this->model_->setVisible(true);
98
99                //this->explosionEntity_->setSyncMode(0);
100
101                //this->model_->setSyncMode(0);
102
103                if(effect1_ != "")
104                {
105                        this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_);
106                        this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem());
107                }
108
109                if(effect2_ != "")
110                {
111                        this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_);
112                        this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem());
113                }       
114
115                this->explosionEntity_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(minSpeed_,maxSpeed_));
116        this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
117        this->explosionEntity_->setScale(4);
118
119        this->explosionEntity_->attach(model_);
120
121        this->attach(explosionEntity_);
122
123        if (GameMode::isMaster())
124        {
125            this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this)));
126        }
127
128        }
129
130        void ExplosionPart::stop()
131        {
132                if (this->effect1Particle_)
133            this->effect1Particle_->setEnabled(false);
134        if (this->effect2Particle_)
135            this->effect2Particle_->setEnabled(false);
136        if (this->model_)
137            this->model_->setVisible(false);
138
139        if (GameMode::isMaster())
140        {
141            this->bStop_ = true;
142            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionPart::destroy, this)));
143        }
144        }
145
146
147
148
149        void ExplosionPart::setMesh(const std::string& newString)
150        {
151                if(newString != "")
152                {
153                        this->mesh_ = newString;
154                        this->model_->setMeshSource(mesh_);
155                        this->model_->setVisible(false);
156                }
157        }
158
159        void ExplosionPart::setEffect1(const std::string& newString)
160        {
161                this->effect1_ = newString;
162        }
163
164        void ExplosionPart::setEffect2(const std::string& newString)
165        {
166                this->effect2_ = newString;
167        }
168
169        void ExplosionPart::setMinSpeed(float speed)
170        {
171                this->minSpeed_ = speed;
172        }
173
174        void ExplosionPart::setMaxSpeed(float speed)
175        {
176                this->maxSpeed_ = speed;
177        }
178
179        void ExplosionPart::setOffset(Vector3 newVector)
180        {
181                this->posOffset_ = newVector;
182                this->setPosition(this->getPosition() + this->posOffset_);
183        }
184
185        std::string& ExplosionPart::getMesh()
186        { return this->mesh_; }
187
188        std::string& ExplosionPart::getEffect1()
189        { return this->effect1_; }
190
191        std::string& ExplosionPart::getEffect2()
192        { return this->effect2_; }
193
194        float ExplosionPart::getMinSpeed()
195        {
196                return this->minSpeed_;
197        }
198
199        float ExplosionPart::getMaxSpeed()
200        {
201                return this->maxSpeed_;
202        }
203
204        Vector3 ExplosionPart::getOffset()
205        {
206                return this->posOffset_;
207        }
208
209
210
211}
Note: See TracBrowser for help on using the repository browser.