Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud3/src/orxonox/objects/SpaceShip.cc @ 1310

Last change on this file since 1310 was 1310, checked in by FelixSchulthess, 16 years ago

repositioned hud layout

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