Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.cc @ 2478

Last change on this file since 2478 was 2478, checked in by landauf, 15 years ago
  • Readded smooth camera movement (configurable through CameraPosition), works also with camera-position-changes
  • Added free mouse look (press left control key)
  • Made strength of boost-blur configurable
  • Property svn:eol-style set to native
File size: 5.5 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 "OrxonoxStableHeaders.h"
30#include "Spectator.h"
31
32#include "core/CoreIncludes.h"
33#include "core/ConfigValueIncludes.h"
34#include "core/Core.h"
35#include "objects/worldentities/Model.h"
36#include "objects/Scene.h"
37#include "objects/infos/PlayerInfo.h"
38#include "objects/gametypes/Gametype.h"
39#include "tools/BillboardSet.h"
40#include "overlays/OverlayText.h"
41#include "overlays/OverlayGroup.h"
42#include "util/Convert.h"
43
44namespace orxonox
45{
46    CreateFactory(Spectator);
47
48    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
49    {
50        RegisterObject(Spectator);
51
52        this->speed_ = 200;
53
54        this->yaw_ = 0;
55        this->pitch_ = 0;
56        this->roll_ = 0;
57        this->setHudTemplate("spectatorhud");
58
59        this->setDestroyWhenPlayerLeft(true);
60
61        this->greetingFlare_ = new BillboardSet();
62        this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 0, 0), 1);
63        if (this->greetingFlare_->getBillboardSet())
64            this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
65        this->greetingFlare_->setVisible(false);
66        this->bGreetingFlareVisible_ = false;
67        this->bGreeting_ = false;
68
69        this->setConfigValues();
70        this->registerVariables();
71    }
72
73    Spectator::~Spectator()
74    {
75        if (this->isInitialized())
76        {
77            if (this->greetingFlare_)
78            {
79                if (this->greetingFlare_->getBillboardSet())
80                    this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
81                delete this->greetingFlare_;
82            }
83        }
84    }
85
86    void Spectator::setConfigValues()
87    {
88        SetConfigValue(speed_, 200.0f);
89    }
90
91    void Spectator::registerVariables()
92    {
93        REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
94        REGISTERDATA(this->bGreeting_,             direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
95    }
96
97    void Spectator::changedGreeting()
98    {
99        this->bGreetingFlareVisible_ = this->bGreeting_;
100        this->changedFlareVisibility();
101    }
102
103    void Spectator::changedFlareVisibility()
104    {
105        this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
106    }
107
108    void Spectator::tick(float dt)
109    {
110        if (this->hasLocalController())
111        {
112            Vector3 velocity = this->getVelocity();
113            velocity.normalise();
114            this->setVelocity(velocity * this->speed_);
115
116            if (!this->isInMouseLook())
117            {
118                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()));
119                this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
120                this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
121            }
122
123            this->yaw_ = this->pitch_ = this->roll_ = 0;
124        }
125
126        SUPER(Spectator, tick, dt);
127
128        if (this->hasLocalController())
129        {
130            this->setVelocity(Vector3::ZERO);
131        }
132    }
133
134    void Spectator::setPlayer(PlayerInfo* player)
135    {
136        ControllableEntity::setPlayer(player);
137
138//        this->setObjectMode(direction::toclient);
139    }
140
141    void Spectator::startLocalHumanControl()
142    {
143        ControllableEntity::startLocalHumanControl();
144    }
145
146    void Spectator::moveFrontBack(const Vector2& value)
147    {
148        this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);
149    }
150
151    void Spectator::moveRightLeft(const Vector2& value)
152    {
153        this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);
154    }
155
156    void Spectator::moveUpDown(const Vector2& value)
157    {
158        this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);
159    }
160
161    void Spectator::rotateYaw(const Vector2& value)
162    {
163        this->yaw_ = value.y;
164
165        ControllableEntity::rotateYaw(value);
166    }
167
168    void Spectator::rotatePitch(const Vector2& value)
169    {
170        this->pitch_ = value.y;
171
172        ControllableEntity::rotatePitch(value);
173    }
174
175    void Spectator::rotateRoll(const Vector2& value)
176    {
177        this->roll_ = value.y;
178
179        ControllableEntity::rotateRoll(value);
180    }
181
182    void Spectator::fire()
183    {
184        if (this->getPlayer())
185            this->getPlayer()->setReadyToSpawn(true);
186    }
187
188    void Spectator::greet()
189    {
190        this->bGreeting_ = !this->bGreeting_;
191
192        if (Core::isMaster())
193        {
194            this->bGreetingFlareVisible_ = this->bGreeting_;
195            this->changedFlareVisibility();
196        }
197    }
198}
Note: See TracBrowser for help on using the repository browser.