Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/orxonox/objects/SpaceShip.cc @ 1213

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