Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged hud branch back to trunk

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