Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/SpaceShip.cc @ 717

Last change on this file since 717 was 717, checked in by landauf, 17 years ago

some changes (yes! CHANGES! unbelievable! they exist! well, ok, not in politics)

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