Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2909 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

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