Stellarium 0.12.3
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;}
92 
94  void setZRotation(float d) {angleRotateZOffset = d;}
95 
96 protected:
100  void loadCommon(const QSettings& landscapeIni, const QString& landscapeId);
101 
106  const QString getTexturePath(const QString& basename, const QString& landscapeId);
107  const float radius;
108  QString name;
109  float skyBrightness;
110  float nightBrightness;
111  bool validLandscape; // was a landscape loaded properly?
112  LinearFader landFader;
113  LinearFader fogFader;
114  QString author;
115  QString description;
116 
117  // Currently, rows and cols do not change after initialization.
118  // If, in future, these values can be modified, cached vertex/index buffers
119  // will have to be regenerated after the change.
120  // GZ patched, these can now be set in landscape.ini:
121  int rows; // horizontal rows
122  int cols; // vertical columns
123  int defaultBortleIndex; // light pollution from landscape.ini, or -1(no change)
124  int defaultFogSetting; // fog flag setting from landscape.ini: -1(no change), 0(off), 1(on)
125  double defaultExtinctionCoefficient; // atmospheric_extinction_coefficient from landscape.ini or -1
126  double defaultTemperature; // atmospheric_temperature from landscape.ini or -1000.0
127  double defaultPressure; // atmospheric_pressure from landscape.ini or -1.0
128 
129  typedef struct
130  {
131  class StelTextureNew* tex;
132  float texCoords[4];
134 
135  StelLocation location;
136  float angleRotateZ;
137  float angleRotateZOffset;
138 };
139 
140 
142 {
143 public:
144  LandscapeOldStyle(float radius = 2.f);
145  virtual ~LandscapeOldStyle();
146  virtual void load(const QSettings& landscapeIni, const QString& landscapeId);
147  virtual void draw(StelCore* core, class StelRenderer* renderer);
148  void create(bool _fullpath, QMap<QString, QString> param);
149 
150 private:
155  void drawFog(StelCore* core, class StelRenderer* renderer);
156 
161  void drawDecor(StelCore* core, class StelRenderer* renderer);
162 
167  void drawGround(StelCore* core, class StelRenderer* renderer);
168 
174  void generateGroundFanDisk(class StelRenderer* renderer);
175 
179  void lazyInitTextures(class StelRenderer* renderer);
180 
186  void generatePrecomputedSides(class StelRenderer* renderer);
187 
188  struct SideTexture
189  {
190  QString path;
191  class StelTextureNew* texture;
192  };
193 
194  SideTexture* sideTexs;
195  bool texturesInitialized;
196  int nbSideTexs;
197  int nbSide;
198  landscapeTexCoord* sides;
199  class StelTextureNew* fogTex;
200  QString fogTexPath;
201  landscapeTexCoord fogTexCoord;
202  class StelTextureNew* groundTex;
203  QString groundTexPath;
204  landscapeTexCoord groundTexCoord;
205  int nbDecorRepeat;
206  float fogAltAngle;
207  float fogAngleShift;
208  float decorAltAngle;
209  float decorAngleShift;
210  float groundAngleShift;
211  float groundAngleRotateZ;
212  int drawGroundFirst;
213  bool tanMode; // Whether the angles should be converted using tan instead of sin
214  bool calibrated; // if true, the documented altitudes are inded correct (the original code is buggy!)
215 
217  struct LOSSide
218  {
222  StelIndexBuffer* indices;
224  class StelTextureNew* tex;
225  };
226 
227  QList<LOSSide> precomputedSides;
228 
232  QMap<int, int> texToSide;
233 
235  StelVertexBuffer<VertexP3T2>* fogCylinderBuffer;
236 
238  float previousFogHeight;
239 
241  StelVertexBuffer<VertexP3T2>* groundFanDisk;
242 
244  StelIndexBuffer* groundFanDiskIndices;
245 };
246 
248 {
249 public:
250  LandscapeFisheye(float radius = 1.f);
251  virtual ~LandscapeFisheye();
252  virtual void load(const QSettings& landscapeIni, const QString& landscapeId);
253  virtual void draw(StelCore* core, class StelRenderer* renderer);
254  void create(const QString name, const QString& maptex, float texturefov, float angleRotateZ);
255 private:
256 
257  class StelTextureNew* mapTex;
258  QString mapTexPath;
259  // Currently, this does not change after initialization.
260  // If, in future, this value can be modified, cached vertex/index buffers
261  // will have to be regenerated after the change.
262  float texFov;
263 
265  class StelGeometrySphere* fisheyeSphere;
266 };
267 
268 
270 {
271 public:
272  LandscapeSpherical(float radius = 1.f);
273  virtual ~LandscapeSpherical();
274  virtual void load(const QSettings& landscapeIni, const QString& landscapeId);
275  virtual void draw(StelCore* core, class StelRenderer* renderer);
276  void create(const QString name, const QString& maptex, float angleRotateZ);
277 private:
278 
279  class StelTextureNew* mapTex;
280  QString mapTexPath;
281 
283  class StelGeometrySphere* landscapeSphere;
284 };
285 
286 #endif // _LANDSCAPE_HPP_