Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

problems of the merge should be solved now (hopefully)

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