Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/toonshader/src/orxonox/objects/worldentities/Backlight.cc @ 5829

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

Merged r1-2096 of questsystem5 back to trunk

I hope there weren't more "hidden merge changes" in r2909 than the one in OverlayGroup (removeElement) (and related to this the adjustments in NotificationQueue).

The corresponding media commit seems not yet to be done, but it doesn't break the build.

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/buildsystem2/src/orxonox/objects/worldentities/Backlight.cc2506-2658
    /code/branches/buildsystem3/src/orxonox/objects/worldentities/Backlight.cc2662-2708
    /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/gui/src/orxonox/objects/worldentities/Backlight.cc2795-2894
    /code/branches/input/src/orxonox/objects/Backlight.cc1629-1636
    /code/branches/lodfinal/src/orxonox/objects/worldentities/Backlight.cc2372-2411
    /code/branches/miniprojects/src/orxonox/objects/worldentities/Backlight.cc2754-2824
    /code/branches/network/src/orxonox/objects/worldentities/Backlight.cc2356
    /code/branches/network64/src/orxonox/objects/worldentities/Backlight.cc2210-2355
    /code/branches/objecthierarchy/src/orxonox/objects/worldentities/Backlight.cc2100,​2110-2169
    /code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc2171-2479
    /code/branches/overlay/src/orxonox/objects/worldentities/Backlight.cc2117-2385
    /code/branches/physics/src/orxonox/objects/worldentities/Backlight.cc2107-2439
    /code/branches/physics_merge/src/orxonox/objects/worldentities/Backlight.cc2436-2457
    /code/branches/pickups2/src/orxonox/objects/worldentities/Backlight.cc2107-2497
    /code/branches/presentation/src/orxonox/objects/worldentities/Backlight.cc2369-2652,​2654-2660
    /code/branches/questsystem2/src/orxonox/objects/worldentities/Backlight.cc2107-2259
    /code/branches/questsystem5/src/orxonox/objects/worldentities/Backlight.cc2776-2905
    /code/branches/script_trigger/src/orxonox/objects/Backlight.cc1295-1953,​1955
    /code/branches/weapon2/src/orxonox/objects/worldentities/Backlight.cc2107-2488
    /code/branches/weaponsystem/src/orxonox/objects/worldentities/Backlight.cc2742-2890
    /code/trunk/src/orxonox/objects/worldentities/Backlight.cc2-2085
File size: 7.9 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/GameMode.h"
36#include "core/CoreIncludes.h"
37#include "core/Executor.h"
38#include "core/XMLPort.h"
39#include "objects/Scene.h"
40#include "util/Exception.h"
41
42namespace orxonox
43{
44    CreateFactory(Backlight);
45
46    Backlight::Backlight(BaseObject* creator) : FadingBillboard(creator)
47    {
48        RegisterObject(Backlight);
49
50        this->ribbonTrail_ = 0;
51        this->ribbonTrailNode_ = 0;
52
53        this->width_ = 0;
54        this->length_ = 1.0f;
55        this->lifetime_ = 0.001f;
56        this->maxelements_ = 1;
57
58        this->tickcount_ = 0;
59
60        if (GameMode::showsGraphics())
61        {
62            if (!this->getScene())
63                ThrowException(AbortLoading, "Can't create Backlight, no scene given.");
64            if (!this->getScene()->getSceneManager())
65                ThrowException(AbortLoading, "Can't create Backlight, no scene manager given.");
66            if (!this->getScene()->getRootSceneNode())
67                ThrowException(AbortLoading, "Can't create Backlight, no root scene node given.");
68
69            this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName());
70
71            this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
72            this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
73
74            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
75            this->ribbonTrail_->setTrailLength(this->length_);
76            this->ribbonTrail_->setInitialWidth(0, 0);
77        }
78
79        this->registerVariables();
80    }
81
82    Backlight::~Backlight()
83    {
84        if (this->isInitialized())
85        {
86            if (this->ribbonTrail_)
87            {
88                if (this->ribbonTrailNode_)
89                {
90                    this->ribbonTrailNode_->detachObject(this->ribbonTrail_);
91                    this->getScene()->getSceneManager()->destroySceneNode(this->ribbonTrailNode_->getName());
92                }
93                this->getScene()->getSceneManager()->destroyRibbonTrail(this->ribbonTrail_);
94            }
95        }
96    }
97
98    void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode)
99    {
100        SUPER(Backlight, XMLPort, xmlelement, mode);
101
102        XMLPortParam(Backlight, "length",        setLength,        getLength,        xmlelement, mode).defaultValues(100.0f);
103        XMLPortParam(Backlight, "width",         setWidth,         getWidth,         xmlelement, mode).defaultValues(1.0f);
104        XMLPortParam(Backlight, "elements",      setMaxElements,   getMaxElements,   xmlelement, mode).defaultValues(10);
105        XMLPortParam(Backlight, "lifetime",      setLifetime,      getLifetime,      xmlelement, mode).defaultValues(1.0f);
106        XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode);
107    }
108
109    void Backlight::registerVariables()
110    {
111        registerVariable(this->width_,         variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_width));
112        registerVariable(this->lifetime_,      variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_lifetime));
113        registerVariable(this->length_,        variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_length));
114        registerVariable(this->maxelements_,   variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_maxelements));
115        registerVariable(this->trailmaterial_, variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_trailmaterial));
116    }
117
118    void Backlight::changedColour()
119    {
120        FadingBillboard::changedColour();
121
122        if (this->ribbonTrail_ && this->tickcount_ >= 2)
123            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
124    }
125
126    void Backlight::update_width()
127    {
128        if (this->ribbonTrail_ && this->tickcount_ >= 2)
129            this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getWorldScale());
130        this->update_lifetime();
131    }
132
133    void Backlight::update_lifetime()
134    {
135        if (this->ribbonTrail_ && this->tickcount_ >= 2)
136        {
137            this->ribbonTrail_->setWidthChange(0, this->width_ * this->getWorldScale() / this->lifetime_ * this->getTimeFactor());
138            this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_ * this->getTimeFactor());
139        }
140    }
141
142    void Backlight::update_length()
143    {
144        if (this->ribbonTrail_ && this->tickcount_ >= 2)
145            this->ribbonTrail_->setTrailLength(this->length_ * this->getWorldScale());
146    }
147
148    void Backlight::update_maxelements()
149    {
150        if (this->ribbonTrail_ && this->tickcount_ >= 2)
151            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
152    }
153
154    void Backlight::update_trailmaterial()
155    {
156        if (this->ribbonTrail_ && this->tickcount_ >= 2)
157            this->ribbonTrail_->setMaterialName(this->trailmaterial_);
158    }
159
160    void Backlight::changedVisibility()
161    {
162        SUPER(Backlight, changedVisibility);
163
164        if (this->ribbonTrail_)
165            this->ribbonTrail_->setVisible(this->isVisible());
166    }
167
168    void Backlight::startturnonoff()
169    {
170        FadingBillboard::startturnonoff();
171
172        if (this->ribbonTrail_ && this->isActive() && this->isVisible())
173            this->ribbonTrail_->setVisible(true);
174    }
175
176    void Backlight::stopturnonoff()
177    {
178        this->postprocessingtime_ = max(0.0f, this->lifetime_ - this->turnofftime_);
179
180        FadingBillboard::stopturnonoff();
181
182        if (this->ribbonTrail_)
183            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
184    }
185
186    void Backlight::poststopturnonoff()
187    {
188        FadingBillboard::poststopturnonoff();
189
190        if (this->ribbonTrail_)
191            this->ribbonTrail_->setVisible(false);
192    }
193
194    void Backlight::changedScale()
195    {
196        SUPER(Backlight, changedScale);
197
198        this->update_width();
199        this->update_length();
200    }
201
202    void Backlight::tick(float dt)
203    {
204        if (this->tickcount_ < 2)
205        {
206            ++this->tickcount_;
207            if (this->tickcount_ == 2)
208            {
209                this->changedColour();
210                this->update_width();
211                this->update_lifetime();
212                this->update_length();
213                this->update_maxelements();
214                this->update_trailmaterial();
215                if (this->ribbonTrail_)
216                    this->ribbonTrail_->addNode(this->node_);
217            }
218        }
219
220        SUPER(Backlight, tick, dt);
221
222        if (this->ribbonTrail_ && this->changedirection_ != 0)
223        {
224            // we use alpha_blend, only adjust alpha
225            const ColourValue& colour = this->getColour();
226            this->ribbonTrail_->setInitialColour(0, colour.r, colour.g, colour.b, this->getFadedColour().a);
227        }
228    }
229
230    void Backlight::changedTimeFactor(float factor_new, float factor_old)
231    {
232        this->update_lifetime();
233    }
234}
Note: See TracBrowser for help on using the repository browser.