Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core/src/orxonox/objects/SpaceShip.cc @ 869

Last change on this file since 869 was 869, checked in by landauf, 16 years ago

cool shit's happening here… it works! wow. I wonder why, but hey, don't ask, just commit. this update might also be helpful for the network guys.

  • fixed a bug in XMLPort
  • fixed a bug in the MultiTypes
  • implemented some XMLPort functions in Model, SpaceShip, Skybox and Ambient (and of course the WorldEntity), but this is just a workaround as all those classes are more or less just temporary solutions
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    Element& 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        return xmlelement;
307    }
308
309    int sgn(float x)
310    {
311        if (x >= 0)
312            return 1;
313        else
314            return -1;
315    }
316
317    bool SpaceShip::mouseMoved(const OIS::MouseEvent &e)
318    {
319/*
320        this->mouseX += e.state.X.rel;
321        if (this->bInvertMouse_)
322            this->mouseY += e.state.Y.rel;
323        else
324            this->mouseY -= e.state.Y.rel;
325
326//        if(mouseX>maxMouseX) maxMouseX = mouseX;
327//        if(mouseX<minMouseX) minMouseX = mouseX;
328//        cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;
329
330        this->moved = true;
331*/
332        if (this->bRMousePressed_)
333        {
334            this->camNode_->roll(Degree(-e.state.X.rel * 0.10));
335            this->camNode_->yaw(Degree(e.state.Y.rel * 0.10));
336        }
337        else
338        {
339            float minDimension = e.state.height;
340            if (e.state.width < minDimension)
341                minDimension = e.state.width;
342
343            this->mouseX_ += e.state.X.rel;
344            if (this->mouseX_ < -minDimension)
345                this->mouseX_ = -minDimension;
346            if (this->mouseX_ > minDimension)
347                this->mouseX_ = minDimension;
348
349            this->mouseY_ += e.state.Y.rel;
350            if (this->mouseY_ < -minDimension)
351                this->mouseY_ = -minDimension;
352            if (this->mouseY_ > minDimension)
353                this->mouseY_ = minDimension;
354
355            float xRotation = this->mouseX_ / minDimension;
356            xRotation = xRotation*xRotation * sgn(xRotation);
357            xRotation *= -this->rotationAcceleration_;
358            if (xRotation > this->maxRotation_)
359                xRotation = this->maxRotation_;
360            if (xRotation < -this->maxRotation_)
361                xRotation = -this->maxRotation_;
362            this->mouseXRotation_ = Radian(xRotation);
363
364            float yRotation = this->mouseY_ / minDimension;
365            yRotation = yRotation*yRotation * sgn(yRotation);
366            yRotation *= this->rotationAcceleration_;
367            if (yRotation > this->maxRotation_)
368                yRotation = this->maxRotation_;
369            if (yRotation < -this->maxRotation_)
370                yRotation = -this->maxRotation_;
371            this->mouseYRotation_ = Radian(yRotation);
372        }
373
374        return true;
375    }
376
377    bool SpaceShip::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
378    {
379        if (id == OIS::MB_Left)
380            this->bLMousePressed_ = true;
381        else if (id == OIS::MB_Right)
382            this->bRMousePressed_ = true;
383
384        return true;
385    }
386
387    bool SpaceShip::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
388    {
389        if (id == OIS::MB_Left)
390            this->bLMousePressed_ = false;
391        else if (id == OIS::MB_Right)
392        {
393            this->bRMousePressed_ = false;
394            this->camNode_->resetOrientation();
395        }
396
397        return true;
398    }
399
400    void SpaceShip::tick(float dt)
401    {
402        if (!this->setMouseEventCallback_)
403        {
404            if (Orxonox::getSingleton()->getMouse())
405            {
406                Orxonox::getSingleton()->getMouse()->setEventCallback(this);
407                this->setMouseEventCallback_ = true;
408            }
409        }
410
411        if (this->redNode_ && this->greenNode_)
412        {
413            this->blinkTime_ += dt;
414            float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0);
415            float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0);
416            this->redNode_->setScale(redScale, redScale, redScale);
417            this->greenNode_->setScale(greenScale, greenScale, greenScale);
418        }
419
420        if (this->timeToReload_ > 0)
421            this->timeToReload_ -= dt;
422        else
423            this->timeToReload_ = 0;
424
425        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
426        {
427            new Projectile(this);
428            this->timeToReload_ = this->reloadTime_;
429        }
430
431        OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard();
432        OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse();
433
434        mKeyboard->capture();
435        mMouse->capture();
436
437
438        // #####################################
439        // ############# STEERING ##############
440        // #####################################
441
442        if (this->velocity_.x > this->maxSpeed_)
443            this->velocity_.x = this->maxSpeed_;
444        if (this->velocity_.x < -this->maxSideAndBackSpeed_)
445            this->velocity_.x = -this->maxSideAndBackSpeed_;
446        if (this->velocity_.y > this->maxSideAndBackSpeed_)
447            this->velocity_.y = this->maxSideAndBackSpeed_;
448        if (this->velocity_.y < -this->maxSideAndBackSpeed_)
449            this->velocity_.y = -this->maxSideAndBackSpeed_;
450        if (this->rotationRate_ > this->maxRotationRadian_)
451            this->rotationRate_ = this->maxRotationRadian_;
452        if (this->rotationRate_ < -this->maxRotationRadian_)
453            this->rotationRate_ = -this->maxRotationRadian_;
454
455        if (this->acceleration_.x == 0)
456        {
457            if (this->velocity_.x > 0)
458            {
459                this->velocity_.x -= (this->translationDamping_ * dt);
460                if (this->velocity_.x < 0)
461                    this->velocity_.x = 0;
462            }
463            else if (this->velocity_.x < 0)
464            {
465                this->velocity_.x += (this->translationDamping_ * dt);
466                if (this->velocity_.x > 0)
467                    this->velocity_.x = 0;
468            }
469        }
470
471        if (this->acceleration_.y == 0)
472        {
473            if (this->velocity_.y > 0)
474            {
475                this->velocity_.y -= (this->translationDamping_ * dt);
476                if (this->velocity_.y < 0)
477                    this->velocity_.y = 0;
478            }
479            else if (this->velocity_.y < 0)
480            {
481                this->velocity_.y += (this->translationDamping_ * dt);
482                if (this->velocity_.y > 0)
483                    this->velocity_.y = 0;
484            }
485        }
486
487        if (this->momentum_ == this->zeroRadian_)
488        {
489            if (this->rotationRate_ > this->zeroRadian_)
490            {
491                this->rotationRate_ -= (this->rotationDampingRadian_ * dt);
492                if (this->rotationRate_ < this->zeroRadian_)
493                    this->rotationRate_ = 0;
494            }
495            else if (this->rotationRate_ < this->zeroRadian_)
496            {
497                this->rotationRate_ += (this->rotationDampingRadian_ * dt);
498                if (this->rotationRate_ > this->zeroRadian_)
499                    this->rotationRate_ = 0;
500            }
501        }
502
503        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
504            this->acceleration_.x = this->translationAcceleration_;
505        else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
506            this->acceleration_.x = -this->translationAcceleration_;
507        else
508            this->acceleration_.x = 0;
509
510        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
511            this->acceleration_.y = -this->translationAcceleration_;
512        else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
513            this->acceleration_.y = this->translationAcceleration_;
514        else
515            this->acceleration_.y = 0;
516
517        if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
518            this->momentum_ = Radian(-this->rotationAccelerationRadian_);
519        else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
520            this->momentum_ = Radian(this->rotationAccelerationRadian_);
521        else
522            this->momentum_ = 0;
523
524        WorldEntity::tick(dt);
525
526        this->roll(this->mouseXRotation_ * dt);
527        if (this->bInvertYAxis_)
528            this->yaw(Radian(-this->mouseYRotation_ * dt));
529        else
530            this->yaw(Radian(this->mouseYRotation_ * dt));
531
532        if (this->acceleration_.x > 0)
533            this->tt_->setRate(emitterRate_);
534        else
535            this->tt_->setRate(0);
536
537/*
538        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
539            this->moveForward(speed);
540        else
541            this->moveForward(0);
542
543        if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
544            this->brakeForward(speed);
545        else
546            this->brakeForward(speed/10);
547
548        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
549            this->loopRight(loop);
550        else
551            this->loopRight(0);
552
553        if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
554            this->loopLeft(loop);
555        else
556            this->loopLeft(0);
557
558        if(moved)
559        {
560            if (mouseY<=0)
561                this->rotateUp(-mouseY*rotate);
562            if (mouseY>0)
563                this->rotateDown(mouseY*rotate);
564            if (mouseX>0)
565                this->rotateRight(mouseX*rotate);
566            if (mouseX<=0)
567                this->rotateLeft(-mouseX*rotate);
568
569            mouseY = 0;
570            mouseX = 0;
571            moved = false;
572        }*/
573/*        else
574        {
575            this->rotateUp(0);
576            this->rotateDown(0);
577            this->rotateRight(0);
578            this->rotateLeft(0);
579        }*/
580/*
581        if(moveForward_ > 0)
582        {
583            accelerationForward_ = moveForward_;
584            if(speedForward_ < maxSpeedForward_)
585                speedForward_ += accelerationForward_*dt;
586            if(speedForward_ > maxSpeedForward_)
587                speedForward_ = maxSpeedForward_;
588        }
589
590        if(moveForward_ <= 0)
591        {
592            accelerationForward_ = -brakeForward_;
593            if(speedForward_ > 0)
594                speedForward_ += accelerationForward_*dt;
595            if(speedForward_ < 0)
596                speedForward_ = 0;
597        }
598
599        if(rotateUp_ > 0)
600        {
601            accelerationRotateUpDown_ = rotateUp_;
602            if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
603                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
604            if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
605            speedRotateUpDown_ = maxSpeedRotateUpDown_;
606        }
607
608        if(rotateDown_ > 0)
609        {
610            accelerationRotateUpDown_ = rotateDown_;
611            if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
612                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
613            if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
614                speedRotateUpDown_ = -maxSpeedRotateUpDown_;
615        }
616
617        if(rotateUp_ == 0 && rotateDown_ == 0)
618        {
619            accelerationRotateUpDown_ = brakeRotate_;
620            if(speedRotateUpDown_ > 0)
621                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
622            if(speedRotateUpDown_ < 0)
623                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
624            if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt)
625                speedRotateUpDown_ = 0;
626        }
627
628        if(rotateRight_ > 0)
629        {
630            accelerationRotateRightLeft_ = rotateRight_;
631            if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
632                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
633            if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
634                speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
635        }
636
637        if(rotateLeft_ > 0)
638        {
639            accelerationRotateRightLeft_ = rotateLeft_;
640            if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
641                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
642            if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
643                speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
644        }
645
646        if(rotateRight_ == 0 && rotateLeft_ == 0)
647        {
648            accelerationRotateRightLeft_ = brakeRotate_;
649            if(speedRotateRightLeft_ > 0)
650                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
651            if(speedRotateRightLeft_ < 0)
652                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
653            if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt)
654                speedRotateRightLeft_ = 0;
655        }
656
657        if(loopRight_ > 0)
658        {
659            accelerationLoopRightLeft_ = loopRight_;
660            if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
661                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
662            if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
663                speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
664        }
665
666        if(loopLeft_ > 0)
667        {
668            accelerationLoopRightLeft_ = loopLeft_;
669            if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
670                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
671            if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
672                speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
673        }
674
675        if(loopLeft_ == 0 && loopRight_ == 0)
676        {
677            accelerationLoopRightLeft_ = brakeLoop_;
678            if(speedLoopRightLeft_ > 0)
679                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
680            if(speedLoopRightLeft_ < 0)
681                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
682            if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt)
683                speedLoopRightLeft_ = 0;
684        }
685
686        Vector3 transVector = Vector3::ZERO;
687*/
688/*
689        transVector.z = 1;
690        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
691        this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
692        this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
693        this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
694*/
695/*
696        transVector.x = 1;
697        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
698        this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
699        this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
700        this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
701*/
702    }
703/*
704    void SpaceShip::moveForward(float moveForward) {
705        moveForward_ = moveForward;
706    }
707
708    void SpaceShip::rotateUp(float rotateUp) {
709        rotateUp_ = rotateUp;
710    }
711
712    void SpaceShip::rotateDown(float rotateDown) {
713        rotateDown_ = rotateDown;
714    }
715
716    void SpaceShip::rotateLeft(float rotateLeft) {
717        rotateLeft_ = rotateLeft;
718    }
719
720    void SpaceShip::rotateRight(float rotateRight) {
721        rotateRight_ = rotateRight;
722    }
723
724    void SpaceShip::loopLeft(float loopLeft) {
725        loopLeft_ = loopLeft;
726    }
727
728    void SpaceShip::loopRight(float loopRight) {
729        loopRight_ = loopRight;
730    }
731
732    void SpaceShip::brakeForward(float brakeForward) {
733        brakeForward_ = brakeForward;
734    }
735
736    void SpaceShip::brakeRotate(float brakeRotate) {
737        brakeRotate_ = brakeRotate;
738    }
739
740    void SpaceShip::brakeLoop(float brakeLoop) {
741        brakeLoop_ = brakeLoop;
742    }
743
744    void SpaceShip::maxSpeedForward(float maxSpeedForward) {
745        maxSpeedForward_ = maxSpeedForward;
746    }
747
748    void SpaceShip::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) {
749        maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
750    }
751
752    void SpaceShip::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) {
753        maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
754    }
755
756    void SpaceShip::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) {
757        maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
758    }
759*/
760}
Note: See TracBrowser for help on using the repository browser.