Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/SpaceShip.cc @ 1755

Last change on this file since 1755 was 1755, checked in by rgrieder, 16 years ago

merged gui back to trunk.
update the media repository!

  • Property svn:eol-style set to native
File size: 24.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      Benjamin Knecht
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "SpaceShip.h"
31
32#include <OgreCamera.h>
33#include <OgreRenderWindow.h>
34#include <OgreParticleSystem.h>
35#include <OgreSceneNode.h>
36
37#include "util/Convert.h"
38#include "util/Math.h"
39#include "util/Debug.h"
40#include "core/CoreIncludes.h"
41#include "core/ConfigValueIncludes.h"
42#include "core/Iterator.h"
43#include "core/input/InputManager.h"
44#include "core/XMLPort.h"
45#include "core/ConsoleCommand.h"
46#include "tools/ParticleInterface.h"
47#include "network/Client.h"
48#include "Backlight.h"
49#include "CameraHandler.h"
50#include "ParticleSpawner.h"
51#include "Settings.h"
52#include "RotatingProjectile.h"
53#include "ParticleProjectile.h"
54#include "GraphicsEngine.h"
55
56namespace orxonox
57{
58    SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).accessLevel(AccessLevel::Debug);
59    SetConsoleCommand(SpaceShip, whereAmI, true).accessLevel(AccessLevel::User);
60    SetConsoleCommand(SpaceShip, moveLongitudinal, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
61    SetConsoleCommand(SpaceShip, moveLateral, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
62    SetConsoleCommand(SpaceShip, moveYaw, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
63    SetConsoleCommand(SpaceShip, movePitch, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
64    SetConsoleCommand(SpaceShip, moveRoll, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
65    SetConsoleCommand(SpaceShip, fire, true).accessLevel(AccessLevel::User).keybindMode(KeybindMode::OnHold);
66    SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxSpeed", 1, false).accessLevel(AccessLevel::Debug);
67    SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxBlubber", 2, false).accessLevel(AccessLevel::Debug);
68    SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setRofl", 3, false).accessLevel(AccessLevel::Debug);
69
70    CreateFactory(SpaceShip);
71
72    SpaceShip* SpaceShip::instance_s;
73
74
75    SpaceShip *SpaceShip::getLocalShip(){
76      ObjectList<SpaceShip>::iterator it;
77      for(it = ObjectList<SpaceShip>::begin(); it; ++it){
78        if( (it)->myShip_ )
79          return *it;
80      }
81      assert(0);
82      return 0;
83    }
84
85    SpaceShip::SpaceShip()
86    {
87        RegisterObject(SpaceShip);
88
89        this->setRotationAxis(1, 0, 0);
90        this->setStatic(false);
91
92        this->zeroRadian_ = 0;
93        this->maxSideAndBackSpeed_ = 0;
94        this->maxSpeed_ = 0;
95        this->maxRotation_ = 0;
96        this->translationAcceleration_ = 0;
97        this->rotationAcceleration_ = 0;
98        this->translationDamping_ = 0;
99        this->rotationDamping_ = 0;
100        this->maxRotationRadian_ = 0;
101        this->rotationAccelerationRadian_ = 0;
102        this->rotationDampingRadian_ = 0;
103
104        this->cam_ = 0;
105        this->tt1_ = 0;
106        this->tt2_ = 0;
107        this->smoke_ = 0;
108        this->fire_ = 0;
109
110        this->backlight_ = 0;
111
112        this->redNode_ = 0;
113        this->greenNode_ = 0;
114        this->blinkTime_ = 0;
115
116        this->timeToReload_ = 0;
117
118        this->bLMousePressed_ = false;
119        this->bRMousePressed_ = false;
120        this->mouseXRotation_ = 0;
121        this->mouseYRotation_ = 0;
122        this->myShip_ = false;
123
124        this->registerAllVariables();
125
126        SpaceShip::instance_s = this;
127
128        this->setConfigValues();
129
130        this->initialDir_ = Vector3(1.0, 0.0, 0.0);
131        this->currentDir_ = initialDir_;
132        this->initialOrth_ = Vector3(0.0, 0.0, 1.0);
133        this->currentOrth_ = initialOrth_;
134
135        this->camName_ = this->getName() + "CamNode";
136
137        this->teamNr_ = 0;
138        this->health_ = 100;
139
140        this->radarObject_ = static_cast<WorldEntity*>(this);
141    }
142
143    SpaceShip::~SpaceShip()
144    {
145        if (this->isInitialized())
146        {
147            if (this->tt1_)
148                delete this->tt1_;
149            if (this->tt2_)
150                delete this->tt2_;
151
152            if (this->smoke_)
153                this->smoke_->destroy();
154            if (this->fire_)
155                this->fire_->destroy();
156
157            if (this->backlight_)
158                delete this->backlight_;
159
160            if (this->cam_)
161                delete this->cam_;
162        }
163    }
164
165    bool SpaceShip::create(){
166      if(!myShip_){
167        if(network::Host::running())
168          COUT(3) << "this id: " << this->objectID << " myShipID: " << network::Host::getShipID() << std::endl;
169        if(network::Host::running() && objectID == network::Host::getShipID()){
170          if(!network::Host::isServer())
171            setObjectMode(0x3);
172          myShip_=true;
173        }
174        else
175          this->setRadarObjectColour(this->getProjectileColour());
176      }
177      assert(Model::create());
178      this->init();
179      return true;
180    }
181
182    void SpaceShip::registerAllVariables(){
183      registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 );
184      registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
185      registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
186      registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1);
187      registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1);
188      registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1);
189      registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1);
190      registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1);
191      registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1);
192      registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1);
193
194    }
195
196    void SpaceShip::init()
197    {
198        if (Settings::showsGraphics())
199        {
200            // START CREATING THRUSTERS
201            this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low);
202            this->tt1_->createNewEmitter();
203            this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir());
204            this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1));
205            this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1));
206            this->tt1_->setSpeedFactor(3.0);
207
208            Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a");
209            node2a->setInheritScale(false);
210            node2a->setScale(1, 1, 1);
211            tt1_->addToSceneNode(node2a);
212
213            this->tt2_ = new ParticleInterface("Orxonox/thruster2", LODParticle::normal);
214            this->tt2_->createNewEmitter();
215            this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0));
216            this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2));
217            this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2));
218
219            Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b");
220            node2b->setInheritScale(false);
221            node2b->setScale(0.5, 0.5, 0.5);
222            tt2_->addToSceneNode(node2b);
223
224            this->leftThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, -10, -0.5));
225            this->rightThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, 10, -0.5));
226
227            Ogre::SceneNode* node2c = this->getNode()->createChildSceneNode(this->getName() + "particle2c");
228            node2c->setInheritScale(false);
229            node2c->setScale(2, 2, 2);
230            node2c->attachObject(this->leftThrusterFlare_.getBillboardSet());
231            node2c->attachObject(this->rightThrusterFlare_.getBillboardSet());
232            // END CREATING THRUSTERS
233
234            // START CREATING BLINKING LIGHTS
235            this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
236            this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1);
237
238            this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3));
239            this->redNode_->setInheritScale(false);
240            this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3));
241            this->greenNode_->setInheritScale(false);
242
243            this->redNode_->attachObject(this->redBillboard_.getBillboardSet());
244            this->redNode_->setScale(0.3, 0.3, 0.3);
245
246            this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet());
247            this->greenNode_->setScale(0.3, 0.3, 0.3);
248            // END CREATING BLINKING LIGHTS
249
250            // START CREATING ADDITIONAL EFFECTS
251            /*this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
252            this->attachObject(this->backlight_);
253            this->backlight_->setPosition(-2.35, 0, 0.2);
254            this->backlight_->setColour(this->getProjectileColour());
255
256            this->smoke_ = new ParticleSpawner();
257            this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
258            this->attachObject(this->smoke_);
259
260            this->fire_ = new ParticleSpawner();
261            this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
262            this->attachObject(this->fire_);
263            */
264            // END CREATING ADDITIONAL EFFECTS
265
266            if (this->isExactlyA(Class(SpaceShip)))
267            {
268                // START of testing crosshair
269                this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
270                this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
271
272                this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
273                this->chNearNode_->setInheritScale(false);
274                this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
275                this->chFarNode_->setInheritScale(false);
276
277                this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
278                this->chNearNode_->setScale(0.2, 0.2, 0.2);
279
280                this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
281                this->chFarNode_->setScale(0.4, 0.4, 0.4);
282                // END of testing crosshair
283            }
284        }
285        // END of testing crosshair
286
287        createCamera();
288    }
289
290    void SpaceShip::setConfigValues()
291    {
292        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
293        SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds");
294        SetConfigValue(testvector_, Vector3()).description("asdfblah");
295    }
296
297    void SpaceShip::changedVisibility()
298    {
299        SUPER(SpaceShip, changedVisibility);
300
301        this->tt1_->setEnabled(this->isVisible());
302        this->tt2_->setEnabled(this->isVisible());
303        this->redBillboard_.setVisible(this->isVisible());
304        this->greenBillboard_.setVisible(this->isVisible());
305        this->crosshairNear_.setVisible(this->isVisible());
306        this->crosshairFar_.setVisible(this->isVisible());
307        this->rightThrusterFlare_.setVisible(this->isVisible());
308        this->leftThrusterFlare_.setVisible(this->isVisible());
309        this->smoke_->setVisible(this->isVisible());
310        this->fire_->setVisible(this->isVisible());
311        this->backlight_->setVisible(this->isVisible());
312    }
313
314    void SpaceShip::changedActivity()
315    {
316        SUPER(SpaceShip, changedActivity);
317
318        this->tt1_->setEnabled(this->isVisible());
319        this->tt2_->setEnabled(this->isVisible());
320        this->redBillboard_.setVisible(this->isVisible());
321        this->greenBillboard_.setVisible(this->isVisible());
322        this->crosshairNear_.setVisible(this->isVisible());
323        this->crosshairFar_.setVisible(this->isVisible());
324        this->rightThrusterFlare_.setVisible(this->isVisible());
325        this->leftThrusterFlare_.setVisible(this->isVisible());
326    }
327
328    void SpaceShip::setCamera(const std::string& camera)
329    {
330      camName_=camera;
331      // change camera attributes here, if you want to ;)
332    }
333
334    void SpaceShip::getFocus(){
335      COUT(3) << "requesting focus" << std::endl;
336      //if(!network::Host::running() || network::Host::getShipID()==objectID)
337      if(myShip_)
338        CameraHandler::getInstance()->requestFocus(cam_);
339
340    }
341
342    Camera* SpaceShip::getCamera(){
343        return cam_;
344    }
345
346    void SpaceShip::createCamera(){
347//       COUT(4) << "begin camera creation" << std::endl;
348      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
349      COUT(3) << "position: (this)" << this->getNode()->getPosition() << std::endl;
350      this->camNode_->setPosition(Vector3(-25,0,5));
351//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
352//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
353//      camNode_->setOrientation(q1*q2);
354      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
355      cam_ = new Camera(this->camNode_);
356
357      cam_->setTargetNode(this->getNode());
358//        cam->setPosition(Vector3(0,-350,0));
359//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,0,1));
360//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,1,0));
361      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
362      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0));
363
364       this->camNode_->setOrientation(q2*q1);
365      //if(!network::Host::running() || network::Host::getShipID()==objectID){ //TODO: check this
366      if(myShip_){
367        COUT(3) << "requesting focus for camera" << std::endl;
368        //CameraHandler::getInstance()->requestFocus(cam_);
369        if(this->isExactlyA(Class(SpaceShip))){
370          getFocus();
371          COUT(3) << "getting focus for obj id: " << objectID << std::endl;
372        }else
373          COUT(3) << "not getting focus (not exactly spaceship) for obj id: " << objectID << std::endl;
374      }else
375        COUT(3) << "not getting focus (not my ship) for obj id: " << objectID << std::endl;
376    }
377
378    void SpaceShip::setMaxSpeed(float value)
379    { this->maxSpeed_ = value; }
380    void SpaceShip::setMaxSideAndBackSpeed(float value)
381    { this->maxSideAndBackSpeed_ = value; }
382    void SpaceShip::setMaxRotation(float value)
383    { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); }
384    void SpaceShip::setTransAcc(float value)
385    { this->translationAcceleration_ = value; }
386    void SpaceShip::setRotAcc(float value)
387    { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); }
388    void SpaceShip::setTransDamp(float value)
389    { this->translationDamping_ = value; }
390    void SpaceShip::setRotDamp(float value)
391    { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); }
392
393    /**
394        @brief XML loading and saving.
395        @param xmlelement The XML-element
396        @param loading Loading (true) or saving (false)
397        @return The XML-element
398    */
399    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
400    {
401        SUPER(SpaceShip, XMLPort, xmlelement, mode);
402
403        XMLPortParam(SpaceShip, "camera", setCamera, getCamera, xmlelement, mode);
404        XMLPortParam(SpaceShip, "maxSpeed", setMaxSpeed, getMaxSpeed, xmlelement, mode);
405        XMLPortParam(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, getMaxSideAndBackSpeed, xmlelement, mode);
406        XMLPortParam(SpaceShip, "maxRotation", setMaxRotation, getMaxRotation, xmlelement, mode);
407        XMLPortParam(SpaceShip, "transAcc", setTransAcc, getTransAcc, xmlelement, mode);
408        XMLPortParam(SpaceShip, "rotAcc", setRotAcc, getRotAcc, xmlelement, mode);
409        XMLPortParam(SpaceShip, "transDamp", setTransDamp, getTransDamp, xmlelement, mode);
410        XMLPortParam(SpaceShip, "rotDamp", setRotDamp, getRotDamp, xmlelement, mode);
411
412        myShip_=true; //TODO: this is a hack
413        SpaceShip::create();
414        /*if (this->isExactlyA(Class(SpaceShip)))
415            getFocus();*/
416    }
417
418    std::string SpaceShip::whereAmI() {
419        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
420        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
421        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
422    }
423
424    void SpaceShip::tick(float dt)
425    {
426        if (!this->isActive())
427            return;
428
429        currentDir_ = getOrientation()*initialDir_;
430        currentOrth_ = getOrientation()*initialOrth_;
431
432        if (this->cam_)
433            this->cam_->tick(dt);
434
435        if (Settings::showsGraphics())
436        {
437            if (this->smoke_)
438                this->smoke_->setVisible(this->isVisible() && this->health_ < 40);
439            if (this->fire_)
440                this->fire_->setVisible(this->isVisible() && this->health_ < 20);
441
442            if (this->backlight_)
443            {   // (there's already fire ||                 we're to slow                 ||                  we're moving backwards                  )
444                if (this->health_ < 20   || this->getVelocity().squaredLength() < 150*150 || this->getVelocity().dotProduct(this->getInitialDir()) < 0)
445                    this->backlight_->setActive(false);
446                else
447                    this->backlight_->setActive(true);
448            }
449
450            if (this->redNode_ && this->greenNode_)
451            {
452                this->blinkTime_ += dt;
453                float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0);
454                float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0);
455                this->redNode_->setScale(redScale, redScale, redScale);
456                this->greenNode_->setScale(greenScale, greenScale, greenScale);
457            }
458        }
459
460        if (this->timeToReload_ > 0)
461            this->timeToReload_ -= dt;
462        else
463            this->timeToReload_ = 0;
464
465        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
466        {
467
468            BillboardProjectile* projectile = new ParticleProjectile(this);
469            projectile->setColour(this->getProjectileColour());
470            projectile->create();
471            if (projectile->classID == 0)
472            {
473              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
474            }
475
476            projectile->setObjectMode(0x3);
477            this->timeToReload_ = this->reloadTime_;
478        }
479
480
481        // #####################################
482        // ############# STEERING ##############
483        // #####################################
484
485        if (this->velocity_.x > this->maxSpeed_)
486            this->velocity_.x = this->maxSpeed_;
487        if (this->velocity_.x < -this->maxSideAndBackSpeed_)
488            this->velocity_.x = -this->maxSideAndBackSpeed_;
489        if (this->velocity_.y > this->maxSideAndBackSpeed_)
490            this->velocity_.y = this->maxSideAndBackSpeed_;
491        if (this->velocity_.y < -this->maxSideAndBackSpeed_)
492            this->velocity_.y = -this->maxSideAndBackSpeed_;
493        if (this->rotationRate_ > this->maxRotationRadian_)
494            this->rotationRate_ = this->maxRotationRadian_;
495        if (this->rotationRate_ < -this->maxRotationRadian_)
496            this->rotationRate_ = -this->maxRotationRadian_;
497
498        if (this->acceleration_.x == 0)
499        {
500            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            else if (this->velocity_.x < 0)
507            {
508                this->velocity_.x += (this->translationDamping_ * dt);
509                if (this->velocity_.x > 0)
510                    this->velocity_.x = 0;
511            }
512        }
513
514        if (this->acceleration_.y == 0)
515        {
516            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            else if (this->velocity_.y < 0)
523            {
524                this->velocity_.y += (this->translationDamping_ * dt);
525                if (this->velocity_.y > 0)
526                    this->velocity_.y = 0;
527            }
528        }
529
530        if (this->momentum_ == this->zeroRadian_)
531        {
532            if (this->rotationRate_ > this->zeroRadian_)
533            {
534                this->rotationRate_ -= (this->rotationDampingRadian_ * dt);
535                if (this->rotationRate_ < this->zeroRadian_)
536                    this->rotationRate_ = 0;
537            }
538            else if (this->rotationRate_ < this->zeroRadian_)
539            {
540                this->rotationRate_ += (this->rotationDampingRadian_ * dt);
541                if (this->rotationRate_ > this->zeroRadian_)
542                    this->rotationRate_ = 0;
543            }
544        }
545
546
547        SUPER(SpaceShip, tick, dt);
548
549        this->roll(this->mouseXRotation_ * dt);
550        if (this->bInvertYAxis_)
551            this->yaw(Radian(-this->mouseYRotation_ * dt));
552        else
553            this->yaw(Radian(this->mouseYRotation_ * dt));
554
555        if (this->acceleration_.x > 0)
556        {
557            this->tt1_->setEnabled(true);
558            this->tt2_->setEnabled(true);
559        }
560        else
561        {
562            this->tt1_->setEnabled(false);
563            this->tt2_->setEnabled(false);
564        }
565
566        COUT(5) << "steering our ship: " << objectID << std::endl;
567        this->acceleration_.x = 0;
568        this->acceleration_.y = 0;
569        this->momentum_ = 0;
570        this->mouseXRotation_ = Radian(0);
571        this->mouseYRotation_ = Radian(0);
572        this->bLMousePressed_ = false;
573    }
574
575    void SpaceShip::movePitch(float val)
576    {   getLocalShip()->setMovePitch(val);   }
577    void SpaceShip::moveYaw(float val)
578    {   getLocalShip()->setMoveYaw(val);   }
579    void SpaceShip::moveRoll(float val)
580    {   getLocalShip()->setMoveRoll(val);   }
581    void SpaceShip::moveLongitudinal(float val)
582    {   getLocalShip()->setMoveLongitudinal(val);   }
583    void SpaceShip::moveLateral(float val)
584    {   getLocalShip()->setMoveLateral(val);   }
585    void SpaceShip::fire()
586    {   getLocalShip()->doFire();   }
587
588    void SpaceShip::setMovePitch(float val)
589    {
590        val = -val * val * sgn(val) * this->rotationAcceleration_;
591        if (val > this->maxRotation_)
592            val = this->maxRotation_;
593        if (val < -this->maxRotation_)
594            val = -this->maxRotation_;
595        this->mouseYRotation_ = Radian(val);
596    }
597
598    void SpaceShip::setMoveYaw(float val)
599    {
600        val = -val * val * sgn(val) * this->rotationAcceleration_;
601        if (val > this->maxRotation_)
602            val = this->maxRotation_;
603        if (val < -this->maxRotation_)
604            val = -this->maxRotation_;
605        this->mouseXRotation_ = Radian(val);
606    }
607
608    void SpaceShip::setMoveRoll(float val)
609    {
610        this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val);
611        //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl;
612    }
613
614    void SpaceShip::setMoveLongitudinal(float val)
615    {
616        this->acceleration_.x = this->translationAcceleration_ * val;
617    }
618
619    void SpaceShip::setMoveLateral(float val)
620    {
621        this->acceleration_.y = -this->translationAcceleration_ * val;
622    }
623
624    void SpaceShip::doFire()
625    {
626        this->bLMousePressed_ = true;
627    }
628}
Note: See TracBrowser for help on using the repository browser.