Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/objects/SpaceShip.cc @ 1089

Last change on this file since 1089 was 1030, checked in by landauf, 17 years ago

extracted all config-value related macros from CoreIncludes.h and moved them to ConfigValueIncludes.h.

ConfigValueContainer can now handle std::vector<x> where 'x' is is any type supported by MultiTypeMath (all primitives, pointer, string, vector2, vector3, quaternion, colourvalue, radian, degree).

the vectors size is currently limited to 256 elements. this is just a practical limit, it can be raised if it's necessary. the reason for the limit is: you can add new elements to a vector by simply typing 'set classname varname index value' into the console or adding a new entry in the config-file. if 'index' is bigger than the vectors size, all elements up to 'index' are inserted. if the user accidentally enters a big number, he could end up with >4*109 elements in his config-file, resulting in 10-100gb on the hdd and a completely filled memory. and that's not exactly what i want ;)

File size: 28.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "OrxonoxStableHeaders.h"
29
30#include <string>
31
32#include <OIS/OIS.h>
33#include <OgreCamera.h>
34#include <OgreRenderWindow.h>
35#include <OgreParticleSystem.h>
36#include <OgreSceneNode.h>
37
38#include "util/tinyxml/tinyxml.h"
39#include "util/String2Number.h"
40#include "util/Math.h"
41#include "core/CoreIncludes.h"
42#include "core/ConfigValueIncludes.h"
43#include "core/Debug.h"
44#include "../Orxonox.h"
45#include "../particle/ParticleInterface.h"
46#include "Projectile.h"
47#include "core/XMLPort.h"
48#include "core/ConsoleCommand.h"
49
50#include "SpaceShip.h"
51
52namespace orxonox
53{
54    ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false);
55    ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false);
56    ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false);
57    ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false);
58
59    CreateFactory(SpaceShip);
60
61    SpaceShip* SpaceShip::instance_s;
62
63    SpaceShip::SpaceShip()
64    {
65        RegisterObject(SpaceShip);
66
67        SpaceShip::instance_s = this;
68
69        this->setConfigValues();
70
71        this->setMouseEventCallback_ = false;
72        this->bLMousePressed_ = false;
73        this->bRMousePressed_ = false;
74        this->mouseX_ = 0;
75        this->mouseY_ = 0;
76
77        this->camNode_ = 0;
78
79        this->tt_ = 0;
80        this->redNode_ = 0;
81        this->greenNode_ = 0;
82        this->blinkTime_ = 0;
83
84        this->timeToReload_ = 0;
85
86        this->maxSpeed_ = 0;
87        this->maxSideAndBackSpeed_ = 0;
88        this->maxRotation_ = 0;
89        this->translationAcceleration_ = 0;
90        this->rotationAcceleration_ = 0;
91        this->translationDamping_ = 0;
92        this->rotationDamping_ = 0;
93
94        this->maxRotationRadian_ = 0;
95        this->rotationAccelerationRadian_ = 0;
96        this->rotationDampingRadian_ = 0;
97        this->zeroRadian_ = Radian(0);
98
99        this->setRotationAxis(1, 0, 0);
100        this->setStatic(false);
101/*
102        this->moveForward_ = 0;
103        this->rotateUp_ = 0;
104        this->rotateDown_ = 0;
105        this->rotateRight_ = 0;
106        this->rotateLeft_ = 0;
107        this->loopRight_ = 0;
108        this->loopLeft_ = 0;
109        this->brakeForward_ = 0;
110        this->brakeRotate_ = 0;
111        this->brakeLoop_ = 0;
112        this->speedForward_ = 0;
113        this->speedRotateUpDown_ = 0;
114        this->speedRotateRightLeft_ = 0;
115        this->speedLoopRightLeft_ = 0;
116        this->maxSpeedForward_ = 0;
117        this->maxSpeedRotateUpDown_ = 0;
118        this->maxSpeedRotateRightLeft_ = 0;
119        this->maxSpeedLoopRightLeft_ = 0;
120        this->accelerationForward_ = 0;
121        this->accelerationRotateUpDown_ = 0;
122        this->accelerationRotateRightLeft_ = 0;
123        this->accelerationLoopRightLeft_ = 0;
124
125        this->speed = 250;
126        this->loop = 100;
127        this->rotate = 10;
128        this->mouseX = 0;
129        this->mouseY = 0;
130        this->maxMouseX = 0;
131        this->minMouseX = 0;
132        this->moved = false;
133
134        this->brakeRotate(rotate*10);
135        this->brakeLoop(loop);
136*/
137        this->init();
138
139        COUT(3) << "Info: SpaceShip was loaded" << std::endl;
140    }
141
142    SpaceShip::~SpaceShip()
143    {
144        if (this->tt_)
145            delete this->tt_;
146    }
147
148    void SpaceShip::init()
149    {
150        // START CREATING THRUSTER
151        this->tt_ = new ParticleInterface(Orxonox::getSingleton()->getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
152        this->tt_->getParticleSystem()->setParameter("local_space","true");
153        this->tt_->newEmitter();
154/*
155        this->tt_->setDirection(Vector3(0,0,1));
156        this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15));
157        this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15));
158*/
159        this->tt_->setDirection(Vector3(-1,0,0));
160        this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1));
161        this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1));
162        this->tt_->setVelocity(50);
163
164        emitterRate_ = tt_->getRate();
165
166        Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2");
167        node2->setInheritScale(false);
168        tt_->addToSceneNode(node2);
169        // END CREATING THRUSTER
170
171        // START CREATING BLINKING LIGHTS
172        this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
173        this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1);
174
175        this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.7, -0.3));
176        this->redNode_->setInheritScale(false);
177        this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.7, -0.3));
178        this->greenNode_->setInheritScale(false);
179
180        this->redNode_->attachObject(this->redBillboard_.getBillboardSet());
181        this->redNode_->setScale(0.3, 0.3, 0.3);
182
183        this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet());
184        this->greenNode_->setScale(0.3, 0.3, 0.3);
185        // END CREATING BLINKING LIGHTS
186
187        // START of testing crosshair
188        this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
189        this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
190
191        this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
192        this->chNearNode_->setInheritScale(false);
193        this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
194        this->chFarNode_->setInheritScale(false);
195
196        this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
197        this->chNearNode_->setScale(0.2, 0.2, 0.2);
198
199        this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
200        this->chFarNode_->setScale(0.4, 0.4, 0.4);
201
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        Model::loadParams(xmlElem);
215/*
216        if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
217        {
218            std::string forwardStr = xmlElem->Attribute("forward");
219            std::string rotateupdownStr = xmlElem->Attribute("rotateupdown");
220            std::string rotaterightleftStr = xmlElem->Attribute("rotaterightleft");
221            std::string looprightleftStr = xmlElem->Attribute("looprightleft");
222
223            String2Number<float>(this->maxSpeedForward_, forwardStr);
224            String2Number<float>(this->maxSpeedRotateUpDown_, rotateupdownStr);
225            String2Number<float>(this->maxSpeedRotateRightLeft_, rotaterightleftStr);
226            String2Number<float>(this->maxSpeedLoopRightLeft_, looprightleftStr);
227
228            COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl;
229        }
230*/
231        if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp"))
232        {
233
234            std::string msStr = xmlElem->Attribute("maxSpeed");
235            std::string msabsStr = xmlElem->Attribute("maxSideAndBackSpeed");
236            std::string mrStr = xmlElem->Attribute("maxRotation");
237            std::string taStr = xmlElem->Attribute("transAcc");
238            std::string raStr = xmlElem->Attribute("rotAcc");
239            std::string tdStr = xmlElem->Attribute("transDamp");
240            std::string rdStr = xmlElem->Attribute("rotDamp");
241
242            String2Number<float>(this->maxSpeed_, msStr);
243            String2Number<float>(this->maxSideAndBackSpeed_, msabsStr);
244            String2Number<float>(this->maxRotation_, mrStr);
245            String2Number<float>(this->translationAcceleration_, taStr);
246            String2Number<float>(this->rotationAcceleration_, raStr);
247            String2Number<float>(this->translationDamping_, tdStr);
248            String2Number<float>(this->rotationDamping_, rdStr);
249
250            this->maxRotationRadian_ = Radian(this->maxRotation_);
251            this->rotationAccelerationRadian_ = Radian(this->rotationAcceleration_);
252            this->rotationDampingRadian_ = Radian(this->rotationDamping_);
253
254            COUT(4) << "Loader: Initialized SpaceShip" << std::endl;
255        }
256
257        if (xmlElem->Attribute("camera"))
258        {
259            this->setCamera();
260        }
261    }
262
263    void SpaceShip::setCamera(const std::string& camera)
264    {
265        Ogre::Camera *cam = Orxonox::getSingleton()->getSceneManager()->createCamera("ShipCam");
266        this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
267/*
268//        node->setInheritOrientation(false);
269        cam->setPosition(Vector3(0,50,-150));
270        cam->lookAt(Vector3(0,20,0));
271        cam->roll(Degree(0));
272*/
273
274        cam->setPosition(Vector3(-200,0,35));
275//        cam->setPosition(Vector3(0,-350,0));
276        cam->lookAt(Vector3(0,0,35));
277        cam->roll(Degree(-90));
278
279        this->camNode_->attachObject(cam);
280        Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
281    }
282
283    void SpaceShip::setMaxSpeed(float value)
284    { this->maxSpeed_ = value; }
285    void SpaceShip::setMaxSideAndBackSpeed(float value)
286    { this->maxSideAndBackSpeed_ = value; }
287    void SpaceShip::setMaxRotation(float value)
288    { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); }
289    void SpaceShip::setTransAcc(float value)
290    { this->translationAcceleration_ = value; }
291    void SpaceShip::setRotAcc(float value)
292    { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); }
293    void SpaceShip::setTransDamp(float value)
294    { this->translationDamping_ = value; }
295    void SpaceShip::setRotDamp(float value)
296    { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); }
297
298    /**
299        @brief XML loading and saving.
300        @param xmlelement The XML-element
301        @param loading Loading (true) or saving (false)
302        @return The XML-element
303    */
304    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
305    {
306        Model::XMLPort(xmlelement, mode);
307
308        XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode);
309        XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode);
310        XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode);
311        XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode);
312        XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode);
313        XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode);
314        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
315        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
316    }
317
318    int sgn(float x)
319    {
320        if (x >= 0)
321            return 1;
322        else
323            return -1;
324    }
325
326    bool SpaceShip::mouseMoved(const OIS::MouseEvent &e)
327    {
328/*
329        this->mouseX += e.state.X.rel;
330        if (this->bInvertMouse_)
331            this->mouseY += e.state.Y.rel;
332        else
333            this->mouseY -= e.state.Y.rel;
334
335//        if(mouseX>maxMouseX) maxMouseX = mouseX;
336//        if(mouseX<minMouseX) minMouseX = mouseX;
337//        cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;
338
339        this->moved = true;
340*/
341        if (this->bRMousePressed_)
342        {
343            this->camNode_->roll(Degree(-e.state.X.rel * 0.10));
344            this->camNode_->yaw(Degree(e.state.Y.rel * 0.10));
345        }
346        else
347        {
348            float minDimension = e.state.height;
349            if (e.state.width < minDimension)
350                minDimension = e.state.width;
351
352            this->mouseX_ += e.state.X.rel;
353            if (this->mouseX_ < -minDimension)
354                this->mouseX_ = -minDimension;
355            if (this->mouseX_ > minDimension)
356                this->mouseX_ = minDimension;
357
358            this->mouseY_ += e.state.Y.rel;
359            if (this->mouseY_ < -minDimension)
360                this->mouseY_ = -minDimension;
361            if (this->mouseY_ > minDimension)
362                this->mouseY_ = minDimension;
363
364            float xRotation = this->mouseX_ / minDimension;
365            xRotation = xRotation*xRotation * sgn(xRotation);
366            xRotation *= -this->rotationAcceleration_;
367            if (xRotation > this->maxRotation_)
368                xRotation = this->maxRotation_;
369            if (xRotation < -this->maxRotation_)
370                xRotation = -this->maxRotation_;
371            this->mouseXRotation_ = Radian(xRotation);
372
373            float yRotation = this->mouseY_ / minDimension;
374            yRotation = yRotation*yRotation * sgn(yRotation);
375            yRotation *= this->rotationAcceleration_;
376            if (yRotation > this->maxRotation_)
377                yRotation = this->maxRotation_;
378            if (yRotation < -this->maxRotation_)
379                yRotation = -this->maxRotation_;
380            this->mouseYRotation_ = Radian(yRotation);
381        }
382
383        return true;
384    }
385
386    bool SpaceShip::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
387    {
388        if (id == OIS::MB_Left)
389            this->bLMousePressed_ = true;
390        else if (id == OIS::MB_Right)
391            this->bRMousePressed_ = true;
392
393        return true;
394    }
395
396    bool SpaceShip::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
397    {
398        if (id == OIS::MB_Left)
399            this->bLMousePressed_ = false;
400        else if (id == OIS::MB_Right)
401        {
402            this->bRMousePressed_ = false;
403            this->camNode_->resetOrientation();
404        }
405
406        return true;
407    }
408
409    void SpaceShip::tick(float dt)
410    {
411        if (!this->setMouseEventCallback_)
412        {
413            if (Orxonox::getSingleton()->getMouse())
414            {
415                Orxonox::getSingleton()->getMouse()->setEventCallback(this);
416                this->setMouseEventCallback_ = true;
417            }
418        }
419
420        if (this->redNode_ && this->greenNode_)
421        {
422            this->blinkTime_ += dt;
423            float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0);
424            float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0);
425            this->redNode_->setScale(redScale, redScale, redScale);
426            this->greenNode_->setScale(greenScale, greenScale, greenScale);
427        }
428
429        if (this->timeToReload_ > 0)
430            this->timeToReload_ -= dt;
431        else
432            this->timeToReload_ = 0;
433
434        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
435        {
436            new Projectile(this);
437            this->timeToReload_ = this->reloadTime_;
438        }
439
440        OIS::Keyboard* mKeyboard = Orxonox::getSingleton()->getKeyboard();
441        OIS::Mouse* mMouse = Orxonox::getSingleton()->getMouse();
442
443        mKeyboard->capture();
444        mMouse->capture();
445
446
447        // #####################################
448        // ############# STEERING ##############
449        // #####################################
450
451        if (this->velocity_.x > this->maxSpeed_)
452            this->velocity_.x = this->maxSpeed_;
453        if (this->velocity_.x < -this->maxSideAndBackSpeed_)
454            this->velocity_.x = -this->maxSideAndBackSpeed_;
455        if (this->velocity_.y > this->maxSideAndBackSpeed_)
456            this->velocity_.y = this->maxSideAndBackSpeed_;
457        if (this->velocity_.y < -this->maxSideAndBackSpeed_)
458            this->velocity_.y = -this->maxSideAndBackSpeed_;
459        if (this->rotationRate_ > this->maxRotationRadian_)
460            this->rotationRate_ = this->maxRotationRadian_;
461        if (this->rotationRate_ < -this->maxRotationRadian_)
462            this->rotationRate_ = -this->maxRotationRadian_;
463
464        if (this->acceleration_.x == 0)
465        {
466            if (this->velocity_.x > 0)
467            {
468                this->velocity_.x -= (this->translationDamping_ * dt);
469                if (this->velocity_.x < 0)
470                    this->velocity_.x = 0;
471            }
472            else if (this->velocity_.x < 0)
473            {
474                this->velocity_.x += (this->translationDamping_ * dt);
475                if (this->velocity_.x > 0)
476                    this->velocity_.x = 0;
477            }
478        }
479
480        if (this->acceleration_.y == 0)
481        {
482            if (this->velocity_.y > 0)
483            {
484                this->velocity_.y -= (this->translationDamping_ * dt);
485                if (this->velocity_.y < 0)
486                    this->velocity_.y = 0;
487            }
488            else if (this->velocity_.y < 0)
489            {
490                this->velocity_.y += (this->translationDamping_ * dt);
491                if (this->velocity_.y > 0)
492                    this->velocity_.y = 0;
493            }
494        }
495
496        if (this->momentum_ == this->zeroRadian_)
497        {
498            if (this->rotationRate_ > this->zeroRadian_)
499            {
500                this->rotationRate_ -= (this->rotationDampingRadian_ * dt);
501                if (this->rotationRate_ < this->zeroRadian_)
502                    this->rotationRate_ = 0;
503            }
504            else if (this->rotationRate_ < this->zeroRadian_)
505            {
506                this->rotationRate_ += (this->rotationDampingRadian_ * dt);
507                if (this->rotationRate_ > this->zeroRadian_)
508                    this->rotationRate_ = 0;
509            }
510        }
511
512        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
513            this->acceleration_.x = this->translationAcceleration_;
514        else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
515            this->acceleration_.x = -this->translationAcceleration_;
516        else
517            this->acceleration_.x = 0;
518
519        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
520            this->acceleration_.y = -this->translationAcceleration_;
521        else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
522            this->acceleration_.y = this->translationAcceleration_;
523        else
524            this->acceleration_.y = 0;
525
526        if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
527            this->momentum_ = Radian(-this->rotationAccelerationRadian_);
528        else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
529            this->momentum_ = Radian(this->rotationAccelerationRadian_);
530        else
531            this->momentum_ = 0;
532
533        WorldEntity::tick(dt);
534
535        this->roll(this->mouseXRotation_ * dt);
536        if (this->bInvertYAxis_)
537            this->yaw(Radian(-this->mouseYRotation_ * dt));
538        else
539            this->yaw(Radian(this->mouseYRotation_ * dt));
540
541        if (this->acceleration_.x > 0)
542            this->tt_->setRate(emitterRate_);
543        else
544            this->tt_->setRate(0);
545
546/*
547        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
548            this->moveForward(speed);
549        else
550            this->moveForward(0);
551
552        if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
553            this->brakeForward(speed);
554        else
555            this->brakeForward(speed/10);
556
557        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
558            this->loopRight(loop);
559        else
560            this->loopRight(0);
561
562        if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
563            this->loopLeft(loop);
564        else
565            this->loopLeft(0);
566
567        if(moved)
568        {
569            if (mouseY<=0)
570                this->rotateUp(-mouseY*rotate);
571            if (mouseY>0)
572                this->rotateDown(mouseY*rotate);
573            if (mouseX>0)
574                this->rotateRight(mouseX*rotate);
575            if (mouseX<=0)
576                this->rotateLeft(-mouseX*rotate);
577
578            mouseY = 0;
579            mouseX = 0;
580            moved = false;
581        }*/
582/*        else
583        {
584            this->rotateUp(0);
585            this->rotateDown(0);
586            this->rotateRight(0);
587            this->rotateLeft(0);
588        }*/
589/*
590        if(moveForward_ > 0)
591        {
592            accelerationForward_ = moveForward_;
593            if(speedForward_ < maxSpeedForward_)
594                speedForward_ += accelerationForward_*dt;
595            if(speedForward_ > maxSpeedForward_)
596                speedForward_ = maxSpeedForward_;
597        }
598
599        if(moveForward_ <= 0)
600        {
601            accelerationForward_ = -brakeForward_;
602            if(speedForward_ > 0)
603                speedForward_ += accelerationForward_*dt;
604            if(speedForward_ < 0)
605                speedForward_ = 0;
606        }
607
608        if(rotateUp_ > 0)
609        {
610            accelerationRotateUpDown_ = rotateUp_;
611            if(speedRotateUpDown_ < maxSpeedRotateUpDown_)
612                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
613            if(speedRotateUpDown_ > maxSpeedRotateUpDown_)
614            speedRotateUpDown_ = maxSpeedRotateUpDown_;
615        }
616
617        if(rotateDown_ > 0)
618        {
619            accelerationRotateUpDown_ = rotateDown_;
620            if(speedRotateUpDown_ > -maxSpeedRotateUpDown_)
621                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
622            if(speedRotateUpDown_ < -maxSpeedRotateUpDown_)
623                speedRotateUpDown_ = -maxSpeedRotateUpDown_;
624        }
625
626        if(rotateUp_ == 0 && rotateDown_ == 0)
627        {
628            accelerationRotateUpDown_ = brakeRotate_;
629            if(speedRotateUpDown_ > 0)
630                speedRotateUpDown_ -= accelerationRotateUpDown_*dt;
631            if(speedRotateUpDown_ < 0)
632                speedRotateUpDown_ += accelerationRotateUpDown_*dt;
633            if(fabs(speedRotateUpDown_) < accelerationRotateUpDown_*dt)
634                speedRotateUpDown_ = 0;
635        }
636
637        if(rotateRight_ > 0)
638        {
639            accelerationRotateRightLeft_ = rotateRight_;
640            if(speedRotateRightLeft_ > -maxSpeedRotateRightLeft_)
641                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
642            if(speedRotateRightLeft_ < -maxSpeedRotateRightLeft_)
643                speedRotateRightLeft_ = -maxSpeedRotateRightLeft_;
644        }
645
646        if(rotateLeft_ > 0)
647        {
648            accelerationRotateRightLeft_ = rotateLeft_;
649            if(speedRotateRightLeft_ < maxSpeedRotateRightLeft_)
650                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
651            if(speedRotateRightLeft_ > maxSpeedRotateRightLeft_)
652                speedRotateRightLeft_ = maxSpeedRotateRightLeft_;
653        }
654
655        if(rotateRight_ == 0 && rotateLeft_ == 0)
656        {
657            accelerationRotateRightLeft_ = brakeRotate_;
658            if(speedRotateRightLeft_ > 0)
659                speedRotateRightLeft_ -= accelerationRotateRightLeft_*dt;
660            if(speedRotateRightLeft_ < 0)
661                speedRotateRightLeft_ += accelerationRotateRightLeft_*dt;
662            if(fabs(speedRotateRightLeft_) < accelerationRotateRightLeft_*dt)
663                speedRotateRightLeft_ = 0;
664        }
665
666        if(loopRight_ > 0)
667        {
668            accelerationLoopRightLeft_ = loopRight_;
669            if(speedLoopRightLeft_ < maxSpeedLoopRightLeft_)
670                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
671            if(speedLoopRightLeft_ > maxSpeedLoopRightLeft_)
672                speedLoopRightLeft_ = maxSpeedLoopRightLeft_;
673        }
674
675        if(loopLeft_ > 0)
676        {
677            accelerationLoopRightLeft_ = loopLeft_;
678            if(speedLoopRightLeft_ > -maxSpeedLoopRightLeft_)
679                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
680            if(speedLoopRightLeft_ < -maxSpeedLoopRightLeft_)
681                speedLoopRightLeft_ = -maxSpeedLoopRightLeft_;
682        }
683
684        if(loopLeft_ == 0 && loopRight_ == 0)
685        {
686            accelerationLoopRightLeft_ = brakeLoop_;
687            if(speedLoopRightLeft_ > 0)
688                speedLoopRightLeft_ -= accelerationLoopRightLeft_*dt;
689            if(speedLoopRightLeft_ < 0)
690                speedLoopRightLeft_ += accelerationLoopRightLeft_*dt;
691            if(fabs(speedLoopRightLeft_) < accelerationLoopRightLeft_*dt)
692                speedLoopRightLeft_ = 0;
693        }
694
695        Vector3 transVector = Vector3::ZERO;
696*/
697/*
698        transVector.z = 1;
699        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
700        this->pitch(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
701        this->yaw(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
702        this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
703*/
704/*
705        transVector.x = 1;
706        this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL);
707        this->yaw(Degree(speedRotateUpDown_*dt), Ogre::Node::TS_LOCAL);
708        this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL);
709        this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL);
710*/
711    }
712/*
713    void SpaceShip::moveForward(float moveForward) {
714        moveForward_ = moveForward;
715    }
716
717    void SpaceShip::rotateUp(float rotateUp) {
718        rotateUp_ = rotateUp;
719    }
720
721    void SpaceShip::rotateDown(float rotateDown) {
722        rotateDown_ = rotateDown;
723    }
724
725    void SpaceShip::rotateLeft(float rotateLeft) {
726        rotateLeft_ = rotateLeft;
727    }
728
729    void SpaceShip::rotateRight(float rotateRight) {
730        rotateRight_ = rotateRight;
731    }
732
733    void SpaceShip::loopLeft(float loopLeft) {
734        loopLeft_ = loopLeft;
735    }
736
737    void SpaceShip::loopRight(float loopRight) {
738        loopRight_ = loopRight;
739    }
740
741    void SpaceShip::brakeForward(float brakeForward) {
742        brakeForward_ = brakeForward;
743    }
744
745    void SpaceShip::brakeRotate(float brakeRotate) {
746        brakeRotate_ = brakeRotate;
747    }
748
749    void SpaceShip::brakeLoop(float brakeLoop) {
750        brakeLoop_ = brakeLoop;
751    }
752
753    void SpaceShip::maxSpeedForward(float maxSpeedForward) {
754        maxSpeedForward_ = maxSpeedForward;
755    }
756
757    void SpaceShip::maxSpeedRotateUpDown(float maxSpeedRotateUpDown) {
758        maxSpeedRotateUpDown_ = maxSpeedRotateUpDown;
759    }
760
761    void SpaceShip::maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft) {
762        maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft;
763    }
764
765    void SpaceShip::maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft) {
766        maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft;
767    }
768*/
769}
Note: See TracBrowser for help on using the repository browser.