Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trying to make it tickable

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