Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged core branch to trunk

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