Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/merge/src/orxonox/objects/SpaceShip.cc @ 1263

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