Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud2/src/orxonox/objects/SpaceShip.cc @ 1180

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