Debian Codegraph @

src/renderer.h

raw symbols SCIP
1 /***************************************************************************
2 renderer.h - description
3 -------------------
4 begin : may 29th, 2003
5 copyright : (C) 2003-2008 by Duong Khang NGUYEN
6 email : neoneurone @ gmail com
7
8 $Id: renderer.h 450 2010-11-21 19:11:43Z neoneurone $
9 ***************************************************************************/
10
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * any later version. *
17 * *
18 ***************************************************************************/
19
20 #ifndef _OPENCITY_RENDERER_H_
21 #define _OPENCITY_RENDERER_H_ 1
22
23 #include "main.h"
24 #include "texture.h"
25
26
27 class Layer;
28 class Map;
29
30
31 //========================================================================
32 /** Deal with the OpenGL library to render game's objects. This class
33 shouldn't play with SDL functions but OpenGL
34 */
35 class Renderer
36 {
37 public:
38 Renderer(
39 const uint cityW,
40 const uint cityL );
41
42 ~Renderer();
43
44
45 void RotateLeft( const uint & factor = 1 );
46 void RotateRight( const uint & factor = 1 );
47 void MoveLeft( const uint & factor = 1 );
48 void MoveRight( const uint & factor = 1 );
49 void MoveUp( const uint & factor = 1 );
50 void MoveDown( const uint & factor = 1 );
51
52
53 //========================================================================
54 /** Reinit the map's position as if the game has just been launched
55 */
56 void Home();
57
58 void ZoomIn( );
59 void ZoomOut( );
60
61 void ToggleTerrain();
62 void ToggleWater();
63 void ToggleStructure();
64 void ToggleGrid();
65 void ToggleCompass();
66 void ToggleProjection();
67 void ToggleWireFrame();
68
69
70 //========================================================================
71 /** Display the splash screen at the specified coordinates
72 */
73 void
74 DisplaySplash(
75 const uint & rcuiX = 0,
76 const uint & rcuiY = 0 );
77
78
79 //========================================================================
80 /** Display the layer and the map to the back buffer. The caller must
81 swap the buffers to show the changes
82 */
83 void
84 Display(
85 const Map* pcMap,
86 const Layer* pcLayer );
87
88
89 void
90 DisplayHighlight(
91 const Map* pcMap,
92 const Layer* pcLayer,
93 const OPENCITY_TOOL_CODE & enumTool );
94
95
96 void
97 DisplayHighlight(
98 const Map* pcMap,
99 const Layer* pcLayer,
100 uint uiW1,
101 uint uiL1,
102 uint uiW2,
103 uint uiL2,
104 const OPENCITY_TOOL_CODE & enumTool );
105
106
107 //========================================================================
108 /** Display the specified graphic code with a bounding rectangle
109 */
110 void DisplayBuildPreview(
111 const uint & uiW,
112 const uint & uiL,
113 const GLubyte & rcubR,
114 const GLubyte & rcubG,
115 const GLubyte & rcubB,
116 const OPENCITY_GRAPHIC_CODE & gcode ) const;
117
118
119 void
120 DisplaySelection(
121 const Map* pcMap,
122 const Layer* pcLayer );
123
124
125 void
126 DisplaySelection(
127 const Map* pcMap,
128 const Layer* pcLayer,
129 const uint & rcuiW1,
130 const uint & rcuiL1,
131 const uint & rcuiW2,
132 const uint & rcuiL2 );
133
134
135 //========================================================================
136 void
137 DisplayText(
138 const uint & rcuiX,
139 const uint & rcuiY,
140 const GLubyte & rcubR,
141 const GLubyte & rcubG,
142 const GLubyte & rcubB,
143 const string & rcText );
144
145
146 const bool
147 GetSelectedWLFrom(
148 const uint & rcuiMouseX,
149 const uint & rcuiMouseY,
150 uint & ruiW,
151 uint & ruiL,
152 const Map* pcMap,
153 const Layer* pcLayer );
154
155
156 const bool
157 GetSelectedWLFrom(
158 const uint & rcuiMouseX,
159 const uint & rcuiMouseY,
160 uint & ruiW,
161 uint & ruiL,
162 const Map* pcMap,
163 const Layer* pcLayer,
164 const uint & rcuiW1,
165 const uint & rcuiL1,
166 const uint & rcuiW2,
167 const uint & rcuiL2 );
168
169
170 //========================================================================
171 /** This method _must_ be called whenever the window's size changes. It
172 calculates the viewport and set the correct internal window's width
173 and height
174 */
175 void SetWinSize(
176 const int & rciWidth,
177 const int & rciHeight );
178
179
180 //========================================================================
181 /** The City class use this to notify the renderer class that the
182 height of the map has changed and the current buffered informations
183 need to be recalculated
184 */
185 bool bHeightChange;
186 bool bMinimapChange;
187
188
189 private:
190 bool _bDisplayTerrain; ///< Display the terrain
191 bool _bDisplayWater; ///< Display the water
192 bool _bDisplayStructure; ///< Display the structures built on the layer
193 bool _bDisplayGrid; ///< Display the terrain grid
194 bool _bDisplayCompass; ///< Display the GUI / compass
195 bool _bWireFrame; ///< Wireframe mode
196
197 OC_BYTE _ubProjectionType;
198 GLfloat _fScaleRatio;
199 GLfloat _fXTransDelta; ///< The delta used for translation in the X direction
200 GLfloat _fZTransDelta;
201
202 // GL display lists
203 GLuint _uiGridList; ///< GL list of the grid
204 GLuint _uiFontBase; ///< The base font list index
205 GLuint _uiTerrainList; ///< GL list of the terrain
206 GLuint _uiWaterList; ///< GL list of the water texture
207
208 // Frequently use textures
209 GLuint _uiMinimapTex; ///< Minimap texture
210 Texture moTextureCloud; ///< Cloud texture
211 Texture moTextureTerrain; ///< Terrain texture
212 Texture moTextureWater; ///< Water texture
213 Texture moTextureSplash; ///< Splash texture
214
215
216 /** Contains the X value for the translation of the layer. It is used by
217 MoveLeft() and MoveRight()
218 */
219 GLdouble _dDeltaX;
220
221 /** Contains the Z value for the translation. It is used by
222 MoveUp() and MoveDown()
223 */
224 GLdouble _dDeltaZ;
225
226 /// used for calculating the rotation of the map
227 GLdouble _dYRotateAngle;
228 GLdouble _dmatrixRotate[16];
229
230 /// The model culling grid
231 bool _bCalculateCulling;
232 bool* _baCulledGrid; // The culled grid has w+1 x l+1 nodes
233 bool* _baCulledModel; // The culled model array has w x l models
234
235 /// used for calculating the viewport & the perspective ratio
236 int _iWinHeight;
237 int _iWinWidth;
238
239 /// The city width & height
240 uint _uiCityWidth;
241 uint _uiCityLength;
242
243
244 /*=====================================================================*/
245 /* PRIVATE METHODS */
246 /*=====================================================================*/
247 /** Draw the terrain as an _unique_ TRIANGLE_STRIP which is known
248 as the fastest primitive in OpenGL. It starts at the north-west and when
249 it reaches the north-east map edge, it starts drawing from the north-east
250 to the north-west eadge. Finally the algorithm draws from the north to
251 the south.
252 */
253 void _DisplayTerrain() const;
254
255
256 //========================================================================
257 /** This method uses the same algorithm as _DisplayTerrain() does to
258 draw the water layer
259 \see _DisplayTerrain()
260 */
261 void _DisplayWater() const;
262
263
264 //========================================================================
265 /** Draw the dotted grid. This method uses OpenGL display list inside.
266 */
267 void _DisplayMapGrid( const Map* pcmap );
268
269
270 void _DisplayCompass() const;
271
272
273 //========================================================================
274 /** Prepare the world before drawing the entire scene
275 */
276 void _PrepareView();
277
278 //========================================================================
279 /** Calulate the culled grid which has city_width + 1 and city_length + 1
280 nodes
281 */
282 void _CalculateCulledGrid(
283 uint w1, uint l1,
284 uint w2, uint l2,
285 bool init = false);
286
287 //========================================================================
288 /** Calulate the culled (selected) models from the culled grid.
289 The culled models are drawn, the others are not drawn.
290 */
291 void _CalculateCulledModel( const Layer* pcLayer );
292
293
294 //========================================================================
295 /** Set the LOD according to the scale ratio
296 */
297 void _SetLOD() const;
298 };
299
300 #endif
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328