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 | |
---|
31 | #include "ExplosionPart.h" |
---|
32 | #include "core/XMLPort.h" |
---|
33 | |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | |
---|
38 | RegisterClass(ExplosionPart); |
---|
39 | |
---|
40 | ExplosionPart::ExplosionPart(Context* context) : MovableEntity(context) |
---|
41 | { |
---|
42 | RegisterObject(ExplosionPart); |
---|
43 | this->bStop_ = false; |
---|
44 | this->LOD_ = LODParticle::Normal; |
---|
45 | this->mesh_ = ""; |
---|
46 | this->effect1_ = ""; |
---|
47 | this->effect2_ = ""; |
---|
48 | this->model_= new Model(this->getContext()); |
---|
49 | this->effect1Particle_= NULL; |
---|
50 | this->effect2Particle_= NULL; |
---|
51 | this->explosionEntity_ = new MovableEntity(this->getContext()); |
---|
52 | this->posOffset_ = Vector3::ZERO; |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | ExplosionPart::~ExplosionPart() |
---|
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 | |
---|
77 | void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
78 | { |
---|
79 | SUPER(ExplosionPart, XMLPort, xmlelement, mode); |
---|
80 | |
---|
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 | } |
---|
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 | |
---|
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 | } |
---|
129 | |
---|
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 | } |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | |
---|
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 | |
---|
147 | Vector3 finalDirection = direction_ + sin((rnd(0, angle_))*math::pi/180)*velocityOffset; |
---|
148 | |
---|
149 | this->explosionEntity_->setVelocity(finalDirection*rnd(minSpeed_,maxSpeed_)); |
---|
150 | this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); |
---|
151 | this->explosionEntity_->setScale(this->getScale() * 4); |
---|
152 | |
---|
153 | |
---|
154 | this->explosionEntity_->attach(model_); |
---|
155 | |
---|
156 | |
---|
157 | this->attach(explosionEntity_); |
---|
158 | |
---|
159 | if (GameMode::isMaster()) |
---|
160 | { |
---|
161 | this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this))); |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | |
---|
167 | |
---|
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 | } |
---|
177 | |
---|
178 | void ExplosionPart::setEffect1(const std::string& newString) |
---|
179 | { |
---|
180 | this->effect1_ = newString; |
---|
181 | } |
---|
182 | |
---|
183 | void ExplosionPart::setEffect2(const std::string& newString) |
---|
184 | { |
---|
185 | this->effect2_ = newString; |
---|
186 | } |
---|
187 | |
---|
188 | void ExplosionPart::setMinSpeed(float speed) |
---|
189 | { |
---|
190 | this->minSpeed_ = speed; |
---|
191 | } |
---|
192 | |
---|
193 | void ExplosionPart::setMaxSpeed(float speed) |
---|
194 | { |
---|
195 | this->maxSpeed_ = speed; |
---|
196 | } |
---|
197 | |
---|
198 | void ExplosionPart::setOffset(Vector3 newVector) |
---|
199 | { |
---|
200 | this->posOffset_ = newVector; |
---|
201 | this->explosionEntity_->setPosition(this->getPosition() + this->posOffset_ / this->getScale()); |
---|
202 | } |
---|
203 | |
---|
204 | void ExplosionPart::setDirection(Vector3 newDirection) |
---|
205 | { |
---|
206 | this->direction_ = newDirection; |
---|
207 | } |
---|
208 | |
---|
209 | void ExplosionPart::setAngle(float newAngle) |
---|
210 | { |
---|
211 | this->angle_ = newAngle; |
---|
212 | } |
---|
213 | |
---|
214 | void ExplosionPart::setDelay(float newDelay) |
---|
215 | { |
---|
216 | this->delay_ = newDelay; |
---|
217 | } |
---|
218 | |
---|
219 | std::string& ExplosionPart::getMesh() |
---|
220 | { return this->mesh_; } |
---|
221 | |
---|
222 | std::string& ExplosionPart::getEffect1() |
---|
223 | { return this->effect1_; } |
---|
224 | |
---|
225 | std::string& ExplosionPart::getEffect2() |
---|
226 | { return this->effect2_; } |
---|
227 | |
---|
228 | float ExplosionPart::getMinSpeed() |
---|
229 | { |
---|
230 | return this->minSpeed_; |
---|
231 | } |
---|
232 | |
---|
233 | float ExplosionPart::getMaxSpeed() |
---|
234 | { |
---|
235 | return this->maxSpeed_; |
---|
236 | } |
---|
237 | |
---|
238 | Vector3 ExplosionPart::getOffset() |
---|
239 | { |
---|
240 | return this->posOffset_; |
---|
241 | } |
---|
242 | |
---|
243 | Vector3 ExplosionPart::getDirection() |
---|
244 | { |
---|
245 | return direction_; |
---|
246 | } |
---|
247 | |
---|
248 | float ExplosionPart::getAngle() |
---|
249 | { |
---|
250 | return angle_; |
---|
251 | } |
---|
252 | |
---|
253 | float ExplosionPart::getDelay() |
---|
254 | { |
---|
255 | return delay_; |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | |
---|
260 | } |
---|