Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network3/src/orxonox/objects/SpaceShip.cc @ 1233

Last change on this file since 1233 was 1232, checked in by scheusso, 17 years ago

a lot of changes in order to make it possible to have mulpiple clients with each one a new ship
camera changes
object changes
synchronisable: backsyncronisation should be possible now
gamestatemanager/gamestateclient: functions for backsyncronisation
some changes in order to get the input system (the old one) on the client working
TODO something with the camera position is wrong at the moment (clientside)

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