Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/turret/src/orxonox/graphics/FadingBillboard.cc @ 10121

Last change on this file since 10121 was 5929, checked in by rgrieder, 15 years ago

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

  • Property svn:eol-style set to native
File size: 4.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 "FadingBillboard.h"
30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33
34namespace orxonox
35{
36    CreateFactory(FadingBillboard);
37
38    FadingBillboard::FadingBillboard(BaseObject* creator) : Billboard(creator)
39    {
40        RegisterObject(FadingBillboard);
41
42        this->turnontime_ = 0.0f;
43        this->turnofftime_ = 0.0f;
44        this->postprocessingtime_ = 0.0f;
45        this->changedirection_ = 0;
46
47        this->fadedColour_ = ColourValue::White;
48
49        this->registerVariables();
50    }
51
52    FadingBillboard::~FadingBillboard()
53    {
54    }
55
56    void FadingBillboard::XMLPort(Element& xmlelement, XMLPort::Mode mode)
57    {
58        SUPER(FadingBillboard, XMLPort, xmlelement, mode);
59
60        XMLPortParam(FadingBillboard, "turnontime",  setTurnOnTime,  getTurnOnTime,  xmlelement, mode).defaultValues(0.5f);
61        XMLPortParam(FadingBillboard, "turnofftime", setTurnOffTime, getTurnOffTime, xmlelement, mode).defaultValues(0.5f);
62    }
63
64    void FadingBillboard::registerVariables()
65    {
66        registerVariable(this->turnontime_,  VariableDirection::ToClient);
67        registerVariable(this->turnofftime_, VariableDirection::ToClient);
68    }
69
70    void FadingBillboard::changedColour()
71    {
72        Billboard::changedColour();
73
74        if (this->isActive())
75            this->fadedColour_ = this->getColour();
76        else
77            this->fadedColour_ = ColourValue::ZERO;
78
79        this->getBillboardSet().setColour(this->fadedColour_);
80    }
81
82    void FadingBillboard::changedActivity()
83    {
84        SUPER(FadingBillboard, changedActivity);
85
86        this->startturnonoff();
87    }
88
89    void FadingBillboard::changedVisibility()
90    {
91        SUPER(FadingBillboard, changedVisibility);
92
93        if (this->isVisible() && !this->isActive() && this->changedirection_ == 0)
94        {
95            // Billboard shouldn't be visible
96            this->getBillboardSet().setVisible(false);
97        }
98    }
99
100    void FadingBillboard::startturnonoff()
101    {
102        if (this->isActive())
103        {
104            this->changedirection_ = 1;
105            this->turnonofftimer_.setTimer(this->turnontime_, false, createExecutor(createFunctor(&FadingBillboard::stopturnonoff, this)));
106
107            if (this->isVisible())
108                this->getBillboardSet().setVisible(true);
109        }
110        else
111        {
112            this->changedirection_ = -1;
113            this->turnonofftimer_.setTimer(this->turnofftime_, false, createExecutor(createFunctor(&FadingBillboard::stopturnonoff, this)));
114        }
115    }
116
117    void FadingBillboard::stopturnonoff()
118    {
119        if (this->changedirection_ > 0)
120        {
121            this->fadedColour_ = this->getColour();
122            this->getBillboardSet().setColour(this->fadedColour_);
123        }
124        else if (this->changedirection_ < 0)
125        {
126            this->fadedColour_ = ColourValue::ZERO;
127            this->getBillboardSet().setColour(this->fadedColour_);
128            this->turnonofftimer_.setTimer(this->postprocessingtime_, false, createExecutor(createFunctor(&FadingBillboard::poststopturnonoff, this)));
129        }
130        this->changedirection_ = 0;
131    }
132
133    void FadingBillboard::poststopturnonoff()
134    {
135        this->getBillboardSet().setVisible(false);
136    }
137
138    void FadingBillboard::tick(float dt)
139    {
140        SUPER(FadingBillboard, tick, dt);
141
142        if (this->changedirection_ > 0 && (this->fadedColour_.a < this->getColour().a))
143        {
144            ColourValue colour = this->fadedColour_ + this->getColour() / this->turnontime_ * dt;
145
146            if (colour.a < this->getColour().a)
147            {
148                this->fadedColour_ = colour;
149                this->getBillboardSet().setColour(this->fadedColour_);
150            }
151        }
152        else if (this->changedirection_ < 0 && (this->fadedColour_.a > 0))
153        {
154            ColourValue colour = this->fadedColour_ - this->getColour() / this->turnofftime_ * dt;
155
156            if (colour.a > 0)
157            {
158                this->fadedColour_ = colour;
159                this->getBillboardSet().setColour(this->fadedColour_);
160            }
161        }
162    }
163}
Note: See TracBrowser for help on using the repository browser.