Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1035 was 1035, checked in by rgrieder, 16 years ago
  • minor Singleton changes
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 "GraphicsEngine.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(GraphicsEngine::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 = GraphicsEngine::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        GraphicsEngine::getSingleton().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 (InputManager::getSingleton().getMouse()->getEventCallback() != this)
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
452        // #####################################
453        // ############# STEERING ##############
454        // #####################################
455
456        if (this->velocity_.x > this->maxSpeed_)
457            this->velocity_.x = this->maxSpeed_;
458        if (this->velocity_.x < -this->maxSideAndBackSpeed_)
459            this->velocity_.x = -this->maxSideAndBackSpeed_;
460        if (this->velocity_.y > this->maxSideAndBackSpeed_)
461            this->velocity_.y = this->maxSideAndBackSpeed_;
462        if (this->velocity_.y < -this->maxSideAndBackSpeed_)
463            this->velocity_.y = -this->maxSideAndBackSpeed_;
464        if (this->rotationRate_ > this->maxRotationRadian_)
465            this->rotationRate_ = this->maxRotationRadian_;
466        if (this->rotationRate_ < -this->maxRotationRadian_)
467            this->rotationRate_ = -this->maxRotationRadian_;
468
469        if (this->acceleration_.x == 0)
470        {
471            if (this->velocity_.x > 0)
472            {
473                this->velocity_.x -= (this->translationDamping_ * dt);
474                if (this->velocity_.x < 0)
475                    this->velocity_.x = 0;
476            }
477            else if (this->velocity_.x < 0)
478            {
479                this->velocity_.x += (this->translationDamping_ * dt);
480                if (this->velocity_.x > 0)
481                    this->velocity_.x = 0;
482            }
483        }
484
485        if (this->acceleration_.y == 0)
486        {
487            if (this->velocity_.y > 0)
488            {
489                this->velocity_.y -= (this->translationDamping_ * dt);
490                if (this->velocity_.y < 0)
491                    this->velocity_.y = 0;
492            }
493            else if (this->velocity_.y < 0)
494            {
495                this->velocity_.y += (this->translationDamping_ * dt);
496                if (this->velocity_.y > 0)
497                    this->velocity_.y = 0;
498            }
499        }
500
501        if (this->momentum_ == this->zeroRadian_)
502        {
503            if (this->rotationRate_ > this->zeroRadian_)
504            {
505                this->rotationRate_ -= (this->rotationDampingRadian_ * dt);
506                if (this->rotationRate_ < this->zeroRadian_)
507                    this->rotationRate_ = 0;
508            }
509            else if (this->rotationRate_ < this->zeroRadian_)
510            {
511                this->rotationRate_ += (this->rotationDampingRadian_ * dt);
512                if (this->rotationRate_ > this->zeroRadian_)
513                    this->rotationRate_ = 0;
514            }
515        }
516
517        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
518            this->acceleration_.x = this->translationAcceleration_;
519        else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
520            this->acceleration_.x = -this->translationAcceleration_;
521        else
522            this->acceleration_.x = 0;
523
524        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
525            this->acceleration_.y = -this->translationAcceleration_;
526        else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
527            this->acceleration_.y = this->translationAcceleration_;
528        else
529            this->acceleration_.y = 0;
530
531        if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
532            this->momentum_ = Radian(-this->rotationAccelerationRadian_);
533        else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
534            this->momentum_ = Radian(this->rotationAccelerationRadian_);
535        else
536            this->momentum_ = 0;
537
538        WorldEntity::tick(dt);
539
540        this->roll(this->mouseXRotation_ * dt);
541        if (this->bInvertYAxis_)
542            this->yaw(Radian(-this->mouseYRotation_ * dt));
543        else
544            this->yaw(Radian(this->mouseYRotation_ * dt));
545
546        if (this->acceleration_.x > 0)
547            this->tt_->setRate(emitterRate_);
548        else
549            this->tt_->setRate(0);
550
551/*
552        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
553            this->moveForward(speed);
554        else
555            this->moveForward(0);
556
557        if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
558            this->brakeForward(speed);
559        else
560            this->brakeForward(speed/10);
561
562        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
563            this->loopRight(loop);
564        else
565            this->loopRight(0);
566
567        if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
568            this->loopLeft(loop);
569        else
570            this->loopLeft(0);
571
572        if(moved)
573        {
574            if (mouseY<=0)
575                this->rotateUp(-mouseY*rotate);
576            if (mouseY>0)
577                this->rotateDown(mouseY*rotate);
578            if (mouseX>0)
579                this->rotateRight(mouseX*rotate);
580            if (mouseX<=0)
581                this->rotateLeft(-mouseX*rotate);
582
583            mouseY = 0;
584            mouseX = 0;
585            moved = false;
586        }*/
587/*        else
588        {
589            this->rotateUp(0);
590            this->rotateDown(0);
591            this->rotateRight(0);
592            this->rotateLeft(0);
593        }*/
594/*
595        if(moveForward_ > 0)
596        {
597            accelerationForward_ = moveForward_;
598            if(speedForward_ < maxSpeedForward_)
599                speedForward_ += accelerationForward_*dt;
600            if(speedForward_ > maxSpeedForward_)
601                speedForward_ = maxSpeedForward_;
602        }
603
604        if(moveForward_ <= 0)
605        {
606            accelerationForward_ = -brakeForward_;
607            if(speedForward_ > 0)
608                speedForward_ += accelerationForward_*dt;
609            if(speedForward_ < 0)
610                speedForward_ = 0;
611        }
612
613        if(rotateUp_ > 0)
614        {
615            accelerationRotateUpDown_ = rotateUp_;
616            if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
617                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
618            if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
619            speedRotateUpDown_ = maxSpeedRotateUpDown_;
620        }
621
622        if(rotateDown_ > 0)
623        {
624            accelerationRotateUpDown_ = rotateDown_;
625            if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
626                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
627            if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
628                speedRotateUpDown_ = -maxSpeedRotateUpDown_;
629        }
630
631        if(rotateUp_ == 0 && rotateDown_ == 0)
632        {
633            accelerationRotateUpDown_ = brakeRotate_;
634            if(speedRotateUpDown_ > 0)
635                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
636            if(speedRotateUpDown_ < 0)
637                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
638            if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt)
639                speedRotateUpDown_ = 0;
640        }
641
642        if(rotateRight_ > 0)
643        {
644            accelerationRotateRightLeft_ = rotateRight_;
645            if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
646                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
647            if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
648                speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
649        }
650
651        if(rotateLeft_ > 0)
652        {
653            accelerationRotateRightLeft_ = rotateLeft_;
654            if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
655                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
656            if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
657                speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
658        }
659
660        if(rotateRight_ == 0 && rotateLeft_ == 0)
661        {
662            accelerationRotateRightLeft_ = brakeRotate_;
663            if(speedRotateRightLeft_ > 0)
664                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
665            if(speedRotateRightLeft_ < 0)
666                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
667            if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt)
668                speedRotateRightLeft_ = 0;
669        }
670
671        if(loopRight_ > 0)
672        {
673            accelerationLoopRightLeft_ = loopRight_;
674            if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
675                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
676            if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
677                speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
678        }
679
680        if(loopLeft_ > 0)
681        {
682            accelerationLoopRightLeft_ = loopLeft_;
683            if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
684                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
685            if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
686                speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
687        }
688
689        if(loopLeft_ == 0 && loopRight_ == 0)
690        {
691            accelerationLoopRightLeft_ = brakeLoop_;
692            if(speedLoopRightLeft_ > 0)
693                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
694            if(speedLoopRightLeft_ < 0)
695                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
696            if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt)
697                speedLoopRightLeft_ = 0;
698        }
699
700        Vector3 transVector = Vector3::ZERO;
701*/
702/*
703        transVector.z = 1;
704        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
705        this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
706        this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
707        this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
708*/
709/*
710        transVector.x = 1;
711        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
712        this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
713        this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
714        this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
715*/
716    }
717/*
718    void SpaceShip::moveForward(float moveForward) {
719        moveForward_ = moveForward;
720    }
721
722    void SpaceShip::rotateUp(float rotateUp) {
723        rotateUp_ = rotateUp;
724    }
725
726    void SpaceShip::rotateDown(float rotateDown) {
727        rotateDown_ = rotateDown;
728    }
729
730    void SpaceShip::rotateLeft(float rotateLeft) {
731        rotateLeft_ = rotateLeft;
732    }
733
734    void SpaceShip::rotateRight(float rotateRight) {
735        rotateRight_ = rotateRight;
736    }
737
738    void SpaceShip::loopLeft(float loopLeft) {
739        loopLeft_ = loopLeft;
740    }
741
742    void SpaceShip::loopRight(float loopRight) {
743        loopRight_ = loopRight;
744    }
745
746    void SpaceShip::brakeForward(float brakeForward) {
747        brakeForward_ = brakeForward;
748    }
749
750    void SpaceShip::brakeRotate(float brakeRotate) {
751        brakeRotate_ = brakeRotate;
752    }
753
754    void SpaceShip::brakeLoop(float brakeLoop) {
755        brakeLoop_ = brakeLoop;
756    }
757
758    void SpaceShip::maxSpeedForward(float maxSpeedForward) {
759        maxSpeedForward_ = maxSpeedForward;
760    }
761
762    void SpaceShip::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) {
763        maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
764    }
765
766    void SpaceShip::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) {
767        maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
768    }
769
770    void SpaceShip::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) {
771        maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
772    }
773*/
774}
Note: See TracBrowser for help on using the repository browser.