1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * |
---|
4 | * |
---|
5 | * License notice: |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
20 | * |
---|
21 | * Author: |
---|
22 | * Fabian 'x3n' Landau |
---|
23 | * Co-authors: |
---|
24 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | #include "SpaceShip.h" |
---|
29 | #include "Projectile.h" |
---|
30 | |
---|
31 | #include "../../tinyxml/tinyxml.h" |
---|
32 | #include "../../misc/String2Number.h" |
---|
33 | #include "../core/CoreIncludes.h" |
---|
34 | #include "../Orxonox.h" |
---|
35 | |
---|
36 | #include "OgreCamera.h" |
---|
37 | #include <OgreRenderWindow.h> |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | CreateFactory(SpaceShip); |
---|
42 | |
---|
43 | SpaceShip::SpaceShip() |
---|
44 | { |
---|
45 | RegisterObject(SpaceShip); |
---|
46 | |
---|
47 | this->setConfigValues(); |
---|
48 | |
---|
49 | this->setMouseEventCallback_ = false; |
---|
50 | this->bLMousePressed_ = false; |
---|
51 | this->bRMousePressed_ = false; |
---|
52 | this->mouseX_ = 0; |
---|
53 | this->mouseY_ = 0; |
---|
54 | |
---|
55 | this->camNode_ = 0; |
---|
56 | |
---|
57 | this->tt_ = 0; |
---|
58 | this->redNode_ = 0; |
---|
59 | this->greenNode_ = 0; |
---|
60 | this->blinkTime_ = 0; |
---|
61 | |
---|
62 | this->timeToReload_ = 0; |
---|
63 | |
---|
64 | this->maxSpeed_ = 0; |
---|
65 | this->maxSideAndBackSpeed_ = 0; |
---|
66 | this->maxRotation_ = 0; |
---|
67 | this->translationAcceleration_ = 0; |
---|
68 | this->rotationAcceleration_ = 0; |
---|
69 | this->translationDamping_ = 0; |
---|
70 | this->rotationDamping_ = 0; |
---|
71 | |
---|
72 | this->maxRotationRadian_ = 0; |
---|
73 | this->rotationAccelerationRadian_ = 0; |
---|
74 | this->rotationDampingRadian_ = 0; |
---|
75 | this->zeroRadian_ = Radian(0); |
---|
76 | |
---|
77 | this->setRotationAxis(1, 0, 0); |
---|
78 | this->setStatic(false); |
---|
79 | /* |
---|
80 | this->moveForward_ = 0; |
---|
81 | this->rotateUp_ = 0; |
---|
82 | this->rotateDown_ = 0; |
---|
83 | this->rotateRight_ = 0; |
---|
84 | this->rotateLeft_ = 0; |
---|
85 | this->loopRight_ = 0; |
---|
86 | this->loopLeft_ = 0; |
---|
87 | this->brakeForward_ = 0; |
---|
88 | this->brakeRotate_ = 0; |
---|
89 | this->brakeLoop_ = 0; |
---|
90 | this->speedForward_ = 0; |
---|
91 | this->speedRotateUpDown_ = 0; |
---|
92 | this->speedRotateRightLeft_ = 0; |
---|
93 | this->speedLoopRightLeft_ = 0; |
---|
94 | this->maxSpeedForward_ = 0; |
---|
95 | this->maxSpeedRotateUpDown_ = 0; |
---|
96 | this->maxSpeedRotateRightLeft_ = 0; |
---|
97 | this->maxSpeedLoopRightLeft_ = 0; |
---|
98 | this->accelerationForward_ = 0; |
---|
99 | this->accelerationRotateUpDown_ = 0; |
---|
100 | this->accelerationRotateRightLeft_ = 0; |
---|
101 | this->accelerationLoopRightLeft_ = 0; |
---|
102 | |
---|
103 | this->speed = 250; |
---|
104 | this->loop = 100; |
---|
105 | this->rotate = 10; |
---|
106 | this->mouseX = 0; |
---|
107 | this->mouseY = 0; |
---|
108 | this->maxMouseX = 0; |
---|
109 | this->minMouseX = 0; |
---|
110 | this->moved = false; |
---|
111 | |
---|
112 | this->brakeRotate(rotate*10); |
---|
113 | this->brakeLoop(loop); |
---|
114 | */ |
---|
115 | COUT(3) << "Info: SpaceShip was loaded" << std::endl; |
---|
116 | } |
---|
117 | |
---|
118 | SpaceShip::~SpaceShip() |
---|
119 | { |
---|
120 | if (this->tt_) |
---|
121 | delete this->tt_; |
---|
122 | } |
---|
123 | |
---|
124 | void SpaceShip::setConfigValues() |
---|
125 | { |
---|
126 | SetConfigValue(bInvertYAxis_, false); |
---|
127 | SetConfigValue(reloadTime_, 0.125); |
---|
128 | } |
---|
129 | |
---|
130 | void SpaceShip::loadParams(TiXmlElement* xmlElem) |
---|
131 | { |
---|
132 | Model::loadParams(xmlElem); |
---|
133 | |
---|
134 | |
---|
135 | // START CREATING THRUSTER |
---|
136 | this->tt_ = new particle::ParticleInterface(Orxonox::getSingleton()->getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); |
---|
137 | this->tt_->getParticleSystem()->setParameter("local_space","true"); |
---|
138 | this->tt_->newEmitter(); |
---|
139 | /* |
---|
140 | this->tt_->setDirection(Vector3(0,0,1)); |
---|
141 | this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15)); |
---|
142 | this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15)); |
---|
143 | */ |
---|
144 | this->tt_->setDirection(Vector3(-1,0,0)); |
---|
145 | this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1)); |
---|
146 | this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1)); |
---|
147 | this->tt_->setVelocity(50); |
---|
148 | |
---|
149 | emitterRate_ = tt_->getRate(); |
---|
150 | |
---|
151 | Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2"); |
---|
152 | node2->setInheritScale(false); |
---|
153 | tt_->addToSceneNode(node2); |
---|
154 | // END CREATING THRUSTER |
---|
155 | |
---|
156 | // START CREATING BLINKING LIGHTS |
---|
157 | this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); |
---|
158 | this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1); |
---|
159 | |
---|
160 | this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.7, -0.3)); |
---|
161 | this->redNode_->setInheritScale(false); |
---|
162 | this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.7, -0.3)); |
---|
163 | this->greenNode_->setInheritScale(false); |
---|
164 | |
---|
165 | this->redNode_->attachObject(this->redBillboard_.getBillboardSet()); |
---|
166 | this->redNode_->setScale(0.3, 0.3, 0.3); |
---|
167 | |
---|
168 | this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet()); |
---|
169 | this->greenNode_->setScale(0.3, 0.3, 0.3); |
---|
170 | // END CREATING BLINKING LIGHTS |
---|
171 | |
---|
172 | // START of testing crosshair |
---|
173 | this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
174 | this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
175 | |
---|
176 | this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); |
---|
177 | this->chNearNode_->setInheritScale(false); |
---|
178 | this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); |
---|
179 | this->chFarNode_->setInheritScale(false); |
---|
180 | |
---|
181 | this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); |
---|
182 | this->chNearNode_->setScale(0.2, 0.2, 0.2); |
---|
183 | |
---|
184 | this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); |
---|
185 | this->chFarNode_->setScale(0.4, 0.4, 0.4); |
---|
186 | |
---|
187 | // END of testing crosshair |
---|
188 | |
---|
189 | /* |
---|
190 | if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft")) |
---|
191 | { |
---|
192 | std::string forwardStr = xmlElem->Attribute("forward"); |
---|
193 | std::string rotateupdownStr = xmlElem->Attribute("rotateupdown"); |
---|
194 | std::string rotaterightleftStr = xmlElem->Attribute("rotaterightleft"); |
---|
195 | std::string looprightleftStr = xmlElem->Attribute("looprightleft"); |
---|
196 | |
---|
197 | String2Number<float>(this->maxSpeedForward_, forwardStr); |
---|
198 | String2Number<float>(this->maxSpeedRotateUpDown_, rotateupdownStr); |
---|
199 | String2Number<float>(this->maxSpeedRotateRightLeft_, rotaterightleftStr); |
---|
200 | String2Number<float>(this->maxSpeedLoopRightLeft_, looprightleftStr); |
---|
201 | |
---|
202 | COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl; |
---|
203 | } |
---|
204 | */ |
---|
205 | if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp")) |
---|
206 | { |
---|
207 | |
---|
208 | std::string msStr = xmlElem->Attribute("maxSpeed"); |
---|
209 | std::string msabsStr = xmlElem->Attribute("maxSideAndBackSpeed"); |
---|
210 | std::string mrStr = xmlElem->Attribute("maxRotation"); |
---|
211 | std::string taStr = xmlElem->Attribute("transAcc"); |
---|
212 | std::string raStr = xmlElem->Attribute("rotAcc"); |
---|
213 | std::string tdStr = xmlElem->Attribute("transDamp"); |
---|
214 | std::string rdStr = xmlElem->Attribute("rotDamp"); |
---|
215 | |
---|
216 | String2Number<float>(this->maxSpeed_, msStr); |
---|
217 | String2Number<float>(this->maxSideAndBackSpeed_, msabsStr); |
---|
218 | String2Number<float>(this->maxRotation_, mrStr); |
---|
219 | String2Number<float>(this->translationAcceleration_, taStr); |
---|
220 | String2Number<float>(this->rotationAcceleration_, raStr); |
---|
221 | String2Number<float>(this->translationDamping_, tdStr); |
---|
222 | String2Number<float>(this->rotationDamping_, rdStr); |
---|
223 | |
---|
224 | this->maxRotationRadian_ = Radian(this->maxRotation_); |
---|
225 | this->rotationAccelerationRadian_ = Radian(this->rotationAcceleration_); |
---|
226 | this->rotationDampingRadian_ = Radian(this->rotationDamping_); |
---|
227 | |
---|
228 | COUT(4) << "Loader: Initialized SpaceShip" << std::endl; |
---|
229 | } |
---|
230 | |
---|
231 | if (xmlElem->Attribute("camera")) |
---|
232 | { |
---|
233 | Ogre::Camera *cam = Orxonox::getSingleton()->getSceneManager()->createCamera("ShipCam"); |
---|
234 | this->camNode_ = this->getNode()->createChildSceneNode("CamNode"); |
---|
235 | /* |
---|
236 | // node->setInheritOrientation(false); |
---|
237 | cam->setPosition(Vector3(0,50,-150)); |
---|
238 | cam->lookAt(Vector3(0,20,0)); |
---|
239 | cam->roll(Degree(0)); |
---|
240 | */ |
---|
241 | |
---|
242 | cam->setPosition(Vector3(-200,0,35)); |
---|
243 | // cam->setPosition(Vector3(0,-350,0)); |
---|
244 | cam->lookAt(Vector3(0,0,35)); |
---|
245 | cam->roll(Degree(-90)); |
---|
246 | |
---|
247 | this->camNode_->attachObject(cam); |
---|
248 | Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam); |
---|
249 | } |
---|
250 | } |
---|
251 | |
---|
252 | int sgn(float x) |
---|
253 | { |
---|
254 | if (x >= 0) |
---|
255 | return 1; |
---|
256 | else |
---|
257 | return -1; |
---|
258 | } |
---|
259 | |
---|
260 | bool SpaceShip::mouseMoved(const OIS::MouseEvent &e) |
---|
261 | { |
---|
262 | /* |
---|
263 | this->mouseX += e.state.X.rel; |
---|
264 | if (this->bInvertMouse_) |
---|
265 | this->mouseY += e.state.Y.rel; |
---|
266 | else |
---|
267 | this->mouseY -= e.state.Y.rel; |
---|
268 | |
---|
269 | // if(mouseX>maxMouseX) maxMouseX = mouseX; |
---|
270 | // if(mouseX<minMouseX) minMouseX = mouseX; |
---|
271 | // cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl; |
---|
272 | |
---|
273 | this->moved = true; |
---|
274 | */ |
---|
275 | if (this->bRMousePressed_) |
---|
276 | { |
---|
277 | this->camNode_->roll(Degree(-e.state.X.rel * 0.10)); |
---|
278 | this->camNode_->yaw(Degree(e.state.Y.rel * 0.10)); |
---|
279 | } |
---|
280 | else |
---|
281 | { |
---|
282 | float minDimension = e.state.height; |
---|
283 | if (e.state.width < minDimension) |
---|
284 | minDimension = e.state.width; |
---|
285 | |
---|
286 | this->mouseX_ += e.state.X.rel; |
---|
287 | if (this->mouseX_ < -minDimension) |
---|
288 | this->mouseX_ = -minDimension; |
---|
289 | if (this->mouseX_ > minDimension) |
---|
290 | this->mouseX_ = minDimension; |
---|
291 | |
---|
292 | this->mouseY_ += e.state.Y.rel; |
---|
293 | if (this->mouseY_ < -minDimension) |
---|
294 | this->mouseY_ = -minDimension; |
---|
295 | if (this->mouseY_ > minDimension) |
---|
296 | this->mouseY_ = minDimension; |
---|
297 | |
---|
298 | float xRotation = this->mouseX_ / minDimension; |
---|
299 | xRotation = xRotation*xRotation * sgn(xRotation); |
---|
300 | xRotation *= -this->rotationAcceleration_; |
---|
301 | if (xRotation > this->maxRotation_) |
---|
302 | xRotation = this->maxRotation_; |
---|
303 | if (xRotation < -this->maxRotation_) |
---|
304 | xRotation = -this->maxRotation_; |
---|
305 | this->mouseXRotation_ = Radian(xRotation); |
---|
306 | |
---|
307 | float yRotation = this->mouseY_ / minDimension; |
---|
308 | yRotation = yRotation*yRotation * sgn(yRotation); |
---|
309 | yRotation *= this->rotationAcceleration_; |
---|
310 | if (yRotation > this->maxRotation_) |
---|
311 | yRotation = this->maxRotation_; |
---|
312 | if (yRotation < -this->maxRotation_) |
---|
313 | yRotation = -this->maxRotation_; |
---|
314 | this->mouseYRotation_ = Radian(yRotation); |
---|
315 | } |
---|
316 | |
---|
317 | return true; |
---|
318 | } |
---|
319 | |
---|
320 | bool SpaceShip::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
321 | { |
---|
322 | if (id == OIS::MB_Left) |
---|
323 | this->bLMousePressed_ = true; |
---|
324 | else if (id == OIS::MB_Right) |
---|
325 | this->bRMousePressed_ = true; |
---|
326 | |
---|
327 | return true; |
---|
328 | } |
---|
329 | |
---|
330 | bool SpaceShip::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
331 | { |
---|
332 | if (id == OIS::MB_Left) |
---|
333 | this->bLMousePressed_ = false; |
---|
334 | else if (id == OIS::MB_Right) |
---|
335 | { |
---|
336 | this->bRMousePressed_ = false; |
---|
337 | this->camNode_->resetOrientation(); |
---|
338 | } |
---|
339 | |
---|
340 | return true; |
---|
341 | } |
---|
342 | |
---|
343 | void SpaceShip::tick(float dt) |
---|
344 | { |
---|
345 | if (!this->setMouseEventCallback_) |
---|
346 | { |
---|
347 | if (Orxonox::getSingleton()->getMouse()) |
---|
348 | { |
---|
349 | Orxonox::getSingleton()->getMouse()->setEventCallback(this); |
---|
350 | this->setMouseEventCallback_ = true; |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | if (this->redNode_ && this->greenNode_) |
---|
355 | { |
---|
356 | this->blinkTime_ += dt; |
---|
357 | float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0); |
---|
358 | float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0); |
---|
359 | this->redNode_->setScale(redScale, redScale, redScale); |
---|
360 | this->greenNode_->setScale(greenScale, greenScale, greenScale); |
---|
361 | } |
---|
362 | |
---|
363 | if (this->timeToReload_ > 0) |
---|
364 | this->timeToReload_ -= dt; |
---|
365 | else |
---|
366 | this->timeToReload_ = 0; |
---|
367 | |
---|
368 | if (this->bLMousePressed_ && this->timeToReload_ <= 0) |
---|
369 | { |
---|
370 | new Projectile(this); |
---|
371 | this->timeToReload_ = this->reloadTime_; |
---|
372 | } |
---|
373 | |
---|
374 | OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard(); |
---|
375 | OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse(); |
---|
376 | |
---|
377 | mKeyboard->capture(); |
---|
378 | mMouse->capture(); |
---|
379 | |
---|
380 | |
---|
381 | // ##################################### |
---|
382 | // ############# STEERING ############## |
---|
383 | // ##################################### |
---|
384 | |
---|
385 | if (this->velocity_.x > this->maxSpeed_) |
---|
386 | this->velocity_.x = this->maxSpeed_; |
---|
387 | if (this->velocity_.x < -this->maxSideAndBackSpeed_) |
---|
388 | this->velocity_.x = -this->maxSideAndBackSpeed_; |
---|
389 | if (this->velocity_.y > this->maxSideAndBackSpeed_) |
---|
390 | this->velocity_.y = this->maxSideAndBackSpeed_; |
---|
391 | if (this->velocity_.y < -this->maxSideAndBackSpeed_) |
---|
392 | this->velocity_.y = -this->maxSideAndBackSpeed_; |
---|
393 | if (this->rotationRate_ > this->maxRotationRadian_) |
---|
394 | this->rotationRate_ = this->maxRotationRadian_; |
---|
395 | if (this->rotationRate_ < -this->maxRotationRadian_) |
---|
396 | this->rotationRate_ = -this->maxRotationRadian_; |
---|
397 | |
---|
398 | if (this->acceleration_.x == 0) |
---|
399 | { |
---|
400 | if (this->velocity_.x > 0) |
---|
401 | { |
---|
402 | this->velocity_.x -= (this->translationDamping_ * dt); |
---|
403 | if (this->velocity_.x < 0) |
---|
404 | this->velocity_.x = 0; |
---|
405 | } |
---|
406 | else if (this->velocity_.x < 0) |
---|
407 | { |
---|
408 | this->velocity_.x += (this->translationDamping_ * dt); |
---|
409 | if (this->velocity_.x > 0) |
---|
410 | this->velocity_.x = 0; |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | if (this->acceleration_.y == 0) |
---|
415 | { |
---|
416 | if (this->velocity_.y > 0) |
---|
417 | { |
---|
418 | this->velocity_.y -= (this->translationDamping_ * dt); |
---|
419 | if (this->velocity_.y < 0) |
---|
420 | this->velocity_.y = 0; |
---|
421 | } |
---|
422 | else if (this->velocity_.y < 0) |
---|
423 | { |
---|
424 | this->velocity_.y += (this->translationDamping_ * dt); |
---|
425 | if (this->velocity_.y > 0) |
---|
426 | this->velocity_.y = 0; |
---|
427 | } |
---|
428 | } |
---|
429 | |
---|
430 | if (this->momentum_ == this->zeroRadian_) |
---|
431 | { |
---|
432 | if (this->rotationRate_ > this->zeroRadian_) |
---|
433 | { |
---|
434 | this->rotationRate_ -= (this->rotationDampingRadian_ * dt); |
---|
435 | if (this->rotationRate_ < this->zeroRadian_) |
---|
436 | this->rotationRate_ = 0; |
---|
437 | } |
---|
438 | else if (this->rotationRate_ < this->zeroRadian_) |
---|
439 | { |
---|
440 | this->rotationRate_ += (this->rotationDampingRadian_ * dt); |
---|
441 | if (this->rotationRate_ > this->zeroRadian_) |
---|
442 | this->rotationRate_ = 0; |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) |
---|
447 | this->acceleration_.x = this->translationAcceleration_; |
---|
448 | else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) |
---|
449 | this->acceleration_.x = -this->translationAcceleration_; |
---|
450 | else |
---|
451 | this->acceleration_.x = 0; |
---|
452 | |
---|
453 | if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) |
---|
454 | this->acceleration_.y = -this->translationAcceleration_; |
---|
455 | else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) |
---|
456 | this->acceleration_.y = this->translationAcceleration_; |
---|
457 | else |
---|
458 | this->acceleration_.y = 0; |
---|
459 | |
---|
460 | if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q)) |
---|
461 | this->momentum_ = Radian(-this->rotationAccelerationRadian_); |
---|
462 | else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E)) |
---|
463 | this->momentum_ = Radian(this->rotationAccelerationRadian_); |
---|
464 | else |
---|
465 | this->momentum_ = 0; |
---|
466 | |
---|
467 | WorldEntity::tick(dt); |
---|
468 | |
---|
469 | this->roll(this->mouseXRotation_ * dt); |
---|
470 | if (this->bInvertYAxis_) |
---|
471 | this->yaw(Radian(-this->mouseYRotation_ * dt)); |
---|
472 | else |
---|
473 | this->yaw(Radian(this->mouseYRotation_ * dt)); |
---|
474 | |
---|
475 | if (this->acceleration_.x > 0) |
---|
476 | this->tt_->setRate(emitterRate_); |
---|
477 | else |
---|
478 | this->tt_->setRate(0); |
---|
479 | |
---|
480 | /* |
---|
481 | if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) |
---|
482 | this->moveForward(speed); |
---|
483 | else |
---|
484 | this->moveForward(0); |
---|
485 | |
---|
486 | if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) |
---|
487 | this->brakeForward(speed); |
---|
488 | else |
---|
489 | this->brakeForward(speed/10); |
---|
490 | |
---|
491 | if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) |
---|
492 | this->loopRight(loop); |
---|
493 | else |
---|
494 | this->loopRight(0); |
---|
495 | |
---|
496 | if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) |
---|
497 | this->loopLeft(loop); |
---|
498 | else |
---|
499 | this->loopLeft(0); |
---|
500 | |
---|
501 | if(moved) |
---|
502 | { |
---|
503 | if (mouseY<=0) |
---|
504 | this->rotateUp(-mouseY*rotate); |
---|
505 | if (mouseY>0) |
---|
506 | this->rotateDown(mouseY*rotate); |
---|
507 | if (mouseX>0) |
---|
508 | this->rotateRight(mouseX*rotate); |
---|
509 | if (mouseX<=0) |
---|
510 | this->rotateLeft(-mouseX*rotate); |
---|
511 | |
---|
512 | mouseY = 0; |
---|
513 | mouseX = 0; |
---|
514 | moved = false; |
---|
515 | }*/ |
---|
516 | /* else |
---|
517 | { |
---|
518 | this->rotateUp(0); |
---|
519 | this->rotateDown(0); |
---|
520 | this->rotateRight(0); |
---|
521 | this->rotateLeft(0); |
---|
522 | }*/ |
---|
523 | /* |
---|
524 | if(moveForward_ > 0) |
---|
525 | { |
---|
526 | accelerationForward_ = moveForward_; |
---|
527 | if(speedForward_ < maxSpeedForward_) |
---|
528 | speedForward_ += accelerationForward_*dt; |
---|
529 | if(speedForward_ > maxSpeedForward_) |
---|
530 | speedForward_ = maxSpeedForward_; |
---|
531 | } |
---|
532 | |
---|
533 | if(moveForward_ <= 0) |
---|
534 | { |
---|
535 | accelerationForward_ = -brakeForward_; |
---|
536 | if(speedForward_ > 0) |
---|
537 | speedForward_ += accelerationForward_*dt; |
---|
538 | if(speedForward_ < 0) |
---|
539 | speedForward_ = 0; |
---|
540 | } |
---|
541 | |
---|
542 | if(rotateUp_ > 0) |
---|
543 | { |
---|
544 | accelerationRotateUpDown_ = rotateUp_; |
---|
545 | if(speedRotateUpDown_ < maxSpeedRotateUpDown_) |
---|
546 | speedRotateUpDown_ += accelerationRotateUpDown_*dt; |
---|
547 | if(speedRotateUpDown_ > maxSpeedRotateUpDown_) |
---|
548 | speedRotateUpDown_ = maxSpeedRotateUpDown_; |
---|
549 | } |
---|
550 | |
---|
551 | if(rotateDown_ > 0) |
---|
552 | { |
---|
553 | accelerationRotateUpDown_ = rotateDown_; |
---|
554 | if(speedRotateUpDown_ > -maxSpeedRotateUpDown_) |
---|
555 | speedRotateUpDown_ -= accelerationRotateUpDown_*dt; |
---|
556 | if(speedRotateUpDown_ < -maxSpeedRotateUpDown_) |
---|
557 | speedRotateUpDown_ = -maxSpeedRotateUpDown_; |
---|
558 | } |
---|
559 | |
---|
560 | if(rotateUp_ == 0 && rotateDown_ == 0) |
---|
561 | { |
---|
562 | accelerationRotateUpDown_ = brakeRotate_; |
---|
563 | if(speedRotateUpDown_ > 0) |
---|
564 | speedRotateUpDown_ -= accelerationRotateUpDown_*dt; |
---|
565 | if(speedRotateUpDown_ < 0) |
---|
566 | speedRotateUpDown_ += accelerationRotateUpDown_*dt; |
---|
567 | if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt) |
---|
568 | speedRotateUpDown_ = 0; |
---|
569 | } |
---|
570 | |
---|
571 | if(rotateRight_ > 0) |
---|
572 | { |
---|
573 | accelerationRotateRightLeft_ = rotateRight_; |
---|
574 | if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_) |
---|
575 | speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt; |
---|
576 | if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_) |
---|
577 | speedRotateRightLeft_ = -maxSpeedRotateRightLeft_; |
---|
578 | } |
---|
579 | |
---|
580 | if(rotateLeft_ > 0) |
---|
581 | { |
---|
582 | accelerationRotateRightLeft_ = rotateLeft_; |
---|
583 | if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_) |
---|
584 | speedRotateRightLeft_ += accelerationRotateRightLeft_*dt; |
---|
585 | if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_) |
---|
586 | speedRotateRightLeft_ = maxSpeedRotateRightLeft_; |
---|
587 | } |
---|
588 | |
---|
589 | if(rotateRight_ == 0 && rotateLeft_ == 0) |
---|
590 | { |
---|
591 | accelerationRotateRightLeft_ = brakeRotate_; |
---|
592 | if(speedRotateRightLeft_ > 0) |
---|
593 | speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt; |
---|
594 | if(speedRotateRightLeft_ < 0) |
---|
595 | speedRotateRightLeft_ += accelerationRotateRightLeft_*dt; |
---|
596 | if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt) |
---|
597 | speedRotateRightLeft_ = 0; |
---|
598 | } |
---|
599 | |
---|
600 | if(loopRight_ > 0) |
---|
601 | { |
---|
602 | accelerationLoopRightLeft_ = loopRight_; |
---|
603 | if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_) |
---|
604 | speedLoopRightLeft_ += accelerationLoopRightLeft_*dt; |
---|
605 | if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_) |
---|
606 | speedLoopRightLeft_ = maxSpeedLoopRightLeft_; |
---|
607 | } |
---|
608 | |
---|
609 | if(loopLeft_ > 0) |
---|
610 | { |
---|
611 | accelerationLoopRightLeft_ = loopLeft_; |
---|
612 | if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_) |
---|
613 | speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt; |
---|
614 | if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_) |
---|
615 | speedLoopRightLeft_ = -maxSpeedLoopRightLeft_; |
---|
616 | } |
---|
617 | |
---|
618 | if(loopLeft_ == 0 && loopRight_ == 0) |
---|
619 | { |
---|
620 | accelerationLoopRightLeft_ = brakeLoop_; |
---|
621 | if(speedLoopRightLeft_ > 0) |
---|
622 | speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt; |
---|
623 | if(speedLoopRightLeft_ < 0) |
---|
624 | speedLoopRightLeft_ += accelerationLoopRightLeft_*dt; |
---|
625 | if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt) |
---|
626 | speedLoopRightLeft_ = 0; |
---|
627 | } |
---|
628 | |
---|
629 | Vector3 transVector = Vector3::ZERO; |
---|
630 | */ |
---|
631 | /* |
---|
632 | transVector.z = 1; |
---|
633 | this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL); |
---|
634 | this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL); |
---|
635 | this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
636 | this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
637 | */ |
---|
638 | /* |
---|
639 | transVector.x = 1; |
---|
640 | this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL); |
---|
641 | this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL); |
---|
642 | this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
643 | this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
644 | */ |
---|
645 | } |
---|
646 | /* |
---|
647 | void SpaceShip::moveForward(float moveForward) { |
---|
648 | moveForward_ = moveForward; |
---|
649 | } |
---|
650 | |
---|
651 | void SpaceShip::rotateUp(float rotateUp) { |
---|
652 | rotateUp_ = rotateUp; |
---|
653 | } |
---|
654 | |
---|
655 | void SpaceShip::rotateDown(float rotateDown) { |
---|
656 | rotateDown_ = rotateDown; |
---|
657 | } |
---|
658 | |
---|
659 | void SpaceShip::rotateLeft(float rotateLeft) { |
---|
660 | rotateLeft_ = rotateLeft; |
---|
661 | } |
---|
662 | |
---|
663 | void SpaceShip::rotateRight(float rotateRight) { |
---|
664 | rotateRight_ = rotateRight; |
---|
665 | } |
---|
666 | |
---|
667 | void SpaceShip::loopLeft(float loopLeft) { |
---|
668 | loopLeft_ = loopLeft; |
---|
669 | } |
---|
670 | |
---|
671 | void SpaceShip::loopRight(float loopRight) { |
---|
672 | loopRight_ = loopRight; |
---|
673 | } |
---|
674 | |
---|
675 | void SpaceShip::brakeForward(float brakeForward) { |
---|
676 | brakeForward_ = brakeForward; |
---|
677 | } |
---|
678 | |
---|
679 | void SpaceShip::brakeRotate(float brakeRotate) { |
---|
680 | brakeRotate_ = brakeRotate; |
---|
681 | } |
---|
682 | |
---|
683 | void SpaceShip::brakeLoop(float brakeLoop) { |
---|
684 | brakeLoop_ = brakeLoop; |
---|
685 | } |
---|
686 | |
---|
687 | void SpaceShip::maxSpeedForward(float maxSpeedForward) { |
---|
688 | maxSpeedForward_ = maxSpeedForward; |
---|
689 | } |
---|
690 | |
---|
691 | void SpaceShip::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) { |
---|
692 | maxSpeedRotateUpDown_ = maxSpeedRotateUpDown; |
---|
693 | } |
---|
694 | |
---|
695 | void SpaceShip::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) { |
---|
696 | maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft; |
---|
697 | } |
---|
698 | |
---|
699 | void SpaceShip::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) { |
---|
700 | maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; |
---|
701 | } |
---|
702 | */ |
---|
703 | } |
---|