Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/camera/src/orxonox/objects/SpaceShip.cc @ 1207

Last change on this file since 1207 was 1201, checked in by bknecht, 17 years ago

CameraHandler and Camera work now

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