Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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