Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2009, 10:17:35 PM (16 years ago)
Author:
rgrieder
Message:

Merged presentation branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2171 r2662  
    3030#include "Spectator.h"
    3131
     32#include <OgreBillboardSet.h>
     33
    3234#include "core/CoreIncludes.h"
     35#include "core/ConfigValueIncludes.h"
    3336#include "core/Core.h"
    3437#include "objects/worldentities/Model.h"
     
    4952        RegisterObject(Spectator);
    5053
    51         this->speed_ = 100;
    52         this->rotationSpeed_ = 3;
     54        this->speed_ = 200;
    5355
    5456        this->yaw_ = 0;
    5557        this->pitch_ = 0;
    5658        this->roll_ = 0;
     59        this->localVelocity_ = Vector3::ZERO;
    5760        this->setHudTemplate("spectatorhud");
    58         this->hudmode_ = 0;
     61        this->greetingFlare_ = 0;
    5962
    6063        this->setDestroyWhenPlayerLeft(true);
    6164
    62         this->greetingFlare_ = new BillboardSet();
    63         this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
    64         if (this->greetingFlare_->getBillboardSet())
    65             this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
    66         this->greetingFlare_->setVisible(false);
     65        if (Core::showsGraphics())
     66        {
     67            this->greetingFlare_ = new BillboardSet();
     68            this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
     69            if (this->greetingFlare_->getBillboardSet())
     70                this->attachOgreObject(this->greetingFlare_->getBillboardSet());
     71            this->greetingFlare_->setVisible(false);
     72        }
     73
    6774        this->bGreetingFlareVisible_ = false;
    6875        this->bGreeting_ = false;
    6976
     77        this->setConfigValues();
    7078        this->registerVariables();
    7179    }
     
    7886            {
    7987                if (this->greetingFlare_->getBillboardSet())
    80                     this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
     88                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
     89
    8190                delete this->greetingFlare_;
    8291            }
     
    8493    }
    8594
     95    void Spectator::setConfigValues()
     96    {
     97        SetConfigValue(speed_, 200.0f);
     98    }
     99
    86100    void Spectator::registerVariables()
    87101    {
    88         REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
    89         REGISTERDATA(this->bGreeting_,             direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
    90         REGISTERDATA(this->hudmode_,               direction::toclient);
     102        registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
     103        registerVariable(this->bGreeting_,             variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
    91104    }
    92105
     
    99112    void Spectator::changedFlareVisibility()
    100113    {
    101         this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
     114        if ( this->greetingFlare_ )
     115            this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
    102116    }
    103117
    104118    void Spectator::tick(float dt)
    105119    {
    106         this->updateHUD();
    107 
    108         if (this->isLocallyControlled())
    109         {
    110             Vector3 velocity = this->getVelocity();
    111             velocity.normalise();
    112             this->setVelocity(velocity * this->speed_);
    113 
    114             this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
    115             this->pitch(Radian(this->pitch_ * this->rotationSpeed_));
    116             this->roll(Radian(this->roll_ * this->rotationSpeed_));
     120        if (this->hasLocalController())
     121        {
     122            float localSpeedSquared = this->localVelocity_.squaredLength();
     123            float localSpeed;
     124            if (localSpeedSquared > 1.0)
     125                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
     126            else
     127                localSpeed = this->speed_;
     128
     129            this->localVelocity_.x *= localSpeed;
     130            this->localVelocity_.y *= localSpeed;
     131            this->localVelocity_.z *= localSpeed;
     132            this->setVelocity(this->getOrientation() * this->localVelocity_);
     133            this->localVelocity_.x = 0;
     134            this->localVelocity_.y = 0;
     135            this->localVelocity_.z = 0;
     136
     137            if (!this->isInMouseLook())
     138            {
     139                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()));
     140                this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     141                this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
     142            }
    117143
    118144            this->yaw_ = this->pitch_ = this->roll_ = 0;
     
    120146
    121147        SUPER(Spectator, tick, dt);
    122 
    123         if (this->isLocallyControlled())
    124         {
    125             this->setVelocity(Vector3::ZERO);
    126         }
    127148    }
    128149
     
    131152        ControllableEntity::setPlayer(player);
    132153
    133 //        this->setObjectMode(direction::toclient);
    134     }
    135 
    136     void Spectator::startLocalControl()
    137     {
    138         ControllableEntity::startLocalControl();
    139 //        if (this->isLocallyControlled())
    140 //            this->testmesh_->setVisible(false);
     154//        this->setObjectMode(objectDirection::toclient);
     155    }
     156
     157    void Spectator::startLocalHumanControl()
     158    {
     159        ControllableEntity::startLocalHumanControl();
    141160    }
    142161
    143162    void Spectator::moveFrontBack(const Vector2& value)
    144163    {
    145         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);
     164        this->localVelocity_.z -= value.x;
    146165    }
    147166
    148167    void Spectator::moveRightLeft(const Vector2& value)
    149168    {
    150         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);
     169        this->localVelocity_.x += value.x;
    151170    }
    152171
    153172    void Spectator::moveUpDown(const Vector2& value)
    154173    {
    155         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);
     174        this->localVelocity_.y += value.x;
    156175    }
    157176
    158177    void Spectator::rotateYaw(const Vector2& value)
    159178    {
    160         this->yaw_ = value.y;
     179        this->yaw_ -= value.y;
     180
     181        ControllableEntity::rotateYaw(value);
    161182    }
    162183
    163184    void Spectator::rotatePitch(const Vector2& value)
    164185    {
    165         this->pitch_ = value.y;
     186        this->pitch_ += value.y;
     187
     188        ControllableEntity::rotatePitch(value);
    166189    }
    167190
    168191    void Spectator::rotateRoll(const Vector2& value)
    169192    {
    170         this->roll_ = value.y;
    171     }
    172 
    173     void Spectator::fire()
     193        this->roll_ += value.y;
     194
     195        ControllableEntity::rotateRoll(value);
     196    }
     197
     198    void Spectator::fire(WeaponMode::Enum fireMode)
    174199    {
    175200        if (this->getPlayer())
     
    187212        }
    188213    }
    189 
    190     void Spectator::updateHUD()
    191     {
    192         // <hack>
    193         if (Core::isMaster())
    194         {
    195             if (this->getPlayer() && this->getGametype())
    196             {
    197                 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())
    198                 {
    199                     if (!this->getPlayer()->isReadyToSpawn())
    200                         this->hudmode_ = 0;
    201                     else
    202                         this->hudmode_ = 1;
    203                 }
    204                 else if (!this->getGametype()->hasEnded())
    205                 {
    206                     if (this->getGametype()->isStartCountdownRunning())
    207                         this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());
    208                     else
    209                         this->hudmode_ = 3;
    210                 }
    211                 else
    212                     this->hudmode_ = 4;
    213             }
    214             else
    215                 return;
    216         }
    217 
    218         if (this->getHUD())
    219         {
    220             std::string text;
    221             int hudmode = this->hudmode_ % 10;
    222 
    223             switch (hudmode)
    224             {
    225                 case 0:
    226                     text = "Press [Fire] to start the match";
    227                     break;
    228                 case 1:
    229                     text = "Waiting for other players";
    230                     break;
    231                 case 2:
    232                     text = convertToString((this->hudmode_ - 2) / 10);
    233                     break;
    234                 case 3:
    235                     text = "Press [Fire] to respawn";
    236                     break;
    237                 case 4:
    238                     text = "Game has ended";
    239                     break;
    240                 default:;
    241             }
    242 
    243             std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();
    244             for (; it != this->getHUD()->getOverlays().end(); ++it)
    245             {
    246                 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")
    247                 {
    248                     OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);
    249                     if (overlay)
    250                         overlay->setCaption(text);
    251                     break;
    252                 }
    253             }
    254         }
    255         // </hack>
    256     }
    257214}
Note: See TracChangeset for help on using the changeset viewer.