Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7981 was 7859, checked in by landauf, 14 years ago

implemented feature to reset the mouse cursor to the center
used in NewHumanController to set cursor to the center of the screen every time the ControllableEntity is changed
avoids turning of the spaceship right after spawn, if the player looked around in spectator mode

needs testing with derived mouse input (joysticks should be unchanged).
input system experts may have a look at this. ;)

  • 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
358        KeyBinderManager::getInstance().getCurrent()->resetMouseAxes();
359    }
360
[6111]361    void NewHumanController::updateTarget()
[6055]362    {
363        Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
[6033]364
[6502]365        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]366
[6055]367        rsq->setRay(mouseRay);
368        rsq->setSortByDistance(true);
[6033]369
[6055]370        /*
371        Distance of objects:
372        ignore everything under 200 maybe even take 1000 as min distance to shoot at
[6033]373
[6055]374        shots are regularly traced and are entities!!!!!!!!! this is the biggest problem
375        they vanish only after a distance of 10'000
376        */
[6045]377
378
[6055]379        Ogre::RaySceneQueryResult& result = rsq->execute();
[6111]380        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
[7163]381        WorldEntity* myWe = static_cast<WorldEntity*>(this->getControllableEntity());
[6033]382
[6055]383        Ogre::RaySceneQueryResult::iterator itr;
384        for (itr = result.begin(); itr != result.end(); ++itr)
385        {
[7163]386//             CCOUT(0) << "testing object as target" << endl;
[7801]387            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 200)
[6045]388            {
[6055]389                // Try to cast the user pointer
[7163]390                WorldEntity* wePtr;
391                try
392                {
393                    wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
394                }
395                catch (...)
396                {
397                    continue;
398                }
399
400                // make sure we don't shoot ourselves
401                if( wePtr==myWe )
402                    continue;
403
[6055]404                if (wePtr)
405                {
[6377]406                    // go through all parents of object and look whether they are sightable or not
[6114]407                    bool isSightable = false;
408                    WorldEntity* parent = wePtr->getParent();
[6377]409                    while (parent)
[6114]410                    {
[7163]411                        if (this->targetMask_.isExcluded(parent->getIdentifier()) || parent==myWe)
[6114]412                        {
413                            parent = parent->getParent();
414                            continue;
415                        }
416                        else
417                        {
418                            isSightable = true;
419                            break;
420                        }
421                    }
[6377]422                    if (!isSightable)
[6055]423                        continue;
[6045]424                }
[6143]425
[6377]426                if (this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr)
[6116]427                    this->getControllableEntity()->setTarget(wePtr);
[6091]428
[6377]429                if (pawn)
[6143]430                    pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance );
431
[6195]432                //itr->movable->getParentSceneNode()->showBoundingBox(true);
[6111]433                //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition()
434                return;
[6045]435            }
[6377]436        }
[6091]437
[6377]438        if (pawn)
[6111]439            pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 1200 );
[6143]440
441        if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != 0 )
442            this->getControllableEntity()->setTarget( 0 );
[6033]443
[6091]444        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000);
[6058]445        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getOgreCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);
[6033]446    }
447
[6149]448    void NewHumanController::frontback(const Vector2& value)
449    {
[6173]450        this->accelerating_ = true;
[6149]451
[6173]452        //if (this->acceleration_ == 0)
[6377]453        HumanController::frontback(value);
[6149]454    }
455
[5993]456    void NewHumanController::yaw(const Vector2& value)
457    {
[6377]458        //SUPER(NewHumanController, yaw, value);
459        if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook()))
[6091]460            HumanController::yaw(value);
[6143]461
[7163]462        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
463            this->currentYaw_ = value.x;
[5979]464    }
[6055]465
[5993]466    void NewHumanController::pitch(const Vector2& value)
[5981]467    {
[6377]468        //SUPER(NewHumanController, pitch, value);
469        if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook()))
[6091]470            HumanController::pitch(value);
471
[7163]472        if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
473            this->currentPitch_ = value.x;
[5981]474    }
[6091]475
[6149]476    void NewHumanController::changeMode()
477    {
[6365]478        if (NewHumanController::localController_s)
[6111]479        {
[6365]480            if (NewHumanController::localController_s->controlMode_ == 0)
481            {
[6111]482                NewHumanController::localController_s->controlMode_ = 1;
[6210]483                NewHumanController::localController_s->hideArrows();
[6365]484            }
485            else
486                NewHumanController::localController_s->controlMode_ = 0;
[6111]487        }
[6091]488    }
[6143]489
[6115]490    void NewHumanController::changedControllableEntity()
491    {
492        this->controlMode_ = 0;
[7859]493        this->centerCursor();
[6377]494        if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
[6236]495        {
496            this->showOverlays_ = true;
[6377]497            if (!this->controlPaused_)
[6236]498            {
499                this->showOverlays();
500                this->alignArrows();
501            }
502        }
503        else
504        {
505            this->showOverlays_ = false;
506            this->hideOverlays();
507        }
[6115]508    }
[6149]509
510    void NewHumanController::accelerate()
511    {
[6377]512        if (NewHumanController::localController_s)
[6173]513            NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ + 0.2f, 0.00f, 1.0f);
[6149]514    }
515
516    void NewHumanController::decelerate()
517    {
[6377]518        if (NewHumanController::localController_s)
[6173]519            NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ - 0.1f, 0.0f, 1.0f);
[6149]520    }
[6195]521
[6377]522    void NewHumanController::doResumeControl()
523    {
[6195]524        this->controlPaused_ = false;
[6377]525        if (this->showOverlays_)
[6236]526            this->showOverlays();
[6195]527    }
528
[6377]529    void NewHumanController::doPauseControl()
530    {
[6195]531        this->controlPaused_ = true;
[6236]532        this->hideOverlays();
[6195]533    }
[6210]534
[6377]535    void NewHumanController::alignArrows()
536    {
537        if (showArrows_)
538        {
[6210]539            hideArrows();
[6387]540
[6210]541            float distance = sqrt(pow(static_cast<float>(this->currentYaw_)/2*-1,2) + pow(static_cast<float>(this->currentPitch_)/2*-1,2));
[6387]542
[6502]543            if (distance > 0.04f && distance <= 0.59f * arrowsSize_ / 2.0f )
[6377]544            {
[7184]545                this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
[6210]546                this->arrowsOverlay1_->show();
547            }
[6502]548            else if (distance > 0.59f * arrowsSize_ / 2.0f && distance <= 0.77f * arrowsSize_ / 2.0f )
[6377]549            {
[7184]550                this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
[6210]551                this->arrowsOverlay2_->show();
552            }
[6502]553            else if (distance > 0.77f * arrowsSize_ / 2.0f && distance <= arrowsSize_ / 2.0f)
[6377]554            {
[7184]555                this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
[6210]556                this->arrowsOverlay3_->show();
557            }
[6502]558            else if (distance > arrowsSize_ / 2.0f)
[6377]559            {
[7184]560                this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
[6210]561                this->arrowsOverlay4_->show();
562            }
563        }
564    }
565
[6377]566    void NewHumanController::showOverlays()
567    {
568        if (!GameMode::showsGraphics())
[6320]569            return;
[6236]570        this->crossHairOverlay_->show();
571        this->centerOverlay_->show();
[6289]572
[6377]573        if (showArrows_)
574        {
[6236]575            this->arrowsOverlay1_->show();
576            this->arrowsOverlay2_->show();
577            this->arrowsOverlay3_->show();
578            this->arrowsOverlay4_->show();
579        }
580    }
581
[6377]582    void NewHumanController::hideOverlays()
583    {
584        if (!GameMode::showsGraphics())
[6320]585            return;
[6236]586        this->crossHairOverlay_->hide();
587        this->centerOverlay_->hide();
[6289]588
[6377]589        if (showDamageOverlay_)
590        {
[6310]591            this->damageOverlayTop_->hide();
592            this->damageOverlayRight_->hide();
593            this->damageOverlayBottom_->hide();
594            this->damageOverlayLeft_->hide();
595        }
596
[6236]597        this->hideArrows();
598    }
599
[6377]600    void NewHumanController::hideArrows()
601    {
602        if(!GameMode::showsGraphics())
[6320]603            return;
[6377]604        if (showArrows_)
605        {
[6210]606            this->arrowsOverlay1_->hide();
607            this->arrowsOverlay2_->hide();
608            this->arrowsOverlay3_->hide();
609            this->arrowsOverlay4_->hide();
610        }
611    }
[7163]612
613
614
615
616
[5979]617}
Note: See TracBrowser for help on using the repository browser.