Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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