Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.cc @ 2019

Last change on this file since 2019 was 2019, checked in by landauf, 16 years ago

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

File size: 6.3 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/Core.h"
34#include "objects/worldentities/Model.h"
35#include "objects/Scene.h"
36#include "objects/infos/PlayerInfo.h"
37#include "tools/BillboardSet.h"
38
39namespace orxonox
40{
41    CreateFactory(Spectator);
42
43    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
44    {
45        RegisterObject(Spectator);
46
47        this->speed_ = 100;
48        this->rotationSpeed_ = 3;
49
50        this->yaw_ = 0;
51        this->pitch_ = 0;
52        this->roll_ = 0;
53        this->setHudTemplate("spectatorhud");
54
55        this->setDestroyWhenPlayerLeft(true);
56
57        // test test test
58        if (this->getScene()->getSceneManager())
59        {
60            this->testmesh_ = new Mesh();
61            this->testnode_ = this->getNode()->createChildSceneNode();
62            this->testmesh_->setMeshSource(this->getScene()->getSceneManager(), "assff.mesh");
63            if (this->testmesh_->getEntity())
64                this->testnode_->attachObject(this->testmesh_->getEntity());
65            this->testnode_->pitch(Degree(-90));
66            this->testnode_->roll(Degree(+90));
67            this->testnode_->scale(10, 10, 10);
68        }
69        else
70        {
71            this->testmesh_ = 0;
72            this->testnode_ = 0;
73        }
74        // test test test
75
76        this->greetingFlare_ = new BillboardSet();
77        this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
78        this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
79        this->greetingFlare_->setVisible(false);
80        this->bGreetingFlareVisible_ = false;
81        this->bGreeting_ = false;
82
83        this->registerVariables();
84    }
85
86    Spectator::~Spectator()
87    {
88        if (this->isInitialized())
89        {
90            if (this->greetingFlare_)
91            {
92                this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
93                delete this->greetingFlare_;
94            }
95
96            // test test test
97            {
98                if (this->testmesh_ && this->testnode_)
99                    this->testnode_->detachObject(this->testmesh_->getEntity());
100
101                if (this->testmesh_)
102                    delete this->testmesh_;
103
104                if (this->testnode_)
105                    this->getNode()->removeAndDestroyChild(this->testnode_->getName());
106            }
107            // test test test
108        }
109    }
110
111    void Spectator::registerVariables()
112    {
113        REGISTERDATA(this->bGreetingFlareVisible_, network::direction::toclient, new network::NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
114        REGISTERDATA(this->bGreeting_,             network::direction::toserver, new network::NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
115    }
116
117    void Spectator::changedGreeting()
118    {
119        this->bGreetingFlareVisible_ = this->bGreeting_;
120        this->changedFlareVisibility();
121    }
122
123    void Spectator::changedFlareVisibility()
124    {
125        this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
126    }
127
128    void Spectator::tick(float dt)
129    {
130        if (this->isLocallyControlled())
131        {
132            Vector3 velocity = this->getVelocity();
133            velocity.normalise();
134            this->setVelocity(velocity * this->speed_);
135
136            this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
137            this->pitch(Radian(this->pitch_ * this->rotationSpeed_));
138            this->roll(Radian(this->roll_ * this->rotationSpeed_));
139
140            this->yaw_ = this->pitch_ = this->roll_ = 0;
141        }
142
143        SUPER(Spectator, tick, dt);
144
145        if (this->isLocallyControlled())
146        {
147            this->setVelocity(Vector3::ZERO);
148        }
149    }
150
151    void Spectator::setPlayer(PlayerInfo* player)
152    {
153        ControllableEntity::setPlayer(player);
154
155//        this->setObjectMode(network::direction::toclient);
156    }
157
158    void Spectator::startLocalControl()
159    {
160        ControllableEntity::startLocalControl();
161        if (this->isLocallyControlled())
162            this->testmesh_->setVisible(false);
163    }
164
165    void Spectator::moveFrontBack(float value)
166    {
167        this->setVelocity(this->getVelocity() + value * this->speed_ * WorldEntity::FRONT);
168    }
169
170    void Spectator::moveRightLeft(float value)
171    {
172        this->setVelocity(this->getVelocity() + value * this->speed_ * WorldEntity::RIGHT);
173    }
174
175    void Spectator::moveUpDown(float value)
176    {
177        this->setVelocity(this->getVelocity() + value * this->speed_ * WorldEntity::UP);
178    }
179
180    void Spectator::rotateYaw(float value)
181    {
182        this->yaw_ = value;
183    }
184
185    void Spectator::rotatePitch(float value)
186    {
187        this->pitch_ = value;
188    }
189
190    void Spectator::rotateRoll(float value)
191    {
192        this->roll_ = value;
193    }
194
195    void Spectator::fire()
196    {
197        if (this->getPlayer())
198            this->getPlayer()->setReadyToSpawn(true);
199    }
200
201    void Spectator::greet()
202    {
203        this->bGreeting_ = !this->bGreeting_;
204
205        if (Core::isMaster())
206        {
207            this->bGreetingFlareVisible_ = this->bGreeting_;
208            this->changedFlareVisibility();
209        }
210    }
211}
Note: See TracBrowser for help on using the repository browser.