Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

cant remember ;)

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