Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 976 was 976, checked in by FelixSchulthess, 16 years ago

changed level file so → trunk runnable

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