xoreos  0.0.5
newgamefog.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 <cstdlib>
26 
27 #include "glm/gtc/matrix_transform.hpp"
28 
29 #include "src/common/scopedptr.h"
30 #include "src/common/maths.h"
31 #include "src/common/readstream.h"
32 
33 #include "src/events/events.h"
34 
36 
38 
40 
41 namespace Engines {
42 
43 namespace NWN {
44 
46 private:
50 
51  float _curZoom;
52 
53  float _curFade;
54  float _fadeStep;
55 
56  float _rotateSpeed;
57 
58 public:
59  NewGameFog(const Common::UString &name) :
61 
62  _scale[0] = _scale[1] = 10.0f;
63 
64  _startTime = EventMan.getTimestamp();
66  _timeRotate = _startTime - (std::rand() % 10000);
67 
68  _curZoom = 0.8f;
69 
70  _curFade = (std::rand() % 1000) / 1000.0f;
71  _fadeStep = 0.001f;
72 
73  _rotateSpeed = 40 + ((std::rand() % 3000) / 100.0f);
74  }
75 
77  }
78 
81  return;
82 
83  uint32 curTime = EventMan.getTimestamp();
84 
85  uint32 diffRotate = curTime - _timeRotate;
86  glRotatef(diffRotate / _rotateSpeed, 0.0f, 0.0f, -1.0f);
87 
88  glScalef(_curZoom, _curZoom, 1.0f);
89  _curZoom += ((curTime - _lastTime) / 3000.0f) * _curZoom;
90 
91  if (_curFade >= 1.0f)
92  _fadeStep = -0.0005f - (std::rand() % 100) / 100000.0f;
93  if (_curFade <= 0.0f)
94  _fadeStep = 0.0005f + (std::rand() % 100) / 100000.0f;
95 
96  _curFade += (curTime - _lastTime) * _fadeStep;
97  if (_curFade < 0.0f)
98  _curZoom = 0.8f;
99 
100  glColor4f(1.0f, 1.0f, 1.0f, _curFade);
101 
103 
104  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
105 
106  _lastTime = curTime;
107  }
108 
109  void renderImmediate(const glm::mat4 &parentTransform) {
110  uint32 curTime = EventMan.getTimestamp();
111 
112  uint32 diffRotate = curTime - _timeRotate;
113  glm::mat4 transform = glm::mat4();
114  transform = glm::rotate(transform, Common::deg2rad(diffRotate / _rotateSpeed), glm::vec3(0.0f, 0.0f, -1.0f));
115  transform = glm::scale(transform, glm::vec3(_curZoom * 10.0f, _curZoom * 10.0f, 1.0f));
116 
117  transform = glm::translate(transform, glm::vec3(_position[0], _position[1], _position[2]));
118  if (_orientation[0] != 0.0f ||
119  _orientation[1] != 0.0f ||
120  _orientation[2] != 0.0f) {
121  transform = glm::rotate(transform, _orientation[3], glm::vec3(_orientation[0], _orientation[1], _orientation[2]));
122  }
123  transform = glm::scale(transform, glm::vec3(_scale[0], _scale[1], _scale[2]));
124  _curZoom += ((curTime - _lastTime) / 3000.0f) * _curZoom;
125 
126  if (_curFade >= 1.0f)
127  _fadeStep = -0.0005f - (std::rand() % 100) / 100000.0f;
128  if (_curFade <= 0.0f)
129  _fadeStep = 0.0005f + (std::rand() % 100) / 100000.0f;
130 
131  _curFade += (curTime - _lastTime) * _fadeStep;
132  if (_curFade < 0.0f)
133  _curZoom = 0.8f;
134 
135  for (NodeList::iterator n = _currentState->rootNodes.begin();
136  n != _currentState->rootNodes.end(); ++n) {
137  (*n)->setAlpha(_curFade);
138  }
139 
141  _absolutePosition = transform;
142 
143  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
144 
145  _lastTime = curTime;
146  }
147 };
148 
149 
152 
153  model->setPosition(0.0f, 0.0f, 100.0f);
154 
155  return model.release();
156 }
157 
158 
160  _fogs.reserve(count);
161 
162  for (size_t i = 0; i < count; i++)
163  _fogs.push_back(createNewGameFog());
164 }
165 
167  hide();
168 }
169 
171  for (Common::PtrVector<Graphics::Aurora::Model>::iterator f = _fogs.begin(); f != _fogs.end(); ++f)
172  (*f)->show();
173 }
174 
176  for (Common::PtrVector<Graphics::Aurora::Model>::iterator f = _fogs.begin(); f != _fogs.end(); ++f)
177  (*f)->hide();
178 }
179 
180 
181 } // End of namespace NWN
182 
183 } // End of namespace Engines
Model_NWN(const Common::UString &name, ModelType type=kModelTypeObject, const Common::UString &texture="", ModelCache *modelCache=0)
Definition: model_nwn.cpp:184
Only render transparent parts.
Definition: types.h:99
An element of the front GUI.
Definition: types.h:53
A class holding an UTF-8 string.
Definition: ustring.h:48
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
Definition: scopedptr.h:103
The fog behind the new game dialogs.
A 3D model in the NWN MDL format.
Definition: model_nwn.h:44
Mathematical helpers.
NewGameFog(const Common::UString &name)
Definition: newgamefog.cpp:59
NodeList rootNodes
The nodes in the state without a parent.
Definition: model.h:209
State * _currentState
The current state.
Definition: model.h:227
void renderImmediate(const glm::mat4 &parentTransform)
For shader based systems, don&#39;t sort anything, render this right_now.
Definition: newgamefog.cpp:109
void render(Graphics::RenderPass pass)
Render the object.
Definition: newgamefog.cpp:79
A simple scoped smart pointer template.
A vector of pointer to objects, with automatic deletion.
Definition: ptrvector.h:44
RenderPass
Definition: types.h:97
float _position[3]
Model&#39;s position.
Definition: model.h:239
The global events manager.
Loading MDL files found in Neverwinter Nights.
Basic reading stream interfaces.
float _scale[3]
Model&#39;s scale.
Definition: model.h:237
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
void render(RenderPass pass)
Render the object.
Definition: model.cpp:632
float _orientation[4]
Model&#39;s orientation.
Definition: model.h:238
uint32_t uint32
Definition: types.h:204
glm::mat4 _absolutePosition
Definition: model.h:243
#define pass
Definition: fft.cpp:257
Common::PtrVector< Graphics::Aurora::Model > _fogs
Definition: newgamefog.h:48
static float deg2rad(float deg)
Definition: maths.h:97
static Graphics::Aurora::Model * createNewGameFog()
Definition: newgamefog.cpp:150
void renderImmediate(const glm::mat4 &parentTransform)
For shader based systems, don&#39;t sort anything, render this right_now.
Definition: model.cpp:666
Generic Aurora engines model functions.