Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/SpaceShip.cc @ 1039

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