Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

a huge fix in packetbuffer

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