Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/orxonox/objects/worldentities/pawns/Spectator.cc @ 3186

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

Last part of the cleanup: world entities.

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