Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

many changes, can't remember everything, but these are the most important:

  • attaching entities to other entities works
  • displaying models, lights and shadows works
  • controlling a spectator works
  • removed an update hack in PositionableEntity because I've found a much better solution

and with "works" I mean: it works on client, server and standalone

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