Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8987 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

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