Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

memory free problem

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    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//         COUT(4) << "================ \t\t\t\tspaceship::init" << std::endl;
144        // START CREATING THRUSTER
145        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
146        this->tt_->getParticleSystem()->setParameter("local_space","true");
147        this->tt_->newEmitter();
148/*
149        this->tt_->setDirection(Vector3(0,0,1));
150        this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15));
151        this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15));
152*/
153        this->tt_->setDirection(Vector3(-1,0,0));
154        this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1));
155        this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1));
156        this->tt_->setVelocity(50);
157
158        emitterRate_ = tt_->getRate();
159
160        Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2");
161        node2->setInheritScale(false);
162        tt_->addToSceneNode(node2);
163        // END CREATING THRUSTER
164
165        // START CREATING BLINKING LIGHTS
166        this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
167        this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1);
168
169        this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.7, -0.3));
170        this->redNode_->setInheritScale(false);
171        this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.7, -0.3));
172        this->greenNode_->setInheritScale(false);
173
174//         COUT(4) << "attaching red billboard" << std::endl;
175        this->redNode_->attachObject(this->redBillboard_.getBillboardSet());
176        this->redNode_->setScale(0.3, 0.3, 0.3);
177
178//         COUT(4) << "attaching green billboard" << std::endl;
179        this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet());
180        this->greenNode_->setScale(0.3, 0.3, 0.3);
181        // END CREATING BLINKING LIGHTS
182
183        // START of testing crosshair
184        this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
185        this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
186
187        this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
188        this->chNearNode_->setInheritScale(false);
189        this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
190        this->chFarNode_->setInheritScale(false);
191
192//         COUT(4) << "attaching crosshair near billboard" << std::endl;
193        this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
194        this->chNearNode_->setScale(0.2, 0.2, 0.2);
195
196//         COUT(4) << "attaching crosshair far billboard" << std::endl;
197        this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
198        this->chFarNode_->setScale(0.4, 0.4, 0.4);
199//         COUT(4) << "attaching camera" << std::endl;
200       
201        createCamera();
202        // END of testing crosshair
203    }
204
205    void SpaceShip::setConfigValues()
206    {
207        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
208        SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds");
209        SetConfigValue(testvector_, Vector3()).description("asdfblah");
210    }
211
212    void SpaceShip::loadParams(TiXmlElement* xmlElem)
213    {
214//       COUT(4) << "using loadparams" << std::endl;
215        Model::loadParams(xmlElem);
216        this->create();
217        this->getFocus();
218/*
219        if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
220        {
221            std::string forwardStr = xmlElem->Attribute("forward");
222            std::string rotateupdownStr = xmlElem->Attribute("rotateupdown");
223            std::string rotaterightleftStr = xmlElem->Attribute("rotaterightleft");
224            std::string looprightleftStr = xmlElem->Attribute("looprightleft");
225
226            String2Number<float>(this->maxSpeedForward_, forwardStr);
227            String2Number<float>(this->maxSpeedRotateUpDown_, rotateupdownStr);
228            String2Number<float>(this->maxSpeedRotateRightLeft_, rotaterightleftStr);
229            String2Number<float>(this->maxSpeedLoopRightLeft_, looprightleftStr);
230
231            COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl;
232        }
233*/
234        if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp"))
235        {
236
237            std::string msStr = xmlElem->Attribute("maxSpeed");
238            std::string msabsStr = xmlElem->Attribute("maxSideAndBackSpeed");
239            std::string mrStr = xmlElem->Attribute("maxRotation");
240            std::string taStr = xmlElem->Attribute("transAcc");
241            std::string raStr = xmlElem->Attribute("rotAcc");
242            std::string tdStr = xmlElem->Attribute("transDamp");
243            std::string rdStr = xmlElem->Attribute("rotDamp");
244
245            convertValue<std::string, float>(&this->maxSpeed_, msStr);
246            convertValue<std::string, float>(&this->maxSideAndBackSpeed_, msabsStr);
247            convertValue<std::string, float>(&this->maxRotation_, mrStr);
248            convertValue<std::string, float>(&this->translationAcceleration_, taStr);
249            convertValue<std::string, float>(&this->rotationAcceleration_, raStr);
250            convertValue<std::string, float>(&this->translationDamping_, tdStr);
251            convertValue<std::string, float>(&this->rotationDamping_, rdStr);
252
253            this->maxRotationRadian_ = Radian(this->maxRotation_);
254            this->rotationAccelerationRadian_ = Radian(this->rotationAcceleration_);
255            this->rotationDampingRadian_ = Radian(this->rotationDamping_);
256
257            COUT(4) << "Loader: Initialized SpaceShip" << std::endl;
258        }
259
260        if (xmlElem->Attribute("camera"))
261        {
262            this->setCamera();
263        }
264    }
265
266    void SpaceShip::setCamera(const std::string& camera)
267    {
268      camName_=camera;
269      // change camera attributes here, if you want to ;)
270    }
271   
272    void SpaceShip::getFocus(){
273      COUT(4) << "requesting focus" << std::endl;
274      if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID)
275        CameraHandler::getInstance()->requestFocus(cam_);
276     
277    }
278   
279    void SpaceShip::createCamera(){
280//       COUT(4) << "begin camera creation" << std::endl;
281      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
282      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
283      this->camNode_->setPosition(/*this->getNode()->getPosition() +*/ Vector3(-50,0,10));
284      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
285/*
286//        node->setInheritOrientation(false);
287      cam->setPosition(Vector3(0,50,-150));
288      cam->lookAt(Vector3(0,20,0));
289      cam->roll(Degree(0));
290      *//*COUT(4) << "creating new camera" << std::endl;*/
291      cam_ = new Camera(this->camNode_);
292//       COUT(4) << "setting target node" << std::endl;
293      cam_->setTargetNode(this->getNode());
294      // this only applies to clients
295      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
296        this->setBacksync(true);
297        CameraHandler::getInstance()->requestFocus(cam_);
298      }
299//        cam->setPosition(Vector3(0,-350,0));
300      //cam->roll(Degree(-90));
301
302      //this->camNode_->attachObject(cam);
303//       COUT(4) << "created camera" << std::endl;
304    }
305
306    void SpaceShip::setMaxSpeed(float value)
307    { this->maxSpeed_ = value; }
308    void SpaceShip::setMaxSideAndBackSpeed(float value)
309    { this->maxSideAndBackSpeed_ = value; }
310    void SpaceShip::setMaxRotation(float value)
311    { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); }
312    void SpaceShip::setTransAcc(float value)
313    { this->translationAcceleration_ = value; }
314    void SpaceShip::setRotAcc(float value)
315    { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); }
316    void SpaceShip::setTransDamp(float value)
317    { this->translationDamping_ = value; }
318    void SpaceShip::setRotDamp(float value)
319    { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); }
320
321    /**
322        @brief XML loading and saving.
323        @param xmlelement The XML-element
324        @param loading Loading (true) or saving (false)
325        @return The XML-element
326    */
327    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
328    {
329      COUT(4) << "using xmlport" << std::endl;
330        Model::XMLPort(xmlelement, mode);
331
332        XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode);
333        XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode);
334        XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode);
335        XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode);
336        XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode);
337        XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode);
338        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
339        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
340       
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 OIS::MouseEvent &e)
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(-e.state.X.rel * 0.10));
372            this->camNode_->yaw(Degree(e.state.Y.rel * 0.10));
373        }
374        else
375        {
376            float minDimension = e.state.height;
377            if (e.state.width < minDimension)
378                minDimension = e.state.width;
379
380            this->mouseX_ += e.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_ += e.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::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
415    {
416        if (id == OIS::MB_Left)
417            this->bLMousePressed_ = true;
418        else if (id == OIS::MB_Right)
419            this->bRMousePressed_ = true;
420
421        return true;
422    }
423
424    bool SpaceShip::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
425    {
426        if (id == OIS::MB_Left)
427            this->bLMousePressed_ = false;
428        else if (id == OIS::MB_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        // only do this if not client TODO: remove this hack
440      if ((!network::Client::getSingleton() || network::Client::getSingleton()->getShipID()==objectID ) && InputManager::getSingleton().getMouse()->getEventCallback() != this)
441        {
442            if (InputManager::getSingleton().getMouse())
443            {
444                InputManager::getSingleton().getMouse()->setEventCallback(this);
445                this->setMouseEventCallback_ = true;
446            }
447        }
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        OIS::Keyboard* mKeyboard = InputManager::getSingleton().getKeyboard();
471        //FIXME: variable never used
472        //OIS::Mouse* mMouse = InputManager::getSingleton().getMouse();
473
474
475        // #####################################
476        // ############# STEERING ##############
477        // #####################################
478
479        if (this->velocity_.x > this->maxSpeed_)
480            this->velocity_.x = this->maxSpeed_;
481        if (this->velocity_.x < -this->maxSideAndBackSpeed_)
482            this->velocity_.x = -this->maxSideAndBackSpeed_;
483        if (this->velocity_.y > this->maxSideAndBackSpeed_)
484            this->velocity_.y = this->maxSideAndBackSpeed_;
485        if (this->velocity_.y < -this->maxSideAndBackSpeed_)
486            this->velocity_.y = -this->maxSideAndBackSpeed_;
487        if (this->rotationRate_ > this->maxRotationRadian_)
488            this->rotationRate_ = this->maxRotationRadian_;
489        if (this->rotationRate_ < -this->maxRotationRadian_)
490            this->rotationRate_ = -this->maxRotationRadian_;
491
492        if (this->acceleration_.x == 0)
493        {
494            if (this->velocity_.x > 0)
495            {
496                this->velocity_.x -= (this->translationDamping_ * dt);
497                if (this->velocity_.x < 0)
498                    this->velocity_.x = 0;
499            }
500            else if (this->velocity_.x < 0)
501            {
502                this->velocity_.x += (this->translationDamping_ * dt);
503                if (this->velocity_.x > 0)
504                    this->velocity_.x = 0;
505            }
506        }
507
508        if (this->acceleration_.y == 0)
509        {
510            if (this->velocity_.y > 0)
511            {
512                this->velocity_.y -= (this->translationDamping_ * dt);
513                if (this->velocity_.y < 0)
514                    this->velocity_.y = 0;
515            }
516            else if (this->velocity_.y < 0)
517            {
518                this->velocity_.y += (this->translationDamping_ * dt);
519                if (this->velocity_.y > 0)
520                    this->velocity_.y = 0;
521            }
522        }
523
524        if (this->momentum_ == this->zeroRadian_)
525        {
526            if (this->rotationRate_ > this->zeroRadian_)
527            {
528                this->rotationRate_ -= (this->rotationDampingRadian_ * dt);
529                if (this->rotationRate_ < this->zeroRadian_)
530                    this->rotationRate_ = 0;
531            }
532            else if (this->rotationRate_ < this->zeroRadian_)
533            {
534                this->rotationRate_ += (this->rotationDampingRadian_ * dt);
535                if (this->rotationRate_ > this->zeroRadian_)
536                    this->rotationRate_ = 0;
537            }
538        }
539
540        if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ ){
541          COUT(4) << "steering our ship: " << objectID << " mkeyboard: " << mKeyboard << std::endl;
542          if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
543              this->acceleration_.x = this->translationAcceleration_;
544          else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
545              this->acceleration_.x = -this->translationAcceleration_;
546          else
547              this->acceleration_.x = 0;
548 
549          if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
550              this->acceleration_.y = -this->translationAcceleration_;
551          else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
552              this->acceleration_.y = this->translationAcceleration_;
553          else
554              this->acceleration_.y = 0;
555 
556          if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
557              this->momentum_ = Radian(-this->rotationAccelerationRadian_);
558          else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
559              this->momentum_ = Radian(this->rotationAccelerationRadian_);
560          else
561              this->momentum_ = 0;
562        }/*else
563          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
564
565        WorldEntity::tick(dt);
566
567        this->roll(this->mouseXRotation_ * dt);
568        if (this->bInvertYAxis_)
569            this->yaw(Radian(-this->mouseYRotation_ * dt));
570        else
571            this->yaw(Radian(this->mouseYRotation_ * dt));
572
573        if (this->acceleration_.x > 0)
574            this->tt_->setRate(emitterRate_);
575        else
576            this->tt_->setRate(0);
577
578/*
579        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
580            this->moveForward(speed);
581        else
582            this->moveForward(0);
583
584        if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
585            this->brakeForward(speed);
586        else
587            this->brakeForward(speed/10);
588
589        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
590            this->loopRight(loop);
591        else
592            this->loopRight(0);
593
594        if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
595            this->loopLeft(loop);
596        else
597            this->loopLeft(0);
598
599        if(moved)
600        {
601            if (mouseY<=0)
602                this->rotateUp(-mouseY*rotate);
603            if (mouseY>0)
604                this->rotateDown(mouseY*rotate);
605            if (mouseX>0)
606                this->rotateRight(mouseX*rotate);
607            if (mouseX<=0)
608                this->rotateLeft(-mouseX*rotate);
609
610            mouseY = 0;
611            mouseX = 0;
612            moved = false;
613        }*/
614/*        else
615        {
616            this->rotateUp(0);
617            this->rotateDown(0);
618            this->rotateRight(0);
619            this->rotateLeft(0);
620        }*/
621/*
622        if(moveForward_ > 0)
623        {
624            accelerationForward_ = moveForward_;
625            if(speedForward_ < maxSpeedForward_)
626                speedForward_ += accelerationForward_*dt;
627            if(speedForward_ > maxSpeedForward_)
628                speedForward_ = maxSpeedForward_;
629        }
630
631        if(moveForward_ <= 0)
632        {
633            accelerationForward_ = -brakeForward_;
634            if(speedForward_ > 0)
635                speedForward_ += accelerationForward_*dt;
636            if(speedForward_ < 0)
637                speedForward_ = 0;
638        }
639
640        if(rotateUp_ > 0)
641        {
642            accelerationRotateUpDown_ = rotateUp_;
643            if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
644                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
645            if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
646            speedRotateUpDown_ = maxSpeedRotateUpDown_;
647        }
648
649        if(rotateDown_ > 0)
650        {
651            accelerationRotateUpDown_ = rotateDown_;
652            if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
653                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
654            if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
655                speedRotateUpDown_ = -maxSpeedRotateUpDown_;
656        }
657
658        if(rotateUp_ == 0 && rotateDown_ == 0)
659        {
660            accelerationRotateUpDown_ = brakeRotate_;
661            if(speedRotateUpDown_ > 0)
662                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
663            if(speedRotateUpDown_ < 0)
664                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
665            if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt)
666                speedRotateUpDown_ = 0;
667        }
668
669        if(rotateRight_ > 0)
670        {
671            accelerationRotateRightLeft_ = rotateRight_;
672            if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
673                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
674            if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
675                speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
676        }
677
678        if(rotateLeft_ > 0)
679        {
680            accelerationRotateRightLeft_ = rotateLeft_;
681            if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
682                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
683            if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
684                speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
685        }
686
687        if(rotateRight_ == 0 && rotateLeft_ == 0)
688        {
689            accelerationRotateRightLeft_ = brakeRotate_;
690            if(speedRotateRightLeft_ > 0)
691                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
692            if(speedRotateRightLeft_ < 0)
693                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
694            if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt)
695                speedRotateRightLeft_ = 0;
696        }
697
698        if(loopRight_ > 0)
699        {
700            accelerationLoopRightLeft_ = loopRight_;
701            if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
702                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
703            if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
704                speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
705        }
706
707        if(loopLeft_ > 0)
708        {
709            accelerationLoopRightLeft_ = loopLeft_;
710            if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
711                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
712            if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
713                speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
714        }
715
716        if(loopLeft_ == 0 && loopRight_ == 0)
717        {
718            accelerationLoopRightLeft_ = brakeLoop_;
719            if(speedLoopRightLeft_ > 0)
720                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
721            if(speedLoopRightLeft_ < 0)
722                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
723            if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt)
724                speedLoopRightLeft_ = 0;
725        }
726
727        Vector3 transVector = Vector3::ZERO;
728*/
729/*
730        transVector.z = 1;
731        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
732        this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
733        this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
734        this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
735*/
736/*
737        transVector.x = 1;
738        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
739        this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
740        this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
741        this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
742*/
743    }
744/*
745    void SpaceShip::moveForward(float moveForward) {
746        moveForward_ = moveForward;
747    }
748
749    void SpaceShip::rotateUp(float rotateUp) {
750        rotateUp_ = rotateUp;
751    }
752
753    void SpaceShip::rotateDown(float rotateDown) {
754        rotateDown_ = rotateDown;
755    }
756
757    void SpaceShip::rotateLeft(float rotateLeft) {
758        rotateLeft_ = rotateLeft;
759    }
760
761    void SpaceShip::rotateRight(float rotateRight) {
762        rotateRight_ = rotateRight;
763    }
764
765    void SpaceShip::loopLeft(float loopLeft) {
766        loopLeft_ = loopLeft;
767    }
768
769    void SpaceShip::loopRight(float loopRight) {
770        loopRight_ = loopRight;
771    }
772
773    void SpaceShip::brakeForward(float brakeForward) {
774        brakeForward_ = brakeForward;
775    }
776
777    void SpaceShip::brakeRotate(float brakeRotate) {
778        brakeRotate_ = brakeRotate;
779    }
780
781    void SpaceShip::brakeLoop(float brakeLoop) {
782        brakeLoop_ = brakeLoop;
783    }
784
785    void SpaceShip::maxSpeedForward(float maxSpeedForward) {
786        maxSpeedForward_ = maxSpeedForward;
787    }
788
789    void SpaceShip::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) {
790        maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
791    }
792
793    void SpaceShip::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) {
794        maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
795    }
796
797    void SpaceShip::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) {
798        maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
799    }
800*/
801}
Note: See TracBrowser for help on using the repository browser.