Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1338 was 1261, checked in by scheusso, 17 years ago

fixed a 'bug' in WE-Model-Spaceship

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