Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/SpaceShip.cc @ 1052

Last change on this file since 1052 was 1052, checked in by landauf, 16 years ago

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

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