Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6377


Ignore:
Timestamp:
Dec 18, 2009, 12:29:54 PM (14 years ago)
Author:
rgrieder
Message:

Little code cleanup in NewHumanController.

Location:
code/branches/presentation2/src/orxonox/controllers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc

    r6376 r6377  
    3434#include <OgreCamera.h>
    3535#include <OgreSceneManager.h>
     36#include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
    3637
    3738#include "core/CoreIncludes.h"
     
    4344#include "graphics/Camera.h"
    4445#include "sound/SoundManager.h"
     46#include "tools/BulletConversions.h"
    4547#include "Scene.h"
    46 #include "tools/BulletConversions.h"
    47 #include "bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
    4848
    4949namespace orxonox
    5050{
    51     SetConsoleCommand(NewHumanController, changeMode,          false).keybindMode(KeybindMode::OnPress);
    52     SetConsoleCommand(NewHumanController, accelerate,          false).keybindMode(KeybindMode::OnPress);
    53     SetConsoleCommand(NewHumanController, decelerate,          false).keybindMode(KeybindMode::OnPress);
    54     SetConsoleCommand(NewHumanController, unfire,              true).keybindMode(KeybindMode::OnRelease);
     51    SetConsoleCommand(NewHumanController, changeMode, false).keybindMode(KeybindMode::OnPress);
     52    SetConsoleCommand(NewHumanController, accelerate, false).keybindMode(KeybindMode::OnPress);
     53    SetConsoleCommand(NewHumanController, decelerate, false).keybindMode(KeybindMode::OnPress);
     54    SetConsoleCommand(NewHumanController, unfire,      true).keybindMode(KeybindMode::OnRelease);
    5555
    5656    CreateUnloadableFactory(NewHumanController);
     
    102102            centerOverlay_->setBackgroundMaterial("Orxonox/CenterOverlay");
    103103            centerOverlay_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
    104             centerOverlay_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     104            centerOverlay_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));
    105105            centerOverlay_->hide();
    106106
    107             if ( showDamageOverlay_ )
     107            if (showDamageOverlay_)
    108108            {
    109109                damageOverlayTop_ = new OrxonoxOverlay(this);
    110110                damageOverlayTop_->setBackgroundMaterial("Orxonox/DamageOverlayTop");
    111111                damageOverlayTop_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
    112                 damageOverlayTop_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     112                damageOverlayTop_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));
    113113                damageOverlayTop_->hide();
    114114
     
    116116                damageOverlayRight_->setBackgroundMaterial("Orxonox/DamageOverlayRight");
    117117                damageOverlayRight_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
    118                 damageOverlayRight_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     118                damageOverlayRight_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));
    119119                damageOverlayRight_->hide();
    120120
     
    122122                damageOverlayBottom_->setBackgroundMaterial("Orxonox/DamageOverlayBottom");
    123123                damageOverlayBottom_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
    124                 damageOverlayBottom_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     124                damageOverlayBottom_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));
    125125                damageOverlayBottom_->hide();
    126126
     
    128128                damageOverlayLeft_->setBackgroundMaterial("Orxonox/DamageOverlayLeft");
    129129                damageOverlayLeft_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
    130                 damageOverlayLeft_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
     130                damageOverlayLeft_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));
    131131                damageOverlayLeft_->hide();
    132132            }
    133133
    134             if ( showArrows_ )
     134            if (showArrows_)
    135135            {
    136136                arrowsOverlay1_ = new OrxonoxOverlay(this);
     
    173173        controlPaused_ = false;
    174174
    175 //HumanController::localController_s->getControllableEntity()->getCamera()->setDrag(true);
     175        //HumanController::localController_s->getControllableEntity()->getCamera()->setDrag(true);
    176176    }
    177177
     
    204204        {
    205205
    206             if( this->controllableEntity_ && !this->controllableEntity_->isInMouseLook() )
     206            if (this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
    207207            {
    208208                this->updateTarget();
    209209
    210                 if ( !controlPaused_ ) {
    211                     if (this->getControllableEntity() && (this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket"))
     210                if (!controlPaused_ )
     211                {
     212                    if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
    212213                        this->showOverlays();
    213214
    214215                    this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2));
    215216
    216                     if ( this->controlMode_ == 0 || ( this->controlMode_ == 1 && this->firemode_ == 1 ) )
     217                    if (this->controlMode_ == 0 || (this->controlMode_ == 1 && this->firemode_ == 1))
    217218                    {
    218                         if ( this->showOverlays_ && this->showArrows_)
     219                        if (this->showOverlays_ && this->showArrows_)
    219220                            alignArrows();
    220221                    }
     
    222223                        hideArrows();
    223224
    224                     if ( this->showDamageOverlay_ && ( this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0 ) ) {
     225                    if (this->showDamageOverlay_ && (this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0))
     226                    {
    225227                        this->damageOverlayTT_ -= dt;
    226228                        this->damageOverlayTR_ -= dt;
    227229                        this->damageOverlayTB_ -= dt;
    228230                        this->damageOverlayTL_ -= dt;
    229                         if ( this->damageOverlayTT_ <= 0 )
     231                        if (this->damageOverlayTT_ <= 0)
    230232                            this->damageOverlayTop_->hide();
    231                         if ( this->damageOverlayTR_ <= 0 )
     233                        if (this->damageOverlayTR_ <= 0)
    232234                            this->damageOverlayRight_->hide();
    233                         if ( this->damageOverlayTB_ <= 0 )
     235                        if (this->damageOverlayTB_ <= 0)
    234236                            this->damageOverlayBottom_->hide();
    235                         if ( this->damageOverlayTL_ <= 0 )
     237                        if (this->damageOverlayTL_ <= 0)
    236238                            this->damageOverlayLeft_->hide();
    237239                    }
     
    241243                this->hideOverlays();
    242244
    243             if ( this->acceleration_ > 0 )
    244             {
    245 /*
    246 if (this->controllableEntity_ && this->controllableEntity_->getEngine()) {
    247     std::cout << this->controllableEntity_->getEngine()->getAccelerationFront() << endl;
    248 }
    249 */
    250                 if ( this->accelerating_ )
     245            if (this->acceleration_ > 0)
     246            {
     247                if (this->accelerating_)
    251248                    HumanController::moveFrontBack(Vector2(1, 0));
    252249                else
     
    265262    }
    266263
    267     /*void NewHumanController::tick(float dt)
    268     {
    269         if (GameMode::playsSound() && NewHumanController::localController_s && NewHumanController::localController_s->controllableEntity_)
    270         {
    271             // Update sound listener
    272             Camera* camera = NewHumanController::localController_s->controllableEntity_->getCamera();
    273             if (camera)
    274             {
    275                 SoundManager::getInstance().setListenerPosition(camera->getWorldPosition());
    276                 SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation());
    277             }
    278             else
    279                 COUT(3) << "NewHumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
    280         }
    281     }*/
    282    
    283264    void NewHumanController::doFire(unsigned int firemode)
    284265    {
    285         if ( !this->controllableEntity_ )
     266        if (!this->controllableEntity_)
    286267            return;
    287         //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) {
    288 
    289 /*
    290         // Get results, create a node/entity on the position
    291         for ( itr = result.begin(); itr != result.end(); itr++ )
    292         {
    293             if (itr->movable && itr->movable->getName() == "Head")
    294             {
    295                 soundMgr->StopSound( &jaguarSoundChannel );
    296                 soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
    297                 break;
    298             } // if
    299         }
    300 */
    301268
    302269        this->firemode_ = firemode;
     
    313280    }
    314281
    315     void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {
    316         if ( this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook() ) {
     282    void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     283    {
     284        if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
     285        {
    317286            Vector3 posA;
    318             if ( originator )
     287            if (originator)
    319288                posA = originator->getWorldPosition();
    320289            else
     
    329298            //y is down positive
    330299            relativeHit.normalise();
    331 //            COUT(0) << relativeHit << endl;
    332300
    333301            float threshold = 0.3;
    334             // && abs(relativeHit.y) < 0.5
    335             if ( relativeHit.x > threshold) // Left
     302            if (relativeHit.x > threshold) // Left
    336303            {
    337304                this->damageOverlayLeft_->show();
     
    339306                //this->damageOverlayLeft_->setBackgroundAlpha(0.3);
    340307            }
    341             if ( relativeHit.x < -threshold) //Right
     308            if (relativeHit.x < -threshold) //Right
    342309            {
    343310                this->damageOverlayRight_->show();
     
    345312                //this->damageOverlayRight_->setBackgroundAlpha(0.3);
    346313            }
    347             if ( relativeHit.y > threshold) //Top
     314            if (relativeHit.y > threshold) //Top
    348315            {
    349316                this->damageOverlayBottom_->show();
     
    351318                //this->damageOverlayTop_->setBackgroundAlpha(0.3);
    352319            }
    353             if ( relativeHit.y < -threshold) //Bottom
     320            if (relativeHit.y < -threshold) //Bottom
    354321            {
    355322                this->damageOverlayTop_->show();
     
    357324                //this->damageOverlayBottom_->setBackgroundAlpha(0.3);
    358325            }
    359 
    360326        }
    361327    }
     
    403369                if (wePtr)
    404370                {
    405                     // go through all parents of object and look wheter they are Sightable or not
     371                    // go through all parents of object and look whether they are sightable or not
    406372                    bool isSightable = false;
    407373                    WorldEntity* parent = wePtr->getParent();
    408                     while( parent )
     374                    while (parent)
    409375                    {
    410376                        if (this->targetMask_.isExcluded(parent->getIdentifier()))
     
    419385                        }
    420386                    }
    421                     if ( !isSightable )
     387                    if (!isSightable)
    422388                        continue;
    423389                }
    424390
    425                 if ( this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr )
    426                 {
     391                if (this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr)
    427392                    this->getControllableEntity()->setTarget(wePtr);
    428                 }
    429 
    430                 if( pawn )
    431                 {
     393
     394                if (pawn)
    432395                    pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance );
    433                 }
    434396
    435397                //itr->movable->getParentSceneNode()->showBoundingBox(true);
    436                 //std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
    437398                //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition()
    438399                return;
    439400            }
    440 
    441         }
    442         if ( pawn )
    443         {
     401        }
     402
     403        if (pawn)
    444404            pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 1200 );
    445         }
    446405
    447406        if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != 0 )
    448407            this->getControllableEntity()->setTarget( 0 );
    449    
    450408
    451409        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000);
     
    458416
    459417        //if (this->acceleration_ == 0)
    460             HumanController::frontback(value);
     418        HumanController::frontback(value);
    461419    }
    462420
    463421    void NewHumanController::yaw(const Vector2& value)
    464422    {
    465 //         SUPER(NewHumanController, yaw, value);
    466         if (this->controlMode_ == 0 || ( this->controllableEntity_ && this->controllableEntity_->isInMouseLook() ) )
     423        //SUPER(NewHumanController, yaw, value);
     424        if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook()))
    467425            HumanController::yaw(value);
    468426
     
    472430    void NewHumanController::pitch(const Vector2& value)
    473431    {
    474 //         SUPER(NewHumanController, pitch, value);
    475         if (this->controlMode_ == 0 || ( this->controllableEntity_ && this->controllableEntity_->isInMouseLook() ) )
     432        //SUPER(NewHumanController, pitch, value);
     433        if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook()))
    476434            HumanController::pitch(value);
    477435
     
    495453    void NewHumanController::changedControllableEntity()
    496454    {
    497 /*
    498         if( this->getControllableEntity() )
    499             CCOUT(0) << "changed controllable entity to: " << this->getControllableEntity()->getIdentifier()->getName() << endl;
    500         else
    501             CCOUT(0) << "changed controllable entity to: " << this->getControllableEntity() << endl;
    502 */
    503455        this->controlMode_ = 0;
    504456        this->currentYaw_ = 0;
    505457        this->currentPitch_ = 0;
    506         if (this->getControllableEntity() && ( this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket" ))
     458        if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
    507459        {
    508460            this->showOverlays_ = true;
    509             if( !this->controlPaused_ )
     461            if (!this->controlPaused_)
    510462            {
    511463                this->showOverlays();
     
    522474    void NewHumanController::accelerate()
    523475    {
    524         if ( NewHumanController::localController_s )
    525         {
     476        if (NewHumanController::localController_s)
    526477            NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ + 0.2f, 0.00f, 1.0f);
    527         }
    528478    }
    529479
    530480    void NewHumanController::decelerate()
    531481    {
    532         if ( NewHumanController::localController_s )
    533         {
     482        if (NewHumanController::localController_s)
    534483            NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ - 0.1f, 0.0f, 1.0f);
    535         }
    536     }
    537 
    538     void NewHumanController::doResumeControl() {
     484    }
     485
     486    void NewHumanController::doResumeControl()
     487    {
    539488        this->controlPaused_ = false;
    540         if( this->showOverlays_ ) {
     489        if (this->showOverlays_)
    541490            this->showOverlays();
    542         }
    543     }
    544 
    545     void NewHumanController::doPauseControl() {
     491    }
     492
     493    void NewHumanController::doPauseControl()
     494    {
    546495        this->controlPaused_ = true;
    547 //        COUT(0) << "pause control" << endl;
    548496        this->hideOverlays();
    549497    }
    550498
    551     void NewHumanController::alignArrows() {
    552         if (showArrows_) {
     499    void NewHumanController::alignArrows()
     500    {
     501        if (showArrows_)
     502        {
    553503            hideArrows();
    554504   
    555505            float distance = sqrt(pow(static_cast<float>(this->currentYaw_)/2*-1,2) + pow(static_cast<float>(this->currentPitch_)/2*-1,2));
    556506   
    557             if ( distance > 0.04 && distance <= 0.59 * arrowsSize_ / 2.0 ) {
     507            if (distance > 0.04 && distance <= 0.59 * arrowsSize_ / 2.0 )
     508            {
    558509                this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
    559    
    560510                this->arrowsOverlay1_->show();
    561511            }
    562             else if ( distance > 0.59 * arrowsSize_ / 2.0 && distance <= 0.77 * arrowsSize_ / 2.0 ) {
     512            else if (distance > 0.59 * arrowsSize_ / 2.0 && distance <= 0.77 * arrowsSize_ / 2.0 )
     513            {
    563514                this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
    564    
    565515                this->arrowsOverlay2_->show();
    566516            }
    567             else if ( distance > 0.77 * arrowsSize_ / 2.0 && distance <= arrowsSize_ / 2.0 ) {
     517            else if (distance > 0.77 * arrowsSize_ / 2.0 && distance <= arrowsSize_ / 2.0)
     518            {
    568519                this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
    569    
    570520                this->arrowsOverlay3_->show();
    571521            }
    572             else if ( distance > arrowsSize_ / 2.0 ) {
     522            else if (distance > arrowsSize_ / 2.0)
     523            {
    573524                this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
    574    
    575525                this->arrowsOverlay4_->show();
    576526            }
     
    578528    }
    579529
    580     void NewHumanController::showOverlays() {
    581         if( !GameMode::showsGraphics() )
     530    void NewHumanController::showOverlays()
     531    {
     532        if (!GameMode::showsGraphics())
    582533            return;
    583534        this->crossHairOverlay_->show();
    584535        this->centerOverlay_->show();
    585536
    586         if (showArrows_) {
     537        if (showArrows_)
     538        {
    587539            this->arrowsOverlay1_->show();
    588540            this->arrowsOverlay2_->show();
     
    592544    }
    593545
    594     void NewHumanController::hideOverlays() {
    595         if( !GameMode::showsGraphics() )
     546    void NewHumanController::hideOverlays()
     547    {
     548        if (!GameMode::showsGraphics())
    596549            return;
    597550        this->crossHairOverlay_->hide();
    598551        this->centerOverlay_->hide();
    599552
    600         if ( showDamageOverlay_ ) {
     553        if (showDamageOverlay_)
     554        {
    601555            this->damageOverlayTop_->hide();
    602556            this->damageOverlayRight_->hide();
     
    608562    }
    609563
    610     void NewHumanController::hideArrows() {
    611         if( !GameMode::showsGraphics() )
     564    void NewHumanController::hideArrows()
     565    {
     566        if(!GameMode::showsGraphics())
    612567            return;
    613         if (showArrows_) {
     568        if (showArrows_)
     569        {
    614570            this->arrowsOverlay1_->hide();
    615571            this->arrowsOverlay2_->hide();
  • code/branches/presentation2/src/orxonox/controllers/NewHumanController.h

    r6310 r6377  
    7676            unsigned int                controlMode_;
    7777            static NewHumanController*  localController_s;
     78
    7879        private:
    7980            float                       currentYaw_;
Note: See TracChangeset for help on using the changeset viewer.