Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1318 was 1318, checked in by scheusso, 16 years ago

made clientinformation threadsafe and improved packetbuffer; wrote a static function SpaceShip *SpaceShip::getLocalShip. it returns the pointer to the ship that should be steered

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