Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/worldentities/FadingBillboard.cc @ 3176

Last change on this file since 3176 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

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