Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/objects/SpaceShip.cc @ 947

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