Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged network branch back into trunk

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