Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/controllers/NewHumanController.cc @ 8431

Last change on this file since 8431 was 8351, checked in by rgrieder, 14 years ago

Merged kicklib2 branch back to trunk (includes former branches ois_update, mac_osx and kicklib).

Notes for updating

Linux:
You don't need an extra package for CEGUILua and Tolua, it's already shipped with CEGUI.
However you do need to make sure that the OgreRenderer is installed too with CEGUI 0.7 (may be a separate package).
Also, Orxonox now recognises if you install the CgProgramManager (a separate package available on newer Ubuntu on Debian systems).

Windows:
Download the new dependency packages versioned 6.0 and use these. If you have problems with that or if you don't like the in game console problem mentioned below, you can download the new 4.3 version of the packages (only available for Visual Studio 2005/2008).

Key new features:

  • *Support for Mac OS X*
  • Visual Studio 2010 support
  • Bullet library update to 2.77
  • OIS library update to 1.3
  • Support for CEGUI 0.7 —> Support for Arch Linux and even SuSE
  • Improved install target
  • Compiles now with GCC 4.6
  • Ogre Cg Shader plugin activated for Linux if available
  • And of course lots of bug fixes

There are also some regressions:

  • No support for CEGUI 0.5, Ogre 1.4 and boost 1.35 - 1.39 any more
  • In game console is not working in main menu for CEGUI 0.7
  • Tolua (just the C lib, not the application) and CEGUILua libraries are no longer in our repository. —> You will need to get these as well when compiling Orxonox
  • And of course lots of new bugs we don't yet know about
  • Property svn:eol-style set to native
File size: 23.9 KB
RevLine 
[5979]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:
[5981]23 *      Michael Wirth
[5979]24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "NewHumanController.h"
30
[6256]31#include <cmath>
[6033]32#include <OgreRay.h>
33#include <OgreSceneQuery.h>
34#include <OgreCamera.h>
35#include <OgreSceneManager.h>
[6377]36#include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
[5981]37
[5979]38#include "core/CoreIncludes.h"
[7284]39#include "core/command/ConsoleCommand.h"
[7859]40#include "core/input/KeyBinder.h"
41#include "core/input/KeyBinderManager.h"
[5979]42#include "worldentities/ControllableEntity.h"
[6111]43#include "worldentities/pawns/Pawn.h"
[5979]44#include "infos/PlayerInfo.h"
[6055]45#include "overlays/OrxonoxOverlay.h"
[5979]46#include "graphics/Camera.h"
47#include "sound/SoundManager.h"
[6377]48#include "tools/BulletConversions.h"
[5979]49#include "Scene.h"
50
51namespace orxonox
52{
[7284]53    SetConsoleCommand("NewHumanController", "changeMode", &NewHumanController::changeMode).keybindMode(KeybindMode::OnPress);
54    SetConsoleCommand("NewHumanController", "accelerate", &NewHumanController::accelerate).keybindMode(KeybindMode::OnPress);
55    SetConsoleCommand("NewHumanController", "decelerate", &NewHumanController::decelerate).keybindMode(KeybindMode::OnPress);
56    SetConsoleCommand("NewHumanController", "unfire",     &NewHumanController::unfire    ).keybindMode(KeybindMode::OnRelease).addShortcut();
[6091]57
[5979]58    CreateUnloadableFactory(NewHumanController);
59
[6091]60    NewHumanController* NewHumanController::localController_s = 0;
61
[6122]62    NewHumanController::NewHumanController(BaseObject* creator)
63        : HumanController(creator)
64        , crossHairOverlay_(NULL)
[6195]65        , centerOverlay_(NULL)
[6320]66        , damageOverlayTop_(NULL)
67        , damageOverlayRight_(NULL)
68        , damageOverlayBottom_(NULL)
69        , damageOverlayLeft_(NULL)
70        , damageOverlayTT_(0)
[6328]71        , arrowsOverlay1_(NULL)
72        , arrowsOverlay2_(NULL)
73        , arrowsOverlay3_(NULL)
74        , arrowsOverlay4_(NULL)
[5979]75    {
76        RegisterObject(NewHumanController);
[6001]77
[6502]78        overlaySize_ = 0.08f;
79        arrowsSize_ = 0.4f;
[6310]80
[6502]81        damageOverlayTime_ = 0.6f;
[6310]82
[6055]83        controlMode_ = 0;
[6149]84        acceleration_ = 0;
[6236]85        accelerating_ = false;
[6210]86        firemode_ = -1;
[6310]87
[6210]88        showArrows_ = true;
[6236]89        showOverlays_ = false;
[6310]90        showDamageOverlay_ = true;
[6033]91
[6149]92        //currentPitch_ = 1;
93        //currentYaw_ = 1;
94
[6122]95        if (GameMode::showsGraphics())
96        {
97            crossHairOverlay_ = new OrxonoxOverlay(this);
98            crossHairOverlay_->setBackgroundMaterial("Orxonox/Crosshair3");
99            crossHairOverlay_->setSize(Vector2(overlaySize_, overlaySize_));
[6195]100            crossHairOverlay_->hide();
[6210]101            //crossHairOverlay_->setAspectCorrection(true); not working
[6195]102
103            centerOverlay_ = new OrxonoxOverlay(this);
104            centerOverlay_->setBackgroundMaterial("Orxonox/CenterOverlay");
[6502]105            centerOverlay_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f));
106            centerOverlay_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f));
[6195]107            centerOverlay_->hide();
[6210]108
[6377]109            if (showDamageOverlay_)
[6210]110            {
[6310]111                damageOverlayTop_ = new OrxonoxOverlay(this);
112                damageOverlayTop_->setBackgroundMaterial("Orxonox/DamageOverlayTop");
[6502]113                damageOverlayTop_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f));
114                damageOverlayTop_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f));
[6310]115                damageOverlayTop_->hide();
116
117                damageOverlayRight_ = new OrxonoxOverlay(this);
118                damageOverlayRight_->setBackgroundMaterial("Orxonox/DamageOverlayRight");
[6502]119                damageOverlayRight_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f));
120                damageOverlayRight_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f));
[6310]121                damageOverlayRight_->hide();
122
123                damageOverlayBottom_ = new OrxonoxOverlay(this);
124                damageOverlayBottom_->setBackgroundMaterial("Orxonox/DamageOverlayBottom");
[6502]125                damageOverlayBottom_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f));
126                damageOverlayBottom_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f));
[6310]127                damageOverlayBottom_->hide();
128
129                damageOverlayLeft_ = new OrxonoxOverlay(this);
130                damageOverlayLeft_->setBackgroundMaterial("Orxonox/DamageOverlayLeft");
[6502]131                damageOverlayLeft_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f));
132                damageOverlayLeft_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f));
[6310]133                damageOverlayLeft_->hide();
134            }
135
[6377]136            if (showArrows_)
[6310]137            {
[6210]138                arrowsOverlay1_ = new OrxonoxOverlay(this);
[6289]139                arrowsOverlay1_->setBackgroundMaterial("Orxonox/DirectionArrows1");
[6502]140                arrowsOverlay1_->setSize(Vector2(0.02727f, 0.36f * arrowsSize_));
141                arrowsOverlay1_->setPickPoint(Vector2(0.5f, 0.5f));
142                arrowsOverlay1_->setPosition(Vector2(0.5f, 0.5f));
[6210]143                arrowsOverlay1_->hide();
[6387]144
[6210]145                arrowsOverlay2_ = new OrxonoxOverlay(this);
[6289]146                arrowsOverlay2_->setBackgroundMaterial("Orxonox/DirectionArrows2");
[6502]147                arrowsOverlay2_->setSize(Vector2(0.02727f, 0.59f * arrowsSize_));
148                arrowsOverlay2_->setPickPoint(Vector2(0.5f, 0.5f));
149                arrowsOverlay2_->setPosition(Vector2(0.5f, 0.5f));
[6210]150                arrowsOverlay2_->hide();
[6387]151
[6210]152                arrowsOverlay3_ = new OrxonoxOverlay(this);
[6289]153                arrowsOverlay3_->setBackgroundMaterial("Orxonox/DirectionArrows3");
[6502]154                arrowsOverlay3_->setSize(Vector2(0.02727f, 0.77f * arrowsSize_));
155                arrowsOverlay3_->setPickPoint(Vector2(0.5f, 0.5f));
156                arrowsOverlay3_->setPosition(Vector2(0.5f, 0.5f));
[6210]157                arrowsOverlay3_->hide();
[6387]158
[6210]159                arrowsOverlay4_ = new OrxonoxOverlay(this);
[6289]160                arrowsOverlay4_->setBackgroundMaterial("Orxonox/DirectionArrows4");
[6502]161                arrowsOverlay4_->setSize(Vector2(0.02727f, arrowsSize_));
162                arrowsOverlay4_->setPickPoint(Vector2(0.5f, 0.5f));
163                arrowsOverlay4_->setPosition(Vector2(0.5f, 0.5f));
[6210]164                arrowsOverlay4_->hide();
165            }
[6122]166        }
[6045]167
[6058]168        // HACK: Define which objects are targetable when considering the creator of an orxonox::Model
[6055]169        this->targetMask_.exclude(ClassByString("BaseObject"));
170        this->targetMask_.include(ClassByString("WorldEntity"));
171        this->targetMask_.exclude(ClassByString("Projectile"));
[6091]172
173        NewHumanController::localController_s = this;
[6195]174
[6236]175        controlPaused_ = false;
[6210]176
[6377]177        //HumanController::localController_s->getControllableEntity()->getCamera()->setDrag(true);
[5979]178    }
179
180    NewHumanController::~NewHumanController()
181    {
[6055]182        if (this->isInitialized())
[5981]183        {
[6122]184            if (this->crossHairOverlay_)
185                this->crossHairOverlay_->destroy();
[6210]186            if (this->centerOverlay_)
187                this->centerOverlay_->destroy();
188
[6598]189            if (this->arrowsOverlay1_)
190                this->arrowsOverlay1_->destroy();
191            if (this->arrowsOverlay2_)
192                this->arrowsOverlay2_->destroy();
193            if (this->arrowsOverlay3_)
194                this->arrowsOverlay3_->destroy();
195            if (this->arrowsOverlay4_)
196                this->arrowsOverlay4_->destroy();
197            if (this->damageOverlayTop_)
198                this->damageOverlayTop_->destroy();
199            if (this->damageOverlayLeft_)
200                this->damageOverlayLeft_->destroy();
201            if (this->damageOverlayRight_)
202                this->damageOverlayRight_->destroy();
203            if (this->damageOverlayBottom_)
204                this->damageOverlayBottom_->destroy();
[5981]205        }
[5979]206    }
207
[6055]208    void NewHumanController::tick(float dt)
209    {
[6122]210        if (GameMode::showsGraphics())
[6111]211        {
[6210]212
[6377]213            if (this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
[6122]214            {
[6157]215                this->updateTarget();
[6289]216
[6377]217                if (!controlPaused_ )
218                {
219                    if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
[6289]220                        this->showOverlays();
[7163]221                    else if (this->getControllableEntity() &&  this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
222                    {
223                        this->showOverlays();
224                        this->hideArrows();
225                    }
[6289]226
[6502]227                    this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5f-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5f-overlaySize_/2));
[6210]228
[6377]229                    if (this->controlMode_ == 0 || (this->controlMode_ == 1 && this->firemode_ == 1))
[6236]230                    {
[6377]231                        if (this->showOverlays_ && this->showArrows_)
[6236]232                            alignArrows();
233                    }
[6210]234                    else
235                        hideArrows();
[6310]236
[6377]237                    if (this->showDamageOverlay_ && (this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0))
238                    {
[6310]239                        this->damageOverlayTT_ -= dt;
240                        this->damageOverlayTR_ -= dt;
241                        this->damageOverlayTB_ -= dt;
242                        this->damageOverlayTL_ -= dt;
[6377]243                        if (this->damageOverlayTT_ <= 0)
[6310]244                            this->damageOverlayTop_->hide();
[6377]245                        if (this->damageOverlayTR_ <= 0)
[6310]246                            this->damageOverlayRight_->hide();
[6377]247                        if (this->damageOverlayTB_ <= 0)
[6310]248                            this->damageOverlayBottom_->hide();
[6377]249                        if (this->damageOverlayTL_ <= 0)
[6310]250                            this->damageOverlayLeft_->hide();
251                    }
[6195]252                }
[6122]253            }
[6279]254            else
255                this->hideOverlays();
[6210]256
[6377]257            if (this->acceleration_ > 0)
[6173]258            {
[6377]259                if (this->accelerating_)
[6173]260                    HumanController::moveFrontBack(Vector2(1, 0));
261                else
[6388]262                    HumanController::moveFrontBack(Vector2(this->acceleration_, 0));
[6173]263                this->accelerating_ = false;
264                //HumanController::moveFrontBack(Vector2(clamp(this->acceleration_ + this->currentAcceleration_, 0.0f, 1.0f), 0));
265            }
[6111]266        }
[6001]267
[6360]268        // Reset pitch and yaw rates
[6365]269        // TODO: Reactivate this to fix the game pad problem with 0 input
270        //this->currentPitch_ = 0;
271        //this->currentYaw_ = 0;
[6360]272
[6001]273        HumanController::tick(dt);
274    }
275
[6033]276    void NewHumanController::doFire(unsigned int firemode)
277    {
[6377]278        if (!this->controllableEntity_)
[6316]279            return;
[6033]280
[6210]281        this->firemode_ = firemode;
282
[6157]283        if (firemode == 1 && this->controlMode_ == 1)
284        {
[6143]285            //unlocked steering, steer on right mouse click
[6144]286            HumanController::yaw(Vector2(this->currentYaw_, 0));
287            HumanController::pitch(Vector2(this->currentPitch_, 0));
[6143]288        }
[6157]289        else
[6143]290            HumanController::localController_s->getControllableEntity()->fire(firemode);
291
[6045]292    }
293
[6377]294    void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
295    {
296        if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
297        {
[6310]298            Vector3 posA;
[6377]299            if (originator)
[6310]300                posA = originator->getWorldPosition();
301            else
302                posA = multi_cast<Vector3>(contactpoint.getPositionWorldOnA());
303            //Vector3 posB = multi_cast<Vector3>(contactpoint.getPositionWorldOnB());
304            //posA and posB are almost identical
[6295]305
[6310]306            Vector3 relativeHit = this->getControllableEntity()->getWorldOrientation().UnitInverse() * (this->getControllableEntity()->getWorldPosition() - posA);
[6295]307
[6310]308            //back is z positive
309            //x is left positive
310            //y is down positive
311            relativeHit.normalise();
312
[6502]313            float threshold = 0.3f;
[6377]314            if (relativeHit.x > threshold) // Left
[6310]315            {
316                this->damageOverlayLeft_->show();
317                this->damageOverlayTL_ = this->damageOverlayTime_;
318                //this->damageOverlayLeft_->setBackgroundAlpha(0.3);
319            }
[6377]320            if (relativeHit.x < -threshold) //Right
[6310]321            {
322                this->damageOverlayRight_->show();
323                this->damageOverlayTR_ = this->damageOverlayTime_;
324                //this->damageOverlayRight_->setBackgroundAlpha(0.3);
325            }
[6377]326            if (relativeHit.y > threshold) //Top
[6310]327            {
[6312]328                this->damageOverlayBottom_->show();
329                this->damageOverlayTB_ = this->damageOverlayTime_;
[6310]330                //this->damageOverlayTop_->setBackgroundAlpha(0.3);
331            }
[6377]332            if (relativeHit.y < -threshold) //Bottom
[6310]333            {
[6312]334                this->damageOverlayTop_->show();
335                this->damageOverlayTT_ = this->damageOverlayTime_;
[6310]336                //this->damageOverlayBottom_->setBackgroundAlpha(0.3);
337            }
338        }
[6295]339    }
340
[6210]341    void NewHumanController::unfire()
342    {
343        if (NewHumanController::localController_s)
344            NewHumanController::localController_s->doUnfire();
345    }
346
347    void NewHumanController::doUnfire()
348    {
349        this->firemode_ = -1;
350        hideArrows();
351    }
352
[7859]353    void NewHumanController::centerCursor()
354    {
355        this->currentYaw_ = 0;
356        this->currentPitch_ = 0;
357
[8316]358        if( KeyBinderManager::exists() )
359            KeyBinderManager::getInstance().getCurrent()->resetMouseAxes();
[7859]360    }
361
[6111]362    void NewHumanController::updateTarget()
[6055]363    {
364        Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
[6033]365
[6502]366        Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getOgreCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5f, static_cast<float>(this->currentPitch_)/2*-1+.5f);
[6033]367
[6055]368        rsq->setRay(mouseRay);
369        rsq->setSortByDistance(true);
[6033]370
[6055]371        /*
372        Distance of objects:
373        ignore everything under 200 maybe even take 1000 as min distance to shoot at
[6033]374
[6055]375        shots are regularly traced and are entities!!!!!!!!! this is the biggest problem
376        they vanish only after a distance of 10'000
377        */
[6045]378
379
[6055]380        Ogre::RaySceneQueryResult& result = rsq->execute();
[6111]381        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
[7163]382        WorldEntity* myWe = static_cast<WorldEntity*>(this->getControllableEntity());
[6033]383
[6055]384        Ogre::RaySceneQueryResult::iterator itr;
385        for (itr = result.begin(); itr != result.end(); ++itr)
386        {
[7163]387//             CCOUT(0) << "testing object as target" << endl;
[7801]388            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 200)
[6045]389            {
[6055]390                // Try to cast the user pointer
[7163]391                WorldEntity* wePtr;
392                try
393                {
394                    wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
395                }
396                catch (...)
397                {
398                    continue;
399                }
400
401                // make sure we don't shoot ourselves
402                if( wePtr==myWe )
403                    continue;
404
[6055]405                if (wePtr)
406                {
[6377]407                    // go through all parents of object and look whether they are sightable or not
[6114]408                    bool isSightable = false;
409                    WorldEntity* parent = wePtr->getParent();
[6377]410                    while (parent)
[6114]411                    {
[7163]412                        if (this->targetMask_.isExcluded(parent->getIdentifier()) || parent==myWe)
[6114]413                        {
414                            parent = parent->getParent();
415                            continue;
416                        }
417                        else
418                        {
419                            isSightable = true;
420                            break;
421                        }
422                    }
[6377]423                    if (!isSightable)
[6055]424                        continue;
[6045]425                }
[6143]426
[6377]427                if (this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr)
[6116]428                    this->getControllableEntity()->setTarget(wePtr);
[6091]429
[6377]430                if (pawn)
[6143]431                    pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance );
432
[6195]433                //itr->movable->getParentSceneNode()->showBoundingBox(true);
[6111]434                //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition()
435                return;
[6045]436            }
[6377]437        }
[6091]438
[6377]439        if (pawn)
[6111]440            pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 1200 );
[6143]441
442        if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != 0 )
443            this->getControllableEntity()->setTarget( 0 );
[6033]444
[6091]445        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000);
[6058]446        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getOgreCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);
[6033]447    }
448
[6149]449    void NewHumanController::frontback(const Vector2& value)
450    {
[6173]451        this->accelerating_ = true;
[6149]452
[6173]453        //if (this->acceleration_ == 0)
[6377]454        HumanController::frontback(value);
[6149]455    }
456
[5993]457    void NewHumanController::yaw(const Vector2& value)
458    {
[6377]459        //SUPER(NewHumanController, yaw, value);
460        if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook()))
[6091]461            HumanController::yaw(value);
[6143]462
[7163]463        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
464            this->currentYaw_ = value.x;
[5979]465    }
[6055]466
[5993]467    void NewHumanController::pitch(const Vector2& value)
[5981]468    {
[6377]469        //SUPER(NewHumanController, pitch, value);
470        if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook()))
[6091]471            HumanController::pitch(value);
472
[7163]473        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
474            this->currentPitch_ = value.x;
[5981]475    }
[6091]476
[6149]477    void NewHumanController::changeMode()
478    {
[6365]479        if (NewHumanController::localController_s)
[6111]480        {
[6365]481            if (NewHumanController::localController_s->controlMode_ == 0)
482            {
[6111]483                NewHumanController::localController_s->controlMode_ = 1;
[6210]484                NewHumanController::localController_s->hideArrows();
[6365]485            }
486            else
487                NewHumanController::localController_s->controlMode_ = 0;
[6111]488        }
[6091]489    }
[6143]490
[6115]491    void NewHumanController::changedControllableEntity()
492    {
493        this->controlMode_ = 0;
[7859]494        this->centerCursor();
[6377]495        if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
[6236]496        {
497            this->showOverlays_ = true;
[6377]498            if (!this->controlPaused_)
[6236]499            {
500                this->showOverlays();
501                this->alignArrows();
502            }
503        }
504        else
505        {
506            this->showOverlays_ = false;
507            this->hideOverlays();
508        }
[6115]509    }
[6149]510
511    void NewHumanController::accelerate()
512    {
[6377]513        if (NewHumanController::localController_s)
[6173]514            NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ + 0.2f, 0.00f, 1.0f);
[6149]515    }
516
517    void NewHumanController::decelerate()
518    {
[6377]519        if (NewHumanController::localController_s)
[6173]520            NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ - 0.1f, 0.0f, 1.0f);
[6149]521    }
[6195]522
[6377]523    void NewHumanController::doResumeControl()
524    {
[6195]525        this->controlPaused_ = false;
[6377]526        if (this->showOverlays_)
[6236]527            this->showOverlays();
[6195]528    }
529
[6377]530    void NewHumanController::doPauseControl()
531    {
[6195]532        this->controlPaused_ = true;
[6236]533        this->hideOverlays();
[6195]534    }
[6210]535
[6377]536    void NewHumanController::alignArrows()
537    {
538        if (showArrows_)
539        {
[6210]540            hideArrows();
[6387]541
[6210]542            float distance = sqrt(pow(static_cast<float>(this->currentYaw_)/2*-1,2) + pow(static_cast<float>(this->currentPitch_)/2*-1,2));
[6387]543
[6502]544            if (distance > 0.04f && distance <= 0.59f * arrowsSize_ / 2.0f )
[6377]545            {
[8351]546                this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
[6210]547                this->arrowsOverlay1_->show();
548            }
[6502]549            else if (distance > 0.59f * arrowsSize_ / 2.0f && distance <= 0.77f * arrowsSize_ / 2.0f )
[6377]550            {
[8351]551                this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
[6210]552                this->arrowsOverlay2_->show();
553            }
[6502]554            else if (distance > 0.77f * arrowsSize_ / 2.0f && distance <= arrowsSize_ / 2.0f)
[6377]555            {
[8351]556                this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
[6210]557                this->arrowsOverlay3_->show();
558            }
[6502]559            else if (distance > arrowsSize_ / 2.0f)
[6377]560            {
[8351]561                this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f));
[6210]562                this->arrowsOverlay4_->show();
563            }
564        }
565    }
566
[6377]567    void NewHumanController::showOverlays()
568    {
569        if (!GameMode::showsGraphics())
[6320]570            return;
[6236]571        this->crossHairOverlay_->show();
572        this->centerOverlay_->show();
[6289]573
[6377]574        if (showArrows_)
575        {
[6236]576            this->arrowsOverlay1_->show();
577            this->arrowsOverlay2_->show();
578            this->arrowsOverlay3_->show();
579            this->arrowsOverlay4_->show();
580        }
581    }
582
[6377]583    void NewHumanController::hideOverlays()
584    {
585        if (!GameMode::showsGraphics())
[6320]586            return;
[6236]587        this->crossHairOverlay_->hide();
588        this->centerOverlay_->hide();
[6289]589
[6377]590        if (showDamageOverlay_)
591        {
[6310]592            this->damageOverlayTop_->hide();
593            this->damageOverlayRight_->hide();
594            this->damageOverlayBottom_->hide();
595            this->damageOverlayLeft_->hide();
596        }
597
[6236]598        this->hideArrows();
599    }
600
[6377]601    void NewHumanController::hideArrows()
602    {
603        if(!GameMode::showsGraphics())
[6320]604            return;
[6377]605        if (showArrows_)
606        {
[6210]607            this->arrowsOverlay1_->hide();
608            this->arrowsOverlay2_->hide();
609            this->arrowsOverlay3_->hide();
610            this->arrowsOverlay4_->hide();
611        }
612    }
[7163]613
614
615
616
617
[5979]618}
Note: See TracBrowser for help on using the repository browser.