Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/releases/0.1.0/src/orxonox/objects/SpaceShip.cc @ 1998

Last change on this file since 1998 was 790, checked in by nicolasc, 17 years ago

merged FICN back into trunk
awaiting release.

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