Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapon/src/orxonox/objects/SpaceShip.cc @ 2060

Last change on this file since 2060 was 2060, checked in by polakma, 16 years ago

WeaponSystem, Projectile (kompiliert nicht)

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