Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 696 was 670, checked in by landauf, 17 years ago

copyright notes

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