Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1602 was 1602, checked in by landauf, 16 years ago
  • added thruster flares
  • used new particle effects
  • enemies with less health emit smoke and fire

!!!! MEDIA UPDATE !!!

  • Property svn:eol-style set to native
File size: 22.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      Benjamin Knecht
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "SpaceShip.h"
31
32#include <OgreCamera.h>
33#include <OgreRenderWindow.h>
34#include <OgreParticleSystem.h>
35#include <OgreSceneNode.h>
36
37#include "CameraHandler.h"
38#include "util/Convert.h"
39#include "util/Math.h"
40#include "core/CoreIncludes.h"
41#include "core/ConfigValueIncludes.h"
42#include "core/Debug.h"
43#include "GraphicsEngine.h"
44#include "core/input/InputManager.h"
45#include "tools/ParticleInterface.h"
46#include "RotatingProjectile.h"
47#include "ParticleProjectile.h"
48#include "core/XMLPort.h"
49#include "core/ConsoleCommand.h"
50#include "network/Client.h"
51#include "hud/HUD.h"
52
53namespace orxonox
54{
55    SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug);
56    SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User);
57    SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
58    SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
59    SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
60    SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
61    SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold);
62    SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold);
63    SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);
64    SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);
65    SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);
66
67    CreateFactory(SpaceShip);
68
69    SpaceShip* SpaceShip::instance_s;
70
71
72    SpaceShip *SpaceShip::getLocalShip(){
73      Iterator<SpaceShip> it;
74      for(it = ObjectList<SpaceShip>::start(); it; ++it){
75        if( (it)->myShip_ )
76          return *it;
77      }
78      return NULL;
79    }
80
81    SpaceShip::SpaceShip()
82    {
83        RegisterObject(SpaceShip);
84
85        this->setRotationAxis(1, 0, 0);
86        this->setStatic(false);
87
88        this->zeroRadian_ = 0;
89        this->maxSideAndBackSpeed_ = 0;
90        this->maxSpeed_ = 0;
91        this->maxRotation_ = 0;
92        this->translationAcceleration_ = 0;
93        this->rotationAcceleration_ = 0;
94        this->translationDamping_ = 0;
95        this->rotationDamping_ = 0;
96        this->maxRotationRadian_ = 0;
97        this->rotationAccelerationRadian_ = 0;
98        this->rotationDampingRadian_ = 0;
99
100        this->cam_ = 0;
101        this->tt1_ = 0;
102        this->tt2_ = 0;
103
104        this->redNode_ = 0;
105        this->greenNode_ = 0;
106        this->blinkTime_ = 0;
107
108        this->timeToReload_ = 0;
109
110        this->setMouseEventCallback_ = false;
111        this->bLMousePressed_ = false;
112        this->bRMousePressed_ = false;
113        this->mouseXRotation_ = 0;
114        this->mouseYRotation_ = 0;
115        this->mouseX_ = 0;
116        this->mouseY_ = 0;
117        this->myShip_ = false;
118
119        this->registerAllVariables();
120
121        SpaceShip::instance_s = this;
122
123        this->setConfigValues();
124
125        this->initialDir_ = Vector3(1.0, 0.0, 0.0);
126        this->currentDir_ = initialDir_;
127        this->initialOrth_ = Vector3(0.0, 0.0, 1.0);
128        this->currentOrth_ = initialOrth_;
129
130        this->camName_ = this->getName() + "CamNode";
131
132        this->teamNr_ = 0;
133        this->health_ = 100;
134    }
135
136    SpaceShip::~SpaceShip()
137    {
138        if (this->isInitialized())
139        {
140            if (this->tt1_)
141                delete this->tt1_;
142            if (this->tt2_)
143                delete this->tt2_;
144
145            if (setMouseEventCallback_)
146                InputManager::removeMouseHandler("SpaceShip");
147
148            if (this->cam_)
149                delete this->cam_;
150
151            if (!this->myShip_)
152                HUD::getSingleton().removeRadarObject(this);
153        }
154    }
155
156    bool SpaceShip::create(){
157      if(!myShip_){
158        if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID())
159          myShip_=true;
160        else
161          HUD::getSingleton().addRadarObject(this, this->getProjectileColour());
162      }
163      if(Model::create())
164        this->init();
165      else
166        return false;
167      return true;
168    }
169
170    void SpaceShip::registerAllVariables(){
171      registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 );
172      registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
173      registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
174      registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1);
175      registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1);
176      registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1);
177      registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1);
178      registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1);
179      registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1);
180      registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1);
181
182    }
183
184    void SpaceShip::init()
185    {
186        // START CREATING THRUSTER
187        this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low);
188        this->tt1_->createNewEmitter();
189        this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir());
190        this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1));
191        this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1));
192        this->tt1_->setSpeedFactor(3.0);
193
194        Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a");
195        node2a->setInheritScale(false);
196        node2a->setScale(1, 1, 1);
197        tt1_->addToSceneNode(node2a);
198
199        this->tt2_ = new ParticleInterface("Orxonox/thruster2", LODParticle::normal);
200        this->tt2_->createNewEmitter();
201        this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0));
202        this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2));
203        this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2));
204
205        Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b");
206        node2b->setInheritScale(false);
207        node2b->setScale(0.5, 0.5, 0.5);
208        tt2_->addToSceneNode(node2b);
209
210        this->leftThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, -10, -0.5));
211        this->rightThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, 10, -0.5));
212
213        Ogre::SceneNode* node2c = this->getNode()->createChildSceneNode(this->getName() + "particle2c");
214        node2c->setInheritScale(false);
215        node2c->setScale(2, 2, 2);
216        node2c->attachObject(this->leftThrusterFlare_.getBillboardSet());
217        node2c->attachObject(this->rightThrusterFlare_.getBillboardSet());
218        // END CREATING THRUSTER
219
220        // START CREATING BLINKING LIGHTS
221        this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
222        this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1);
223
224        this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3));
225        this->redNode_->setInheritScale(false);
226        this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3));
227        this->greenNode_->setInheritScale(false);
228
229        this->redNode_->attachObject(this->redBillboard_.getBillboardSet());
230        this->redNode_->setScale(0.3, 0.3, 0.3);
231
232        this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet());
233        this->greenNode_->setScale(0.3, 0.3, 0.3);
234        // END CREATING BLINKING LIGHTS
235
236        this->smoke_.setParticle("Orxonox/smoke5", LODParticle::normal);
237        this->fire_.setParticle("Orxonox/fire3", LODParticle::normal);
238        this->attachObject(this->smoke_);
239        this->attachObject(this->fire_);
240
241        if (this->isExactlyA(Class(SpaceShip)))
242        {
243            // START of testing crosshair
244            this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
245            this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1);
246
247            this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0));
248            this->chNearNode_->setInheritScale(false);
249            this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0));
250            this->chFarNode_->setInheritScale(false);
251
252            this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet());
253            this->chNearNode_->setScale(0.2, 0.2, 0.2);
254
255            this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
256            this->chFarNode_->setScale(0.4, 0.4, 0.4);
257        }
258
259        createCamera();
260        // END of testing crosshair
261    }
262
263    void SpaceShip::setConfigValues()
264    {
265        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down).");
266        SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds");
267        SetConfigValue(testvector_, Vector3()).description("asdfblah");
268    }
269
270    void SpaceShip::changedVisibility()
271    {
272        Model::changedVisibility();
273
274        this->tt1_->setEnabled(this->isVisible());
275        this->tt2_->setEnabled(this->isVisible());
276        this->redBillboard_.setVisible(this->isVisible());
277        this->greenBillboard_.setVisible(this->isVisible());
278        this->crosshairNear_.setVisible(this->isVisible());
279        this->crosshairFar_.setVisible(this->isVisible());
280        this->rightThrusterFlare_.setVisible(this->isVisible());
281        this->leftThrusterFlare_.setVisible(this->isVisible());
282        this->smoke_.setVisible(this->isVisible());
283        this->fire_.setVisible(this->isVisible());
284    }
285
286    void SpaceShip::changedActivity()
287    {
288        Model::changedActivity();
289
290        this->tt1_->setEnabled(this->isVisible());
291        this->tt2_->setEnabled(this->isVisible());
292        this->redBillboard_.setVisible(this->isVisible());
293        this->greenBillboard_.setVisible(this->isVisible());
294        this->crosshairNear_.setVisible(this->isVisible());
295        this->crosshairFar_.setVisible(this->isVisible());
296        this->rightThrusterFlare_.setVisible(this->isVisible());
297        this->leftThrusterFlare_.setVisible(this->isVisible());
298    }
299
300    void SpaceShip::setCamera(const std::string& camera)
301    {
302      myShip_=true; // TODO: this is only a hack
303      camName_=camera;
304      // change camera attributes here, if you want to ;)
305    }
306
307    void SpaceShip::getFocus(){
308      COUT(4) << "requesting focus" << std::endl;
309      if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID)
310        CameraHandler::getInstance()->requestFocus(cam_);
311
312    }
313
314    Camera* SpaceShip::getCamera(){
315        return cam_;
316    }
317
318    void SpaceShip::createCamera(){
319//       COUT(4) << "begin camera creation" << std::endl;
320      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
321      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
322      this->camNode_->setPosition(Vector3(-25,0,5));
323//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
324//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
325//      camNode_->setOrientation(q1*q2);
326      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
327      cam_ = new Camera(this->camNode_);
328
329      cam_->setTargetNode(this->getNode());
330//        cam->setPosition(Vector3(0,-350,0));
331      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
332      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0));
333      this->camNode_->setOrientation(q2*q1);
334      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
335        this->setBacksync(true);
336        CameraHandler::getInstance()->requestFocus(cam_);
337      }
338
339    }
340
341    void SpaceShip::setMaxSpeed(float value)
342    { this->maxSpeed_ = value; }
343    void SpaceShip::setMaxSideAndBackSpeed(float value)
344    { this->maxSideAndBackSpeed_ = value; }
345    void SpaceShip::setMaxRotation(float value)
346    { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); }
347    void SpaceShip::setTransAcc(float value)
348    { this->translationAcceleration_ = value; }
349    void SpaceShip::setRotAcc(float value)
350    { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); }
351    void SpaceShip::setTransDamp(float value)
352    { this->translationDamping_ = value; }
353    void SpaceShip::setRotDamp(float value)
354    { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); }
355
356    /**
357        @brief XML loading and saving.
358        @param xmlelement The XML-element
359        @param loading Loading (true) or saving (false)
360        @return The XML-element
361    */
362    void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
363    {
364        Model::XMLPort(xmlelement, mode);
365
366        XMLPortParamLoadOnly(SpaceShip, "camera", setCamera, xmlelement, mode);
367        XMLPortParamLoadOnly(SpaceShip, "maxSpeed", setMaxSpeed, xmlelement, mode);
368        XMLPortParamLoadOnly(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, xmlelement, mode);
369        XMLPortParamLoadOnly(SpaceShip, "maxRotation", setMaxRotation, xmlelement, mode);
370        XMLPortParamLoadOnly(SpaceShip, "transAcc", setTransAcc, xmlelement, mode);
371        XMLPortParamLoadOnly(SpaceShip, "rotAcc", setRotAcc, xmlelement, mode);
372        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
373        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
374
375        SpaceShip::create();
376        if (this->isExactlyA(Class(SpaceShip)))
377            getFocus();
378    }
379
380    int sgn(float x)
381    {
382        if (x >= 0)
383            return 1;
384        else
385            return -1;
386    }
387
388    std::string SpaceShip::whereAmI() {
389        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
390        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
391        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
392    }
393
394    void SpaceShip::tick(float dt)
395    {
396        if (!this->isActive())
397            return;
398
399        currentDir_ = getOrientation()*initialDir_;
400                currentOrth_ = getOrientation()*initialOrth_;
401
402        if (this->cam_)
403            this->cam_->tick(dt);
404
405        this->smoke_.setVisible(this->isVisible() && this->health_ < 40);
406        this->fire_.setVisible(this->isVisible() && this->health_ < 20);
407
408        if (this->redNode_ && this->greenNode_)
409        {
410            this->blinkTime_ += dt;
411            float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0);
412            float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0);
413            this->redNode_->setScale(redScale, redScale, redScale);
414            this->greenNode_->setScale(greenScale, greenScale, greenScale);
415        }
416
417        if (this->timeToReload_ > 0)
418            this->timeToReload_ -= dt;
419        else
420            this->timeToReload_ = 0;
421
422        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
423        {
424
425            BillboardProjectile* projectile = new ParticleProjectile(this);
426            projectile->setColour(this->getProjectileColour());
427            projectile->create();
428            if (projectile->classID == 0)
429            {
430              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
431            }
432
433            projectile->setBacksync(true);
434            this->timeToReload_ = this->reloadTime_;
435        }
436
437
438        // #####################################
439        // ############# STEERING ##############
440        // #####################################
441
442        if (this->velocity_.x > this->maxSpeed_)
443            this->velocity_.x = this->maxSpeed_;
444        if (this->velocity_.x < -this->maxSideAndBackSpeed_)
445            this->velocity_.x = -this->maxSideAndBackSpeed_;
446        if (this->velocity_.y > this->maxSideAndBackSpeed_)
447            this->velocity_.y = this->maxSideAndBackSpeed_;
448        if (this->velocity_.y < -this->maxSideAndBackSpeed_)
449            this->velocity_.y = -this->maxSideAndBackSpeed_;
450        if (this->rotationRate_ > this->maxRotationRadian_)
451            this->rotationRate_ = this->maxRotationRadian_;
452        if (this->rotationRate_ < -this->maxRotationRadian_)
453            this->rotationRate_ = -this->maxRotationRadian_;
454
455        if (this->acceleration_.x == 0)
456        {
457            if (this->velocity_.x > 0)
458            {
459                this->velocity_.x -= (this->translationDamping_ * dt);
460                if (this->velocity_.x < 0)
461                    this->velocity_.x = 0;
462            }
463            else if (this->velocity_.x < 0)
464            {
465                this->velocity_.x += (this->translationDamping_ * dt);
466                if (this->velocity_.x > 0)
467                    this->velocity_.x = 0;
468            }
469        }
470
471        if (this->acceleration_.y == 0)
472        {
473            if (this->velocity_.y > 0)
474            {
475                this->velocity_.y -= (this->translationDamping_ * dt);
476                if (this->velocity_.y < 0)
477                    this->velocity_.y = 0;
478            }
479            else if (this->velocity_.y < 0)
480            {
481                this->velocity_.y += (this->translationDamping_ * dt);
482                if (this->velocity_.y > 0)
483                    this->velocity_.y = 0;
484            }
485        }
486
487        if (this->momentum_ == this->zeroRadian_)
488        {
489            if (this->rotationRate_ > this->zeroRadian_)
490            {
491                this->rotationRate_ -= (this->rotationDampingRadian_ * dt);
492                if (this->rotationRate_ < this->zeroRadian_)
493                    this->rotationRate_ = 0;
494            }
495            else if (this->rotationRate_ < this->zeroRadian_)
496            {
497                this->rotationRate_ += (this->rotationDampingRadian_ * dt);
498                if (this->rotationRate_ > this->zeroRadian_)
499                    this->rotationRate_ = 0;
500            }
501        }
502
503
504        WorldEntity::tick(dt);
505
506        this->roll(this->mouseXRotation_ * dt);
507        if (this->bInvertYAxis_)
508            this->yaw(Radian(-this->mouseYRotation_ * dt));
509        else
510            this->yaw(Radian(this->mouseYRotation_ * dt));
511
512        if (this->acceleration_.x > 0)
513        {
514            this->tt1_->setEnabled(true);
515            this->tt2_->setEnabled(true);
516        }
517        else
518        {
519            this->tt1_->setEnabled(false);
520            this->tt2_->setEnabled(false);
521        }
522
523        if( myShip_ )
524        {
525          COUT(5) << "steering our ship: " << objectID << std::endl;
526          this->acceleration_.x = 0;
527          this->acceleration_.y = 0;
528          this->momentum_ = 0;
529          this->mouseXRotation_ = Radian(0);
530          this->mouseYRotation_ = Radian(0);
531        }/*else
532          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
533
534          this->bLMousePressed_ = false;
535    }
536
537    void SpaceShip::movePitch(float val)
538    {   getLocalShip()->setMovePitch(val);   }
539    void SpaceShip::moveYaw(float val)
540    {   getLocalShip()->setMoveYaw(val);   }
541    void SpaceShip::moveRoll(float val)
542    {   getLocalShip()->setMoveRoll(val);   }
543    void SpaceShip::moveLongitudinal(float val)
544    {   getLocalShip()->setMoveLongitudinal(val);   }
545    void SpaceShip::moveLateral(float val)
546    {   getLocalShip()->setMoveLateral(val);   }
547    void SpaceShip::fire()
548    {   getLocalShip()->doFire();   }
549
550    void SpaceShip::setMovePitch(float val)
551    {
552        val = -val * val * sgn(val) * this->rotationAcceleration_;
553        if (val > this->maxRotation_)
554            val = this->maxRotation_;
555        if (val < -this->maxRotation_)
556            val = -this->maxRotation_;
557        this->mouseYRotation_ = Radian(val);
558    }
559
560    void SpaceShip::setMoveYaw(float val)
561    {
562        val = -val * val * sgn(val) * this->rotationAcceleration_;
563        if (val > this->maxRotation_)
564            val = this->maxRotation_;
565        if (val < -this->maxRotation_)
566            val = -this->maxRotation_;
567        this->mouseXRotation_ = Radian(val);
568    }
569
570    void SpaceShip::setMoveRoll(float val)
571    {
572        this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val);
573        //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl;
574    }
575
576    void SpaceShip::setMoveLongitudinal(float val)
577    {
578        this->acceleration_.x = this->translationAcceleration_ * val;
579    }
580
581    void SpaceShip::setMoveLateral(float val)
582    {
583        this->acceleration_.y = -this->translationAcceleration_ * val;
584    }
585
586    void SpaceShip::doFire()
587    {
588        this->bLMousePressed_ = true;
589    }
590}
Note: See TracBrowser for help on using the repository browser.