Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc @ 3110

Last change on this file since 3110 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

  • Property svn:eol-style set to native
File size: 6.0 KB
Line 
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:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Spectator.h"
30
31#include <OgreBillboardSet.h>
32
33#include "core/CoreIncludes.h"
34#include "core/ConfigValueIncludes.h"
35#include "core/GameMode.h"
36#include "objects/worldentities/Model.h"
37#include "objects/Scene.h"
38#include "objects/infos/PlayerInfo.h"
39#include "objects/gametypes/Gametype.h"
40#include "tools/BillboardSet.h"
41#include "overlays/OverlayText.h"
42#include "overlays/OverlayGroup.h"
43#include "util/Convert.h"
44
45namespace orxonox
46{
47    CreateFactory(Spectator);
48
49    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
50    {
51        RegisterObject(Spectator);
52
53        this->speed_ = 200;
54
55        this->yaw_ = 0;
56        this->pitch_ = 0;
57        this->roll_ = 0;
58        this->localVelocity_ = Vector3::ZERO;
59        this->setHudTemplate("spectatorhud");
60        this->greetingFlare_ = 0;
61
62        this->setDestroyWhenPlayerLeft(true);
63
64        if (GameMode::showsGraphics())
65        {
66            this->greetingFlare_ = new BillboardSet();
67            this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
68            if (this->greetingFlare_->getBillboardSet())
69                this->attachOgreObject(this->greetingFlare_->getBillboardSet());
70            this->greetingFlare_->setVisible(false);
71        }
72
73        this->bGreetingFlareVisible_ = false;
74        this->bGreeting_ = false;
75
76        this->setConfigValues();
77        this->registerVariables();
78    }
79
80    Spectator::~Spectator()
81    {
82        if (this->isInitialized())
83        {
84            if (this->greetingFlare_)
85            {
86                if (this->greetingFlare_->getBillboardSet())
87                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
88
89                delete this->greetingFlare_;
90            }
91        }
92    }
93
94    void Spectator::setConfigValues()
95    {
96        SetConfigValue(speed_, 200.0f);
97    }
98
99    void Spectator::registerVariables()
100    {
101        registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
102        registerVariable(this->bGreeting_,             variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
103    }
104
105    void Spectator::changedGreeting()
106    {
107        this->bGreetingFlareVisible_ = this->bGreeting_;
108        this->changedFlareVisibility();
109    }
110
111    void Spectator::changedFlareVisibility()
112    {
113        if (this->greetingFlare_)
114            this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
115    }
116
117    void Spectator::tick(float dt)
118    {
119        if (this->hasLocalController())
120        {
121            float localSpeedSquared = this->localVelocity_.squaredLength();
122            float localSpeed;
123            if (localSpeedSquared > 1.0)
124                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
125            else
126                localSpeed = this->speed_;
127
128            this->localVelocity_.x *= localSpeed;
129            this->localVelocity_.y *= localSpeed;
130            this->localVelocity_.z *= localSpeed;
131            this->setVelocity(this->getOrientation() * this->localVelocity_);
132            this->localVelocity_.x = 0;
133            this->localVelocity_.y = 0;
134            this->localVelocity_.z = 0;
135
136            if (!this->isInMouseLook())
137            {
138                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()));
139                this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
140                this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
141            }
142
143            this->yaw_ = this->pitch_ = this->roll_ = 0;
144        }
145
146        SUPER(Spectator, tick, dt);
147    }
148
149    void Spectator::setPlayer(PlayerInfo* player)
150    {
151        ControllableEntity::setPlayer(player);
152
153//        this->setObjectMode(objectDirection::toclient);
154    }
155
156    void Spectator::startLocalHumanControl()
157    {
158        ControllableEntity::startLocalHumanControl();
159    }
160
161    void Spectator::moveFrontBack(const Vector2& value)
162    {
163        this->localVelocity_.z -= value.x;
164    }
165
166    void Spectator::moveRightLeft(const Vector2& value)
167    {
168        this->localVelocity_.x += value.x;
169    }
170
171    void Spectator::moveUpDown(const Vector2& value)
172    {
173        this->localVelocity_.y += value.x;
174    }
175
176    void Spectator::rotateYaw(const Vector2& value)
177    {
178        this->yaw_ += value.y;
179
180        ControllableEntity::rotateYaw(value);
181    }
182
183    void Spectator::rotatePitch(const Vector2& value)
184    {
185        this->pitch_ += value.y;
186
187        ControllableEntity::rotatePitch(value);
188    }
189
190    void Spectator::rotateRoll(const Vector2& value)
191    {
192        this->roll_ += value.y;
193
194        ControllableEntity::rotateRoll(value);
195    }
196
197    void Spectator::fire(unsigned int firemode)
198    {
199        if (this->getPlayer())
200            this->getPlayer()->setReadyToSpawn(true);
201    }
202
203    void Spectator::greet()
204    {
205        this->bGreeting_ = !this->bGreeting_;
206
207        if (GameMode::isMaster())
208        {
209            this->bGreetingFlareVisible_ = this->bGreeting_;
210            this->changedFlareVisibility();
211        }
212    }
213}
Note: See TracBrowser for help on using the repository browser.