Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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