Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc @ 2254

Last change on this file since 2254 was 2254, checked in by landauf, 15 years ago

Update your media repository and delete keybindings.ini if you want to use boost (space).

  • Added new class "Engine" to control the speed of a SpaceShip (Engine is an Item, MultiStateEngine is a specialized version of Engine)
  • Added FadingBillboard, a billboard with the ability to fade in and out smoothly when activated/deactivated.
  • Several changes in Backlight, it's now a child of FadingBillboard
  • Some changes concerning local control in ControllableEntity
  • Fixed a bug in WorldEntity caused by different destruction order of attached objects on server and client
  • Added a "MainState" to BaseObject. An object has several states (activity, visibility, …) and one of it can be defined as "MainState" in the XML file. Other objects can change this state without knowing which state it really is (used by MultiStateEngine).
  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/objecthierarchy/src/orxonox/objects/worldentities/Backlight.ccmergedeligible
    /code/branches/ceguilua/src/orxonox/objects/Backlight.cc1802-1808
    /code/branches/core3/src/orxonox/objects/Backlight.cc1572-1739
    /code/branches/gcc43/src/orxonox/objects/Backlight.cc1580
    /code/branches/gui/src/orxonox/objects/Backlight.cc1635-1723
    /code/branches/input/src/orxonox/objects/Backlight.cc1629-1636
    /code/branches/script_trigger/src/orxonox/objects/Backlight.cc1295-1953,​1955
File size: 7.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 "Backlight.h"
31
32#include <OgreRibbonTrail.h>
33#include <OgreSceneManager.h>
34
35#include "core/Core.h"
36#include "core/CoreIncludes.h"
37#include "core/Executor.h"
38#include "core/XMLPort.h"
39#include "objects/Scene.h"
40
41namespace orxonox
42{
43    CreateFactory(Backlight);
44
45    Backlight::Backlight(BaseObject* creator) : FadingBillboard(creator)
46    {
47        RegisterObject(Backlight);
48
49        this->ribbonTrail_ = 0;
50        this->ribbonTrailNode_ = 0;
51
52        this->width_ = 0;
53        this->length_ = 1.0f;
54        this->lifetime_ = 0.001f;
55        this->maxelements_ = 1;
56
57        this->tickcount_ = 0;
58
59        if (Core::showsGraphics())
60        {
61            assert(this->getScene());
62            assert(this->getScene()->getSceneManager());
63            assert(this->getScene()->getRootSceneNode());
64
65            this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName());
66
67            this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
68            this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
69
70            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
71            this->ribbonTrail_->setTrailLength(this->length_);
72            this->ribbonTrail_->setInitialWidth(0, 0);
73        }
74
75        this->registerVariables();
76    }
77
78    Backlight::~Backlight()
79    {
80        if (this->isInitialized())
81        {
82            if (this->ribbonTrail_)
83            {
84                if (this->ribbonTrailNode_)
85                {
86                    this->ribbonTrailNode_->detachObject(this->ribbonTrail_);
87                    this->getScene()->getSceneManager()->destroySceneNode(this->ribbonTrailNode_->getName());
88                }
89                this->getScene()->getSceneManager()->destroyRibbonTrail(this->ribbonTrail_);
90            }
91        }
92    }
93
94    void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode)
95    {
96        SUPER(Backlight, XMLPort, xmlelement, mode);
97
98        XMLPortParam(Backlight, "length",        setLength,        getLength,        xmlelement, mode).defaultValues(100.0f);
99        XMLPortParam(Backlight, "width",         setWidth,         getWidth,         xmlelement, mode).defaultValues(1.0f);
100        XMLPortParam(Backlight, "elements",      setMaxElements,   getMaxElements,   xmlelement, mode).defaultValues(10);
101        XMLPortParam(Backlight, "lifetime",      setLifetime,      getLifetime,      xmlelement, mode).defaultValues(1.0f);
102        XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode);
103    }
104
105    void Backlight::registerVariables()
106    {
107        REGISTERDATA  (this->width_,         direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_width));
108        REGISTERDATA  (this->lifetime_,      direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_lifetime));
109        REGISTERDATA  (this->length_,        direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_length));
110        REGISTERDATA  (this->maxelements_,   direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_maxelements));
111        REGISTERSTRING(this->trailmaterial_, direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_trailmaterial));
112    }
113
114    void Backlight::changedColour()
115    {
116        FadingBillboard::changedColour();
117
118        if (this->ribbonTrail_ && this->tickcount_ >= 2)
119            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
120    }
121
122    void Backlight::update_width()
123    {
124        if (this->ribbonTrail_ && this->tickcount_ >= 2)
125            this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getWorldScale());
126        this->update_lifetime();
127    }
128
129    void Backlight::update_lifetime()
130    {
131        if (this->ribbonTrail_ && this->tickcount_ >= 2)
132        {
133            this->ribbonTrail_->setWidthChange(0, this->width_ * this->getWorldScale() / this->lifetime_/* * Backlight::timeFactor_s*/);
134            this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_/* * Backlight::timeFactor_s*/);
135        }
136    }
137
138    void Backlight::update_length()
139    {
140        if (this->ribbonTrail_ && this->tickcount_ >= 2)
141            this->ribbonTrail_->setTrailLength(this->length_ * this->getWorldScale());
142    }
143
144    void Backlight::update_maxelements()
145    {
146        if (this->ribbonTrail_ && this->tickcount_ >= 2)
147            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
148    }
149
150    void Backlight::update_trailmaterial()
151    {
152        if (this->ribbonTrail_ && this->tickcount_ >= 2)
153            this->ribbonTrail_->setMaterialName(this->trailmaterial_);
154    }
155
156    void Backlight::changedVisibility()
157    {
158        SUPER(Backlight, changedVisibility);
159
160        if (this->ribbonTrail_)
161            this->ribbonTrail_->setVisible(this->isVisible());
162    }
163
164    void Backlight::startturnonoff()
165    {
166        FadingBillboard::startturnonoff();
167
168        if (this->ribbonTrail_ && this->isActive() && this->isVisible())
169            this->ribbonTrail_->setVisible(true);
170    }
171
172    void Backlight::stopturnonoff()
173    {
174        this->postprocessingtime_ = max(0.0f, this->lifetime_ - this->turnofftime_);
175
176        FadingBillboard::stopturnonoff();
177
178        if (this->ribbonTrail_)
179            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
180    }
181
182    void Backlight::poststopturnonoff()
183    {
184        FadingBillboard::poststopturnonoff();
185
186        if (this->ribbonTrail_)
187            this->ribbonTrail_->setVisible(false);
188    }
189
190    void Backlight::changedScale()
191    {
192        SUPER(Backlight, changedScale);
193
194        this->update_width();
195        this->update_length();
196    }
197
198    void Backlight::tick(float dt)
199    {
200        if (this->tickcount_ < 2)
201        {
202            ++this->tickcount_;
203            if (this->tickcount_ == 2)
204            {
205                this->changedColour();
206                this->update_width();
207                this->update_lifetime();
208                this->update_length();
209                this->update_maxelements();
210                this->update_trailmaterial();
211                if (this->ribbonTrail_)
212                    this->ribbonTrail_->addNode(this->getNode());
213            }
214        }
215
216        SUPER(Backlight, tick, dt);
217
218        if (this->ribbonTrail_ && this->changedirection_ != 0)
219        {
220            // we use alpha_blend, only adjust alpha
221            const ColourValue& colour = this->getColour();
222            this->ribbonTrail_->setInitialColour(0, colour.r, colour.g, colour.b, this->getFadedColour().a);
223        }
224    }
225}
Note: See TracBrowser for help on using the repository browser.