xoreos  0.0.5
fadequad.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/util.h"
26 #include "src/common/maths.h"
27 
29 
30 #include "src/events/events.h"
31 
32 namespace Graphics {
33 
34 namespace Aurora {
35 
37  _fadeType(kFadeNone), _r(1.0f), _g(0.0f), _b(0.0f),
38  _opacity(0.0f), _wait(0), _run(0), _start(0) {
39 }
40 
41 void FadeQuad::getColor(float &r, float &g, float &b) const {
42  r = _r;
43  g = _g;
44  b = _b;
45 }
46 
47 void FadeQuad::setColor(float r, float g, float b) {
48  _r = r;
49  _g = g;
50  _b = b;
51 }
52 
53 void FadeQuad::getWaitTime(float &wait) const {
54  wait = _wait / 1000;
55 }
56 
57 void FadeQuad::setWaitTime(float wait) {
58  _wait = wait * 1000;
59 }
60 
61 void FadeQuad::getRunTime(float &run) const {
62  run = _run / 1000;
63 }
64 
65 void FadeQuad::setRunTime(float run) {
66  _run = run * 1000;
67 }
68 
71  _start = EventMan.getTimestamp();
72  show();
73 }
74 
77  _start = EventMan.getTimestamp();
78  show();
79 }
80 
82 }
83 
85  bool isTransparent = _opacity < 1.0f;
86  if (((pass == Graphics::kRenderPassOpaque ) && isTransparent) ||
87  ((pass == Graphics::kRenderPassTransparent) && !isTransparent))
88  return;
89 
90  if (_fadeType == kFadeNone)
91  return;
92 
93  uint32 time = EventMan.getTimestamp() - _start;
94 
95  if (time > _wait) {
96  time = time - _wait;
97 
98  if (_run == 0.0f) {
99  if (_fadeType == kFadeOut)
100  _opacity = 1.0f;
101  if (_fadeType == kFadeIn)
102  _opacity = 0.0f;
103  } else {
104  if (_fadeType == kFadeOut)
105  _opacity = MIN(1.0f, static_cast<float>(time) / _run);
106  if (_fadeType == kFadeIn)
107  _opacity = MAX(0.0f, (_run - static_cast<float>(time)) / _run);
108  }
109  }
110 
111  GLint viewport[4];
112  glGetIntegerv(GL_VIEWPORT, viewport);
113 
114  glColor4f(_r, _g, _b, _opacity);
115 
116  float width, height;
117  width = viewport[2] / 2;
118  height = viewport[3] / 2;
119 
120  glBegin(GL_QUADS);
121  glVertex3f(width, height, -FLT_MAX);
122  glVertex3f(-width, height, -FLT_MAX);
123  glVertex3f(-width, -height, -FLT_MAX);
124  glVertex3f(width, -height, -FLT_MAX);
125  glEnd();
126 
127  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
128 }
129 
130 } // End of namespace Aurora
131 
132 } // End of namespace Graphics
The Quad to handle one color fades.
virtual void show()
Show the object.
Definition: renderable.cpp:114
Only render transparent parts.
Definition: types.h:99
void setWaitTime(float wait)
Set the time to wait until fading begins.
Definition: fadequad.cpp:57
Mathematical helpers.
void getColor(float &r, float &g, float &b) const
Get the current color of the quad.
Definition: fadequad.cpp:41
void getWaitTime(float &wait) const
Get the time to wait until fading begins.
Definition: fadequad.cpp:53
RenderPass
Definition: types.h:97
Utility templates and functions.
The global events manager.
void render(RenderPass pass)
Render the object.
Definition: fadequad.cpp:84
T MIN(T a, T b)
Definition: util.h:70
void fadeIn()
Start a fade in.
Definition: fadequad.cpp:69
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
An object that can be displayed by the graphics manager.
Definition: renderable.h:42
void setColor(float r, float g, float b)
Set the current color of the quad.
Definition: fadequad.cpp:47
uint32_t uint32
Definition: types.h:204
void fadeOut()
Start a fade out.
Definition: fadequad.cpp:75
void getRunTime(float &run) const
Get the time the quad is fading.
Definition: fadequad.cpp:61
#define pass
Definition: fft.cpp:257
T MAX(T a, T b)
Definition: util.h:71
void setRunTime(float run)
Set the time the quad is fading.
Definition: fadequad.cpp:65
void calculateDistance()
Calculate the object&#39;s distance.
Definition: fadequad.cpp:81
#define FLT_MAX
Definition: maths.h:47
Only render opaque parts.
Definition: types.h:98