Stellarium 0.12.4
Landscape.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2003 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _LANDSCAPE_HPP_
21 #define _LANDSCAPE_HPP_
22 
23 #include <QMap>
24 #include "VecMath.hpp"
25 #include "StelToneReproducer.hpp"
26 #include "StelProjector.hpp"
27 
28 #include "StelFader.hpp"
29 #include "StelUtils.hpp"
30 #include "renderer/GenericVertexTypes.hpp"
31 #include "renderer/StelIndexBuffer.hpp"
32 #include "renderer/StelVertexBuffer.hpp"
33 #include "StelLocation.hpp"
34 
35 class QSettings;
36 class StelLocation;
37 class StelCore;
38 
42 class Landscape
43 {
44 public:
45  Landscape(float _radius = 2.f);
46  virtual ~Landscape();
47  virtual void load(const QSettings& landscapeIni, const QString& landscapeId) = 0;
48 
53  virtual void draw(StelCore* core, class StelRenderer* renderer) = 0;
54 
55  void update(double deltaTime)
56  {
57  landFader.update((int)(deltaTime*1000));
58  fogFader.update((int)(deltaTime*1000));
59  }
60 
62  void setBrightness(const float b) {skyBrightness = b;}
63 
65  void setFlagShow(const bool b) {landFader=b;}
67  bool getFlagShow() const {return (bool)landFader;}
69  void setFlagShowFog(const bool b) {fogFader=b;}
71  bool getFlagShowFog() const {return (bool)fogFader;}
73  QString getName() const {return name;}
75  QString getAuthorName() const {return author;}
77  QString getDescription() const {return description;}
78 
80  const StelLocation& getLocation() const {return location;}
82  int getDefaultBortleIndex() const {return defaultBortleIndex;}
84  int getDefaultFogSetting() const {return defaultFogSetting;}
86  float getDefaultAtmosphericExtinction() const {return defaultExtinctionCoefficient;}
88  float getDefaultAtmosphericTemperature() const {return defaultTemperature;}
91  float getDefaultAtmosphericPressure() const {return defaultPressure;}
94  float getLandscapeNightBrightness() const {return defaultBrightness;}
95 
97  void setZRotation(float d) {angleRotateZOffset = d;}
98 
99 protected:
103  void loadCommon(const QSettings& landscapeIni, const QString& landscapeId);
104 
109  const QString getTexturePath(const QString& basename, const QString& landscapeId);
110  const float radius;
111  QString name;
112  float skyBrightness;
113  float nightBrightness;
114  float defaultBrightness;
115  bool validLandscape; // was a landscape loaded properly?
116  LinearFader landFader;
117  LinearFader fogFader;
118  QString author;
119  QString description;
120 
121  // Currently, rows and cols do not change after initialization.
122  // If, in future, these values can be modified, cached vertex/index buffers
123  // will have to be regenerated after the change.
124  // GZ patched, these can now be set in landscape.ini:
125  int rows; // horizontal rows
126  int cols; // vertical columns
127  int defaultBortleIndex; // light pollution from landscape.ini, or -1(no change)
128  int defaultFogSetting; // fog flag setting from landscape.ini: -1(no change), 0(off), 1(on)
129  double defaultExtinctionCoefficient; // atmospheric_extinction_coefficient from landscape.ini or -1
130  double defaultTemperature; // atmospheric_temperature from landscape.ini or -1000.0
131  double defaultPressure; // atmospheric_pressure from landscape.ini or -1.0
132 
133  typedef struct
134  {
135  class StelTextureNew* tex;
136  float texCoords[4];
138 
139  StelLocation location;
140  float angleRotateZ;
141  float angleRotateZOffset;
142 };
143 
144 
146 {
147 public:
148  LandscapeOldStyle(float radius = 2.f);
149  virtual ~LandscapeOldStyle();
150  virtual void load(const QSettings& landscapeIni, const QString& landscapeId);
151  virtual void draw(StelCore* core, class StelRenderer* renderer);
152  void create(bool _fullpath, QMap<QString, QString> param);
153 
154 private:
159  void drawFog(StelCore* core, class StelRenderer* renderer);
160 
165  void drawDecor(StelCore* core, class StelRenderer* renderer);
166 
171  void drawGround(StelCore* core, class StelRenderer* renderer);
172 
178  void generateGroundFanDisk(class StelRenderer* renderer);
179 
183  void lazyInitTextures(class StelRenderer* renderer);
184 
190  void generatePrecomputedSides(class StelRenderer* renderer);
191 
192  struct SideTexture
193  {
194  QString path;
195  class StelTextureNew* texture;
196  };
197 
198  SideTexture* sideTexs;
199  bool texturesInitialized;
200  int nbSideTexs;
201  int nbSide;
202  landscapeTexCoord* sides;
203  class StelTextureNew* fogTex;
204  QString fogTexPath;
205  landscapeTexCoord fogTexCoord;
206  class StelTextureNew* groundTex;
207  QString groundTexPath;
208  landscapeTexCoord groundTexCoord;
209  int nbDecorRepeat;
210  float fogAltAngle;
211  float fogAngleShift;
212  float decorAltAngle;
213  float decorAngleShift;
214  float groundAngleShift;
215  float groundAngleRotateZ;
216  int drawGroundFirst;
217  bool tanMode; // Whether the angles should be converted using tan instead of sin
218  bool calibrated; // if true, the documented altitudes are inded correct (the original code is buggy!)
219 
221  struct LOSSide
222  {
226  StelIndexBuffer* indices;
228  class StelTextureNew* tex;
229  };
230 
231  QList<LOSSide> precomputedSides;
232 
236  QMap<int, int> texToSide;
237 
239  StelVertexBuffer<VertexP3T2>* fogCylinderBuffer;
240 
242  float previousFogHeight;
243 
245  StelVertexBuffer<VertexP3T2>* groundFanDisk;
246 
248  StelIndexBuffer* groundFanDiskIndices;
249 };
250 
252 {
253 public:
254  LandscapeFisheye(float radius = 1.f);
255  virtual ~LandscapeFisheye();
256  virtual void load(const QSettings& landscapeIni, const QString& landscapeId);
257  virtual void draw(StelCore* core, class StelRenderer* renderer);
258  void create(const QString name, const QString& maptex, float texturefov, float angleRotateZ);
259 private:
260 
261  class StelTextureNew* mapTex;
262  QString mapTexPath;
263  // Currently, this does not change after initialization.
264  // If, in future, this value can be modified, cached vertex/index buffers
265  // will have to be regenerated after the change.
266  float texFov;
267 
269  class StelGeometrySphere* fisheyeSphere;
270 };
271 
272 
274 {
275 public:
276  LandscapeSpherical(float radius = 1.f);
277  virtual ~LandscapeSpherical();
278  virtual void load(const QSettings& landscapeIni, const QString& landscapeId);
279  virtual void draw(StelCore* core, class StelRenderer* renderer);
280  void create(const QString name, const QString& maptex, float angleRotateZ);
281 private:
282 
283  class StelTextureNew* mapTex;
284  QString mapTexPath;
285 
287  class StelGeometrySphere* landscapeSphere;
288 };
289 
290 #endif // _LANDSCAPE_HPP_