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
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                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);
90        }
91
92
93        void ExplosionPart::Explode()
94        {
95                this->destroyTimer_.setTimer(delay_, false, createExecutor(createFunctor(&ExplosionPart::ActuallyExplode, this)));
96        }
97
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);
106
107        if (GameMode::isMaster())
108        {
109            this->bStop_ = true;
110            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionPart::destroy, this)));
111        }
112        }
113
114        void ExplosionPart::ActuallyExplode()
115        {
116                this->model_->setVisible(true);
117
118                //this->explosionEntity_->setSyncMode(0);
119
120                //this->model_->setSyncMode(0);
121
122                if(effect1_ != "")
123                {
124                        this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_);
125                        this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem());
126                }
127
128                if(effect2_ != "")
129                {
130                        this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_);
131                        this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem());
132                }
133
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_));
145        this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
146        this->explosionEntity_->setScale(size_);
147
148        this->explosionEntity_->attach(model_);
149
150        this->attach(explosionEntity_);
151
152        if (GameMode::isMaster())
153        {
154            this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this)));
155        }
156        }
157
158
159
160
161        void ExplosionPart::setMesh(const std::string& newString)
162        {
163                if(newString != "")
164                {
165                        this->mesh_ = newString;
166                        this->model_->setMeshSource(mesh_);
167                        this->model_->setVisible(false);
168                }
169        }
170
171        void ExplosionPart::setEffect1(const std::string& newString)
172        {
173                this->effect1_ = newString;
174        }
175
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
191        void ExplosionPart::setOffset(Vector3 newVector)
192        {
193                this->posOffset_ = newVector;
194                this->explosionEntity_->setPosition(this->getPosition() + this->posOffset_);
195        }
196
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
217        std::string& ExplosionPart::getMesh()
218        { return this->mesh_; }
219
220        std::string& ExplosionPart::getEffect1()
221        { return this->effect1_; }
222
223        std::string& ExplosionPart::getEffect2()
224        { return this->effect2_; }
225
226        float ExplosionPart::getMinSpeed()
227        {
228                return this->minSpeed_;
229        }
230
231        float ExplosionPart::getMaxSpeed()
232        {
233                return this->maxSpeed_;
234        }
235
236        Vector3 ExplosionPart::getOffset()
237        {
238                return this->posOffset_;
239        }
240
241        Vector3 ExplosionPart::getDirection()
242        {
243                return direction_;
244        }
245
246        float ExplosionPart::getAngle()
247        {
248                return angle_;
249        }
250
251        float ExplosionPart::getSize()
252        {
253                return size_;
254        }
255
256        float ExplosionPart::getDelay()
257        {
258                return delay_;
259        }
260
261
262
263}
Note: See TracBrowser for help on using the repository browser.