Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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