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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "SpaceShip.h" |
---|
31 | |
---|
32 | #include <string> |
---|
33 | |
---|
34 | #include <OIS/OIS.h> |
---|
35 | #include <OgreCamera.h> |
---|
36 | #include <OgreRenderWindow.h> |
---|
37 | #include <OgreParticleSystem.h> |
---|
38 | #include <OgreSceneNode.h> |
---|
39 | |
---|
40 | #include "util/tinyxml/tinyxml.h" |
---|
41 | #include "util/Convert.h" |
---|
42 | #include "util/Math.h" |
---|
43 | #include "core/CoreIncludes.h" |
---|
44 | #include "core/ConfigValueIncludes.h" |
---|
45 | #include "core/Debug.h" |
---|
46 | #include "GraphicsEngine.h" |
---|
47 | #include "core/InputManager.h" |
---|
48 | #include "particle/ParticleInterface.h" |
---|
49 | #include "Projectile.h" |
---|
50 | #include "core/XMLPort.h" |
---|
51 | #include "core/ConsoleCommand.h" |
---|
52 | #include "network/Client.h" |
---|
53 | |
---|
54 | namespace orxonox |
---|
55 | { |
---|
56 | ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false); |
---|
57 | ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false); |
---|
58 | ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false); |
---|
59 | ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false); |
---|
60 | |
---|
61 | CreateFactory(SpaceShip); |
---|
62 | |
---|
63 | SpaceShip* SpaceShip::instance_s; |
---|
64 | |
---|
65 | SpaceShip::SpaceShip() |
---|
66 | { |
---|
67 | RegisterObject(SpaceShip); |
---|
68 | this->registerAllVariables(); |
---|
69 | |
---|
70 | SpaceShip::instance_s = this; |
---|
71 | |
---|
72 | this->setConfigValues(); |
---|
73 | |
---|
74 | this->setMouseEventCallback_ = false; |
---|
75 | this->bLMousePressed_ = false; |
---|
76 | this->bRMousePressed_ = false; |
---|
77 | this->mouseX_ = 0; |
---|
78 | this->mouseY_ = 0; |
---|
79 | |
---|
80 | this->camNode_ = 0; |
---|
81 | |
---|
82 | this->tt_ = 0; |
---|
83 | this->redNode_ = 0; |
---|
84 | this->greenNode_ = 0; |
---|
85 | this->blinkTime_ = 0; |
---|
86 | |
---|
87 | this->timeToReload_ = 0; |
---|
88 | |
---|
89 | this->maxSpeed_ = 0; |
---|
90 | this->maxSideAndBackSpeed_ = 0; |
---|
91 | this->maxRotation_ = 0; |
---|
92 | this->translationAcceleration_ = 0; |
---|
93 | this->rotationAcceleration_ = 0; |
---|
94 | this->translationDamping_ = 0; |
---|
95 | this->rotationDamping_ = 0; |
---|
96 | |
---|
97 | this->maxRotationRadian_ = 0; |
---|
98 | this->rotationAccelerationRadian_ = 0; |
---|
99 | this->rotationDampingRadian_ = 0; |
---|
100 | this->zeroRadian_ = Radian(0); |
---|
101 | |
---|
102 | this->setRotationAxis(1, 0, 0); |
---|
103 | this->setStatic(false); |
---|
104 | /* |
---|
105 | this->moveForward_ = 0; |
---|
106 | this->rotateUp_ = 0; |
---|
107 | this->rotateDown_ = 0; |
---|
108 | this->rotateRight_ = 0; |
---|
109 | this->rotateLeft_ = 0; |
---|
110 | this->loopRight_ = 0; |
---|
111 | this->loopLeft_ = 0; |
---|
112 | this->brakeForward_ = 0; |
---|
113 | this->brakeRotate_ = 0; |
---|
114 | this->brakeLoop_ = 0; |
---|
115 | this->speedForward_ = 0; |
---|
116 | this->speedRotateUpDown_ = 0; |
---|
117 | this->speedRotateRightLeft_ = 0; |
---|
118 | this->speedLoopRightLeft_ = 0; |
---|
119 | this->maxSpeedForward_ = 0; |
---|
120 | this->maxSpeedRotateUpDown_ = 0; |
---|
121 | this->maxSpeedRotateRightLeft_ = 0; |
---|
122 | this->maxSpeedLoopRightLeft_ = 0; |
---|
123 | this->accelerationForward_ = 0; |
---|
124 | this->accelerationRotateUpDown_ = 0; |
---|
125 | this->accelerationRotateRightLeft_ = 0; |
---|
126 | this->accelerationLoopRightLeft_ = 0; |
---|
127 | |
---|
128 | this->speed = 250; |
---|
129 | this->loop = 100; |
---|
130 | this->rotate = 10; |
---|
131 | this->mouseX = 0; |
---|
132 | this->mouseY = 0; |
---|
133 | this->maxMouseX = 0; |
---|
134 | this->minMouseX = 0; |
---|
135 | this->moved = false; |
---|
136 | |
---|
137 | this->brakeRotate(rotate*10); |
---|
138 | this->brakeLoop(loop); |
---|
139 | */ |
---|
140 | // this->create(); |
---|
141 | |
---|
142 | |
---|
143 | COUT(3) << "Info: SpaceShip was loaded" << std::endl; |
---|
144 | } |
---|
145 | |
---|
146 | SpaceShip::~SpaceShip() |
---|
147 | { |
---|
148 | if (this->tt_) |
---|
149 | delete this->tt_; |
---|
150 | } |
---|
151 | |
---|
152 | bool SpaceShip::create(){ |
---|
153 | if(Model::create()) |
---|
154 | this->init(); |
---|
155 | else |
---|
156 | return false; |
---|
157 | return true; |
---|
158 | } |
---|
159 | |
---|
160 | void SpaceShip::registerAllVariables(){ |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | void SpaceShip::init() |
---|
167 | { |
---|
168 | createCamera(); |
---|
169 | // START CREATING THRUSTER |
---|
170 | this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); |
---|
171 | this->tt_->getParticleSystem()->setParameter("local_space","true"); |
---|
172 | this->tt_->newEmitter(); |
---|
173 | /* |
---|
174 | this->tt_->setDirection(Vector3(0,0,1)); |
---|
175 | this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15)); |
---|
176 | this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15)); |
---|
177 | */ |
---|
178 | this->tt_->setDirection(Vector3(-1,0,0)); |
---|
179 | this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1)); |
---|
180 | this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1)); |
---|
181 | this->tt_->setVelocity(50); |
---|
182 | |
---|
183 | emitterRate_ = tt_->getRate(); |
---|
184 | |
---|
185 | Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2"); |
---|
186 | node2->setInheritScale(false); |
---|
187 | tt_->addToSceneNode(node2); |
---|
188 | // END CREATING THRUSTER |
---|
189 | |
---|
190 | // START CREATING BLINKING LIGHTS |
---|
191 | this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); |
---|
192 | this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1); |
---|
193 | |
---|
194 | this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.7, -0.3)); |
---|
195 | this->redNode_->setInheritScale(false); |
---|
196 | this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.7, -0.3)); |
---|
197 | this->greenNode_->setInheritScale(false); |
---|
198 | |
---|
199 | this->redNode_->attachObject(this->redBillboard_.getBillboardSet()); |
---|
200 | this->redNode_->setScale(0.3, 0.3, 0.3); |
---|
201 | |
---|
202 | this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet()); |
---|
203 | this->greenNode_->setScale(0.3, 0.3, 0.3); |
---|
204 | // END CREATING BLINKING LIGHTS |
---|
205 | |
---|
206 | // START of testing crosshair |
---|
207 | this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
208 | this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
209 | |
---|
210 | this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); |
---|
211 | this->chNearNode_->setInheritScale(false); |
---|
212 | this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); |
---|
213 | this->chFarNode_->setInheritScale(false); |
---|
214 | |
---|
215 | this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); |
---|
216 | this->chNearNode_->setScale(0.2, 0.2, 0.2); |
---|
217 | |
---|
218 | this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); |
---|
219 | this->chFarNode_->setScale(0.4, 0.4, 0.4); |
---|
220 | |
---|
221 | // END of testing crosshair |
---|
222 | } |
---|
223 | |
---|
224 | void SpaceShip::setConfigValues() |
---|
225 | { |
---|
226 | SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); |
---|
227 | SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds"); |
---|
228 | SetConfigValue(testvector_, Vector3()).description("asdfblah"); |
---|
229 | } |
---|
230 | |
---|
231 | void SpaceShip::loadParams(TiXmlElement* xmlElem) |
---|
232 | { |
---|
233 | Model::loadParams(xmlElem); |
---|
234 | this->create(); |
---|
235 | /* |
---|
236 | if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft")) |
---|
237 | { |
---|
238 | std::string forwardStr = xmlElem->Attribute("forward"); |
---|
239 | std::string rotateupdownStr = xmlElem->Attribute("rotateupdown"); |
---|
240 | std::string rotaterightleftStr = xmlElem->Attribute("rotaterightleft"); |
---|
241 | std::string looprightleftStr = xmlElem->Attribute("looprightleft"); |
---|
242 | |
---|
243 | String2Number<float>(this->maxSpeedForward_, forwardStr); |
---|
244 | String2Number<float>(this->maxSpeedRotateUpDown_, rotateupdownStr); |
---|
245 | String2Number<float>(this->maxSpeedRotateRightLeft_, rotaterightleftStr); |
---|
246 | String2Number<float>(this->maxSpeedLoopRightLeft_, looprightleftStr); |
---|
247 | |
---|
248 | COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl; |
---|
249 | } |
---|
250 | */ |
---|
251 | if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp")) |
---|
252 | { |
---|
253 | |
---|
254 | std::string msStr = xmlElem->Attribute("maxSpeed"); |
---|
255 | std::string msabsStr = xmlElem->Attribute("maxSideAndBackSpeed"); |
---|
256 | std::string mrStr = xmlElem->Attribute("maxRotation"); |
---|
257 | std::string taStr = xmlElem->Attribute("transAcc"); |
---|
258 | std::string raStr = xmlElem->Attribute("rotAcc"); |
---|
259 | std::string tdStr = xmlElem->Attribute("transDamp"); |
---|
260 | std::string rdStr = xmlElem->Attribute("rotDamp"); |
---|
261 | |
---|
262 | convertValue<std::string, float>(&this->maxSpeed_, msStr); |
---|
263 | convertValue<std::string, float>(&this->maxSideAndBackSpeed_, msabsStr); |
---|
264 | convertValue<std::string, float>(&this->maxRotation_, mrStr); |
---|
265 | convertValue<std::string, float>(&this->translationAcceleration_, taStr); |
---|
266 | convertValue<std::string, float>(&this->rotationAcceleration_, raStr); |
---|
267 | convertValue<std::string, float>(&this->translationDamping_, tdStr); |
---|
268 | convertValue<std::string, float>(&this->rotationDamping_, rdStr); |
---|
269 | |
---|
270 | this->maxRotationRadian_ = Radian(this->maxRotation_); |
---|
271 | this->rotationAccelerationRadian_ = Radian(this->rotationAcceleration_); |
---|
272 | this->rotationDampingRadian_ = Radian(this->rotationDamping_); |
---|
273 | |
---|
274 | COUT(4) << "Loader: Initialized SpaceShip" << std::endl; |
---|
275 | } |
---|
276 | |
---|
277 | if (xmlElem->Attribute("camera")) |
---|
278 | { |
---|
279 | this->setCamera(); |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | void SpaceShip::setCamera(const std::string& camera) |
---|
284 | { |
---|
285 | // change camera attributes here, if you want to ;) |
---|
286 | } |
---|
287 | |
---|
288 | void SpaceShip::createCamera(){ |
---|
289 | Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam"); |
---|
290 | this->camNode_ = this->getNode()->createChildSceneNode("CamNode"); |
---|
291 | /* |
---|
292 | // node->setInheritOrientation(false); |
---|
293 | cam->setPosition(Vector3(0,50,-150)); |
---|
294 | cam->lookAt(Vector3(0,20,0)); |
---|
295 | cam->roll(Degree(0)); |
---|
296 | */ |
---|
297 | |
---|
298 | cam->setPosition(Vector3(-200,0,35)); |
---|
299 | // cam->setPosition(Vector3(0,-350,0)); |
---|
300 | cam->lookAt(Vector3(0,0,35)); |
---|
301 | cam->roll(Degree(-90)); |
---|
302 | |
---|
303 | this->camNode_->attachObject(cam); |
---|
304 | GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam); |
---|
305 | |
---|
306 | } |
---|
307 | |
---|
308 | void SpaceShip::setMaxSpeed(float value) |
---|
309 | { this->maxSpeed_ = value; } |
---|
310 | void SpaceShip::setMaxSideAndBackSpeed(float value) |
---|
311 | { this->maxSideAndBackSpeed_ = value; } |
---|
312 | void SpaceShip::setMaxRotation(float value) |
---|
313 | { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); } |
---|
314 | void SpaceShip::setTransAcc(float value) |
---|
315 | { this->translationAcceleration_ = value; } |
---|
316 | void SpaceShip::setRotAcc(float value) |
---|
317 | { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); } |
---|
318 | void SpaceShip::setTransDamp(float value) |
---|
319 | { this->translationDamping_ = value; } |
---|
320 | void SpaceShip::setRotDamp(float value) |
---|
321 | { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); } |
---|
322 | |
---|
323 | /** |
---|
324 | @brief XML loading and saving. |
---|
325 | @param xmlelement The XML-element |
---|
326 | @param loading Loading (true) or saving (false) |
---|
327 | @return The XML-element |
---|
328 | */ |
---|
329 | void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
330 | { |
---|
331 | Model::XMLPort(xmlelement, mode); |
---|
332 | |
---|
333 | XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode); |
---|
334 | XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode); |
---|
335 | XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode); |
---|
336 | XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode); |
---|
337 | XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode); |
---|
338 | XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode); |
---|
339 | XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); |
---|
340 | XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); |
---|
341 | } |
---|
342 | |
---|
343 | int sgn(float x) |
---|
344 | { |
---|
345 | if (x >= 0) |
---|
346 | return 1; |
---|
347 | else |
---|
348 | return -1; |
---|
349 | } |
---|
350 | |
---|
351 | bool SpaceShip::mouseMoved(const OIS::MouseEvent &e) |
---|
352 | { |
---|
353 | /* |
---|
354 | this->mouseX += e.state.X.rel; |
---|
355 | if (this->bInvertMouse_) |
---|
356 | this->mouseY += e.state.Y.rel; |
---|
357 | else |
---|
358 | this->mouseY -= e.state.Y.rel; |
---|
359 | |
---|
360 | // if(mouseX>maxMouseX) maxMouseX = mouseX; |
---|
361 | // if(mouseX<minMouseX) minMouseX = mouseX; |
---|
362 | // cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl; |
---|
363 | |
---|
364 | this->moved = true; |
---|
365 | */ |
---|
366 | if (this->bRMousePressed_) |
---|
367 | { |
---|
368 | this->camNode_->roll(Degree(-e.state.X.rel * 0.10)); |
---|
369 | this->camNode_->yaw(Degree(e.state.Y.rel * 0.10)); |
---|
370 | } |
---|
371 | else |
---|
372 | { |
---|
373 | float minDimension = e.state.height; |
---|
374 | if (e.state.width < minDimension) |
---|
375 | minDimension = e.state.width; |
---|
376 | |
---|
377 | this->mouseX_ += e.state.X.rel; |
---|
378 | if (this->mouseX_ < -minDimension) |
---|
379 | this->mouseX_ = -minDimension; |
---|
380 | if (this->mouseX_ > minDimension) |
---|
381 | this->mouseX_ = minDimension; |
---|
382 | |
---|
383 | this->mouseY_ += e.state.Y.rel; |
---|
384 | if (this->mouseY_ < -minDimension) |
---|
385 | this->mouseY_ = -minDimension; |
---|
386 | if (this->mouseY_ > minDimension) |
---|
387 | this->mouseY_ = minDimension; |
---|
388 | |
---|
389 | float xRotation = this->mouseX_ / minDimension; |
---|
390 | xRotation = xRotation*xRotation * sgn(xRotation); |
---|
391 | xRotation *= -this->rotationAcceleration_; |
---|
392 | if (xRotation > this->maxRotation_) |
---|
393 | xRotation = this->maxRotation_; |
---|
394 | if (xRotation < -this->maxRotation_) |
---|
395 | xRotation = -this->maxRotation_; |
---|
396 | this->mouseXRotation_ = Radian(xRotation); |
---|
397 | |
---|
398 | float yRotation = this->mouseY_ / minDimension; |
---|
399 | yRotation = yRotation*yRotation * sgn(yRotation); |
---|
400 | yRotation *= this->rotationAcceleration_; |
---|
401 | if (yRotation > this->maxRotation_) |
---|
402 | yRotation = this->maxRotation_; |
---|
403 | if (yRotation < -this->maxRotation_) |
---|
404 | yRotation = -this->maxRotation_; |
---|
405 | this->mouseYRotation_ = Radian(yRotation); |
---|
406 | } |
---|
407 | |
---|
408 | return true; |
---|
409 | } |
---|
410 | |
---|
411 | bool SpaceShip::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
412 | { |
---|
413 | if (id == OIS::MB_Left) |
---|
414 | this->bLMousePressed_ = true; |
---|
415 | else if (id == OIS::MB_Right) |
---|
416 | this->bRMousePressed_ = true; |
---|
417 | |
---|
418 | return true; |
---|
419 | } |
---|
420 | |
---|
421 | bool SpaceShip::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) |
---|
422 | { |
---|
423 | if (id == OIS::MB_Left) |
---|
424 | this->bLMousePressed_ = false; |
---|
425 | else if (id == OIS::MB_Right) |
---|
426 | { |
---|
427 | this->bRMousePressed_ = false; |
---|
428 | this->camNode_->resetOrientation(); |
---|
429 | } |
---|
430 | |
---|
431 | return true; |
---|
432 | } |
---|
433 | |
---|
434 | void SpaceShip::tick(float dt) |
---|
435 | { |
---|
436 | // only do this if not client TODO: remove this hack |
---|
437 | if (!network::Client::getSingleton() && InputManager::getSingleton().getMouse()->getEventCallback() != this) |
---|
438 | { |
---|
439 | if (InputManager::getSingleton().getMouse()) |
---|
440 | { |
---|
441 | InputManager::getSingleton().getMouse()->setEventCallback(this); |
---|
442 | this->setMouseEventCallback_ = true; |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | if (this->redNode_ && this->greenNode_) |
---|
447 | { |
---|
448 | this->blinkTime_ += dt; |
---|
449 | float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0); |
---|
450 | float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0); |
---|
451 | this->redNode_->setScale(redScale, redScale, redScale); |
---|
452 | this->greenNode_->setScale(greenScale, greenScale, greenScale); |
---|
453 | } |
---|
454 | |
---|
455 | if (this->timeToReload_ > 0) |
---|
456 | this->timeToReload_ -= dt; |
---|
457 | else |
---|
458 | this->timeToReload_ = 0; |
---|
459 | |
---|
460 | if (this->bLMousePressed_ && this->timeToReload_ <= 0) |
---|
461 | { |
---|
462 | new Projectile(this); |
---|
463 | this->timeToReload_ = this->reloadTime_; |
---|
464 | } |
---|
465 | |
---|
466 | OIS::Keyboard* mKeyboard = InputManager::getSingleton().getKeyboard(); |
---|
467 | //FIXME: variable never used |
---|
468 | //OIS::Mouse* mMouse = InputManager::getSingleton().getMouse(); |
---|
469 | |
---|
470 | |
---|
471 | // ##################################### |
---|
472 | // ############# STEERING ############## |
---|
473 | // ##################################### |
---|
474 | |
---|
475 | if (this->velocity_.x > this->maxSpeed_) |
---|
476 | this->velocity_.x = this->maxSpeed_; |
---|
477 | if (this->velocity_.x < -this->maxSideAndBackSpeed_) |
---|
478 | this->velocity_.x = -this->maxSideAndBackSpeed_; |
---|
479 | if (this->velocity_.y > this->maxSideAndBackSpeed_) |
---|
480 | this->velocity_.y = this->maxSideAndBackSpeed_; |
---|
481 | if (this->velocity_.y < -this->maxSideAndBackSpeed_) |
---|
482 | this->velocity_.y = -this->maxSideAndBackSpeed_; |
---|
483 | if (this->rotationRate_ > this->maxRotationRadian_) |
---|
484 | this->rotationRate_ = this->maxRotationRadian_; |
---|
485 | if (this->rotationRate_ < -this->maxRotationRadian_) |
---|
486 | this->rotationRate_ = -this->maxRotationRadian_; |
---|
487 | |
---|
488 | if (this->acceleration_.x == 0) |
---|
489 | { |
---|
490 | if (this->velocity_.x > 0) |
---|
491 | { |
---|
492 | this->velocity_.x -= (this->translationDamping_ * dt); |
---|
493 | if (this->velocity_.x < 0) |
---|
494 | this->velocity_.x = 0; |
---|
495 | } |
---|
496 | else if (this->velocity_.x < 0) |
---|
497 | { |
---|
498 | this->velocity_.x += (this->translationDamping_ * dt); |
---|
499 | if (this->velocity_.x > 0) |
---|
500 | this->velocity_.x = 0; |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | if (this->acceleration_.y == 0) |
---|
505 | { |
---|
506 | if (this->velocity_.y > 0) |
---|
507 | { |
---|
508 | this->velocity_.y -= (this->translationDamping_ * dt); |
---|
509 | if (this->velocity_.y < 0) |
---|
510 | this->velocity_.y = 0; |
---|
511 | } |
---|
512 | else if (this->velocity_.y < 0) |
---|
513 | { |
---|
514 | this->velocity_.y += (this->translationDamping_ * dt); |
---|
515 | if (this->velocity_.y > 0) |
---|
516 | this->velocity_.y = 0; |
---|
517 | } |
---|
518 | } |
---|
519 | |
---|
520 | if (this->momentum_ == this->zeroRadian_) |
---|
521 | { |
---|
522 | if (this->rotationRate_ > this->zeroRadian_) |
---|
523 | { |
---|
524 | this->rotationRate_ -= (this->rotationDampingRadian_ * dt); |
---|
525 | if (this->rotationRate_ < this->zeroRadian_) |
---|
526 | this->rotationRate_ = 0; |
---|
527 | } |
---|
528 | else if (this->rotationRate_ < this->zeroRadian_) |
---|
529 | { |
---|
530 | this->rotationRate_ += (this->rotationDampingRadian_ * dt); |
---|
531 | if (this->rotationRate_ > this->zeroRadian_) |
---|
532 | this->rotationRate_ = 0; |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | if(!network::Client::getSingleton()){ |
---|
537 | if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) |
---|
538 | this->acceleration_.x = this->translationAcceleration_; |
---|
539 | else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) |
---|
540 | this->acceleration_.x = -this->translationAcceleration_; |
---|
541 | else |
---|
542 | this->acceleration_.x = 0; |
---|
543 | |
---|
544 | if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) |
---|
545 | this->acceleration_.y = -this->translationAcceleration_; |
---|
546 | else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) |
---|
547 | this->acceleration_.y = this->translationAcceleration_; |
---|
548 | else |
---|
549 | this->acceleration_.y = 0; |
---|
550 | |
---|
551 | if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q)) |
---|
552 | this->momentum_ = Radian(-this->rotationAccelerationRadian_); |
---|
553 | else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E)) |
---|
554 | this->momentum_ = Radian(this->rotationAccelerationRadian_); |
---|
555 | else |
---|
556 | this->momentum_ = 0; |
---|
557 | } |
---|
558 | |
---|
559 | WorldEntity::tick(dt); |
---|
560 | |
---|
561 | this->roll(this->mouseXRotation_ * dt); |
---|
562 | if (this->bInvertYAxis_) |
---|
563 | this->yaw(Radian(-this->mouseYRotation_ * dt)); |
---|
564 | else |
---|
565 | this->yaw(Radian(this->mouseYRotation_ * dt)); |
---|
566 | |
---|
567 | if (this->acceleration_.x > 0) |
---|
568 | this->tt_->setRate(emitterRate_); |
---|
569 | else |
---|
570 | this->tt_->setRate(0); |
---|
571 | |
---|
572 | /* |
---|
573 | if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) |
---|
574 | this->moveForward(speed); |
---|
575 | else |
---|
576 | this->moveForward(0); |
---|
577 | |
---|
578 | if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) |
---|
579 | this->brakeForward(speed); |
---|
580 | else |
---|
581 | this->brakeForward(speed/10); |
---|
582 | |
---|
583 | if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) |
---|
584 | this->loopRight(loop); |
---|
585 | else |
---|
586 | this->loopRight(0); |
---|
587 | |
---|
588 | if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) |
---|
589 | this->loopLeft(loop); |
---|
590 | else |
---|
591 | this->loopLeft(0); |
---|
592 | |
---|
593 | if(moved) |
---|
594 | { |
---|
595 | if (mouseY<=0) |
---|
596 | this->rotateUp(-mouseY*rotate); |
---|
597 | if (mouseY>0) |
---|
598 | this->rotateDown(mouseY*rotate); |
---|
599 | if (mouseX>0) |
---|
600 | this->rotateRight(mouseX*rotate); |
---|
601 | if (mouseX<=0) |
---|
602 | this->rotateLeft(-mouseX*rotate); |
---|
603 | |
---|
604 | mouseY = 0; |
---|
605 | mouseX = 0; |
---|
606 | moved = false; |
---|
607 | }*/ |
---|
608 | /* else |
---|
609 | { |
---|
610 | this->rotateUp(0); |
---|
611 | this->rotateDown(0); |
---|
612 | this->rotateRight(0); |
---|
613 | this->rotateLeft(0); |
---|
614 | }*/ |
---|
615 | /* |
---|
616 | if(moveForward_ > 0) |
---|
617 | { |
---|
618 | accelerationForward_ = moveForward_; |
---|
619 | if(speedForward_ < maxSpeedForward_) |
---|
620 | speedForward_ += accelerationForward_*dt; |
---|
621 | if(speedForward_ > maxSpeedForward_) |
---|
622 | speedForward_ = maxSpeedForward_; |
---|
623 | } |
---|
624 | |
---|
625 | if(moveForward_ <= 0) |
---|
626 | { |
---|
627 | accelerationForward_ = -brakeForward_; |
---|
628 | if(speedForward_ > 0) |
---|
629 | speedForward_ += accelerationForward_*dt; |
---|
630 | if(speedForward_ < 0) |
---|
631 | speedForward_ = 0; |
---|
632 | } |
---|
633 | |
---|
634 | if(rotateUp_ > 0) |
---|
635 | { |
---|
636 | accelerationRotateUpDown_ = rotateUp_; |
---|
637 | if(speedRotateUpDown_ < maxSpeedRotateUpDown_) |
---|
638 | speedRotateUpDown_ += accelerationRotateUpDown_*dt; |
---|
639 | if(speedRotateUpDown_ > maxSpeedRotateUpDown_) |
---|
640 | speedRotateUpDown_ = maxSpeedRotateUpDown_; |
---|
641 | } |
---|
642 | |
---|
643 | if(rotateDown_ > 0) |
---|
644 | { |
---|
645 | accelerationRotateUpDown_ = rotateDown_; |
---|
646 | if(speedRotateUpDown_ > -maxSpeedRotateUpDown_) |
---|
647 | speedRotateUpDown_ -= accelerationRotateUpDown_*dt; |
---|
648 | if(speedRotateUpDown_ < -maxSpeedRotateUpDown_) |
---|
649 | speedRotateUpDown_ = -maxSpeedRotateUpDown_; |
---|
650 | } |
---|
651 | |
---|
652 | if(rotateUp_ == 0 && rotateDown_ == 0) |
---|
653 | { |
---|
654 | accelerationRotateUpDown_ = brakeRotate_; |
---|
655 | if(speedRotateUpDown_ > 0) |
---|
656 | speedRotateUpDown_ -= accelerationRotateUpDown_*dt; |
---|
657 | if(speedRotateUpDown_ < 0) |
---|
658 | speedRotateUpDown_ += accelerationRotateUpDown_*dt; |
---|
659 | if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt) |
---|
660 | speedRotateUpDown_ = 0; |
---|
661 | } |
---|
662 | |
---|
663 | if(rotateRight_ > 0) |
---|
664 | { |
---|
665 | accelerationRotateRightLeft_ = rotateRight_; |
---|
666 | if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_) |
---|
667 | speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt; |
---|
668 | if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_) |
---|
669 | speedRotateRightLeft_ = -maxSpeedRotateRightLeft_; |
---|
670 | } |
---|
671 | |
---|
672 | if(rotateLeft_ > 0) |
---|
673 | { |
---|
674 | accelerationRotateRightLeft_ = rotateLeft_; |
---|
675 | if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_) |
---|
676 | speedRotateRightLeft_ += accelerationRotateRightLeft_*dt; |
---|
677 | if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_) |
---|
678 | speedRotateRightLeft_ = maxSpeedRotateRightLeft_; |
---|
679 | } |
---|
680 | |
---|
681 | if(rotateRight_ == 0 && rotateLeft_ == 0) |
---|
682 | { |
---|
683 | accelerationRotateRightLeft_ = brakeRotate_; |
---|
684 | if(speedRotateRightLeft_ > 0) |
---|
685 | speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt; |
---|
686 | if(speedRotateRightLeft_ < 0) |
---|
687 | speedRotateRightLeft_ += accelerationRotateRightLeft_*dt; |
---|
688 | if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt) |
---|
689 | speedRotateRightLeft_ = 0; |
---|
690 | } |
---|
691 | |
---|
692 | if(loopRight_ > 0) |
---|
693 | { |
---|
694 | accelerationLoopRightLeft_ = loopRight_; |
---|
695 | if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_) |
---|
696 | speedLoopRightLeft_ += accelerationLoopRightLeft_*dt; |
---|
697 | if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_) |
---|
698 | speedLoopRightLeft_ = maxSpeedLoopRightLeft_; |
---|
699 | } |
---|
700 | |
---|
701 | if(loopLeft_ > 0) |
---|
702 | { |
---|
703 | accelerationLoopRightLeft_ = loopLeft_; |
---|
704 | if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_) |
---|
705 | speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt; |
---|
706 | if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_) |
---|
707 | speedLoopRightLeft_ = -maxSpeedLoopRightLeft_; |
---|
708 | } |
---|
709 | |
---|
710 | if(loopLeft_ == 0 && loopRight_ == 0) |
---|
711 | { |
---|
712 | accelerationLoopRightLeft_ = brakeLoop_; |
---|
713 | if(speedLoopRightLeft_ > 0) |
---|
714 | speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt; |
---|
715 | if(speedLoopRightLeft_ < 0) |
---|
716 | speedLoopRightLeft_ += accelerationLoopRightLeft_*dt; |
---|
717 | if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt) |
---|
718 | speedLoopRightLeft_ = 0; |
---|
719 | } |
---|
720 | |
---|
721 | Vector3 transVector = Vector3::ZERO; |
---|
722 | */ |
---|
723 | /* |
---|
724 | transVector.z = 1; |
---|
725 | this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL); |
---|
726 | this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL); |
---|
727 | this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
728 | this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
729 | */ |
---|
730 | /* |
---|
731 | transVector.x = 1; |
---|
732 | this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL); |
---|
733 | this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL); |
---|
734 | this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
735 | this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); |
---|
736 | */ |
---|
737 | } |
---|
738 | /* |
---|
739 | void SpaceShip::moveForward(float moveForward) { |
---|
740 | moveForward_ = moveForward; |
---|
741 | } |
---|
742 | |
---|
743 | void SpaceShip::rotateUp(float rotateUp) { |
---|
744 | rotateUp_ = rotateUp; |
---|
745 | } |
---|
746 | |
---|
747 | void SpaceShip::rotateDown(float rotateDown) { |
---|
748 | rotateDown_ = rotateDown; |
---|
749 | } |
---|
750 | |
---|
751 | void SpaceShip::rotateLeft(float rotateLeft) { |
---|
752 | rotateLeft_ = rotateLeft; |
---|
753 | } |
---|
754 | |
---|
755 | void SpaceShip::rotateRight(float rotateRight) { |
---|
756 | rotateRight_ = rotateRight; |
---|
757 | } |
---|
758 | |
---|
759 | void SpaceShip::loopLeft(float loopLeft) { |
---|
760 | loopLeft_ = loopLeft; |
---|
761 | } |
---|
762 | |
---|
763 | void SpaceShip::loopRight(float loopRight) { |
---|
764 | loopRight_ = loopRight; |
---|
765 | } |
---|
766 | |
---|
767 | void SpaceShip::brakeForward(float brakeForward) { |
---|
768 | brakeForward_ = brakeForward; |
---|
769 | } |
---|
770 | |
---|
771 | void SpaceShip::brakeRotate(float brakeRotate) { |
---|
772 | brakeRotate_ = brakeRotate; |
---|
773 | } |
---|
774 | |
---|
775 | void SpaceShip::brakeLoop(float brakeLoop) { |
---|
776 | brakeLoop_ = brakeLoop; |
---|
777 | } |
---|
778 | |
---|
779 | void SpaceShip::maxSpeedForward(float maxSpeedForward) { |
---|
780 | maxSpeedForward_ = maxSpeedForward; |
---|
781 | } |
---|
782 | |
---|
783 | void SpaceShip::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) { |
---|
784 | maxSpeedRotateUpDown_ = maxSpeedRotateUpDown; |
---|
785 | } |
---|
786 | |
---|
787 | void SpaceShip::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) { |
---|
788 | maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft; |
---|
789 | } |
---|
790 | |
---|
791 | void SpaceShip::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) { |
---|
792 | maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; |
---|
793 | } |
---|
794 | */ |
---|
795 | } |
---|