3
* Copyright (C) 2007 Fabien Chereau
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#ifndef _STELSKYDRAWER_HPP_
21
#define _STELSKYDRAWER_HPP_
23
#include "StelTextureTypes.hpp"
24
#include "StelProjectorType.hpp"
25
#include "VecMath.hpp"
29
class StelToneReproducer;
33
//! @class StelSkyDrawer
34
//! Provide a set of methods used to draw sky objects taking into account
35
//! eyes adaptation, zoom level and instrument model
36
class StelSkyDrawer : public QObject
41
StelSkyDrawer(StelCore* core);
45
//! Init parameters from config file
48
//! Update with respect to the time and StelProjector/StelToneReproducer state
49
//! @param deltaTime the time increment in second since last call.
50
void update(double deltaTime);
52
//! Get the painter currently used or NULL
53
const StelPainter* getPainter() {return sPainter;}
55
//! Set the proper openGL state before making calls to drawPointSource
56
//! @param p a pointer to a valid instance of a Painter. The instance must be valid until postDrawPointSource() is called
57
void preDrawPointSource(const StelPainter* p);
59
//! Finalize the drawing of point sources
60
void postDrawPointSource();
62
//! Draw a point source halo.
63
//! @param x the x position of the object on the screen
64
//! @param y the y position of the object on the screen
65
//! @param rcMag the radius and luminance of the source as computed by computeRCMag()
66
//! @param bV the source B-V index
67
//! @return true if the source was actually visible and drawn
68
bool drawPointSource(double x, double y, const float rcMag[2], unsigned int bV)
69
{return drawPointSource(x, y, rcMag, colorTable[bV]);}
71
bool drawPointSource(double x, double y, const float rcMag[2], const Vec3f& color);
73
//! Draw a disk source halo. The real surface brightness is smaller as if it were a
74
//! point source because the flux is spread on the disk area
75
//! @param x the x position of the disk center in pixel
76
//! @param y the y position of the disk centre in pixel
77
//! @param r radius of the disk in pixel
78
//! @param mag the source integrated magnitude
79
//! @param color the source RGB color
80
//! @return true if the source was actually visible and drawn
81
bool drawDiskSource(double x, double y, double r, float mag, const Vec3f& color);
83
//! Terminate drawing of a 3D model, draw the halo
84
//! @param x the x position of the object centroid in pixel
85
//! @param y the y position of the object centroid in pixel
86
//! @param illuminatedArea the illuminated area in arcmin^2
87
//! @param mag the source integrated magnitude
88
//! @param p the StelPainter instance to use for this drawing operation
89
//! @param color the object halo RGB color
90
void postDrawSky3dModel(double x, double y, double illuminatedArea, float mag, const StelPainter* p, const Vec3f& color = Vec3f(1.f,1.f,1.f));
92
//! Compute RMag and CMag from magnitude.
93
//! @param mag the object integrated V magnitude
94
//! @param rcMag array of 2 floats containing the radius and luminance
95
//! @return false if the object is too faint to be displayed
96
bool computeRCMag(float mag, float rcMag[2]) const;
98
//! Report that an object of luminance lum with an on-screen area of area pixels is currently displayed
99
//! This information is used to determine the world adaptation luminance
100
//! This method should be called during the update operations of the main loop
101
//! @param lum luminance in cd/m^2
102
//! @param fastAdaptation adapt the eye quickly if true, other wise use a smooth adaptation
103
void reportLuminanceInFov(double lum, bool fastAdaptation=false);
105
//! To be called before the drawing stage starts
108
//! Compute the luminance for an extended source with the given surface brightness
109
//! @param sb surface brightness in V magnitude/arcmin^2
110
//! @return the luminance in cd/m^2
111
static float surfacebrightnessToLuminance(float sb);
112
//! Compute the surface brightness from the luminance of an extended source
113
//! @param lum luminance in cd/m^2
114
//! @return surface brightness in V magnitude/arcmin^2
115
static float luminanceToSurfacebrightness(float lum);
117
//! Convert quantized B-V index to float B-V
118
static inline float indexToBV(unsigned char bV)
120
return (float)bV*(4.f/127.f)-0.5f;
123
//! Convert quantized B-V index to RGB colors
124
static inline const Vec3f& indexToColor(unsigned char bV)
126
return colorTable[bV];
130
//! Set the way brighter stars will look bigger as the fainter ones
131
void setRelativeStarScale(double b=1.0) {starRelativeScale=b;}
132
//! Get the way brighter stars will look bigger as the fainter ones
133
double getRelativeStarScale(void) const {return starRelativeScale;}
135
//! Set the absolute star brightness scale
136
void setAbsoluteStarScale(double b=1.0) {starAbsoluteScaleF=b;}
137
//! Get the absolute star brightness scale
138
double getAbsoluteStarScale(void) const {return starAbsoluteScaleF;}
140
//! Set source twinkle amount.
141
void setTwinkleAmount(double b) {twinkleAmount=b;}
142
//! Get source twinkle amount.
143
double getTwinkleAmount(void) const {return twinkleAmount;}
145
//! Set flag for source twinkling.
146
void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
147
//! Get flag for source twinkling.
148
bool getFlagTwinkle(void) const {return flagStarTwinkle;}
150
//! Set flag for displaying point sources as GLpoints (faster on some hardware but not so nice).
151
void setFlagPointStar(bool b) {flagPointStar=b;}
152
//! Get flag for displaying point sources as GLpoints (faster on some hardware but not so nice).
153
bool getFlagPointStar(void) const {return flagPointStar;}
155
//! Set the parameters so that the stars disapear at about the limit given by the bortle scale
156
//! The limit is valid only at a given zoom level (around 60 deg)
157
//! See http://en.wikipedia.org/wiki/Bortle_Dark-Sky_Scale
158
void setBortleScale(int index);
159
//! Get the current Bortle scale index
160
int getBortleScale() const {return bortleScaleIndex;}
162
//! Get the magnitude of the currently faintest visible point source
163
//! It depends on the zoom level, on the eye adapation and on the point source rendering parameters
164
//! @return the limit V mag at which a point source will be displayed
165
float getLimitMagnitude() const {return limitMagnitude;}
167
//! Get the luminance of the faintest visible object (e.g. RGB<0.05)
168
//! It depends on the zoom level, on the eye adapation and on the point source rendering parameters
169
//! @return the limit V luminance at which an object will be visible
170
float getLimitLuminance() const {return limitLuminance;}
172
//! Set the value of the eye adaptation flag
173
void setFlagLuminanceAdaptation(bool b) {flagLuminanceAdaptation=b;}
174
//! Get the current value of eye adaptation flag
175
bool getFlagLuminanceAdaptation(void) const {return flagLuminanceAdaptation;}
179
float reverseComputeRCMag(float rmag) const;
181
//! Compute the current limit magnitude by dichotomy
182
float computeLimitMagnitude() const;
184
//! Compute the current limit luminance by dichotomy
185
float computeLimitLuminance() const;
187
//! Get StelSkyDrawer maximum FOV.
188
float getMaxAdaptFov(void) const {return maxAdaptFov;}
189
//! Set StelSkyDrawer maximum FOV.
190
//! Usually stars/planet halos are drawn fainter when FOV gets larger,
191
//! but when FOV gets larger than this value, the stars do not become
192
//! fainter any more. Must be >= 60.0.
193
void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
195
//! Get StelSkyDrawer minimum FOV.
196
float getMinAdaptFov(void) const {return minAdaptFov;}
197
//! Set StelSkyDrawer minimum FOV.
198
//! Usually stars/planet halos are drawn brighter when FOV gets smaller.
199
//! But when FOV gets smaller than this value, the stars do not become
200
//! brighter any more. Must be <= 60.0.
201
void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
203
//! Set the scaling applied to input luminance before they are converted by the StelToneReproducer
204
void setInputScale(double in) {inScale = in;}
205
//! Get the scaling applied to input luminance before they are converted by the StelToneReproducer
206
float getInputScale() const {return inScale;}
208
//! Compute the luminance for a point source with the given mag for the current FOV
209
//! @param mag V magnitude of the point source
210
//! @return the luminance in log(cd/m^2)
211
inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
213
//! Compute the V magnitude for a point source with the given luminance for the current FOV
214
//! @param lum the luminance in cd/m^2
215
//! @return V magnitude of the point source
216
float pointSourceLuminanceToMag(float lum);
218
//! Compute the log of the luminance for a point source with the given mag for the current FOV
219
//! @param mag V magnitude of the point source
220
//! @return the luminance in cd/m^2
221
float pointSourceMagToLnLuminance(float mag) const;
223
//! Find the world adaptation luminance to use so that a point source of magnitude mag
224
//! is displayed with a halo of size targetRadius
225
float findWorldLumForMag(float mag, float targetRadius);
228
StelToneReproducer* eye;
230
float maxAdaptFov, minAdaptFov, lnfovFactor;
232
bool flagStarTwinkle;
235
float starRelativeScale;
236
float starAbsoluteScaleF;
238
float starLinearScale; // optimization variable
240
//! Current magnitude limit for point sources
241
float limitMagnitude;
243
//! Current magnitude luminance
244
float limitLuminance;
246
//! Little halo texture
247
StelTextureSP texHalo;
249
//! Load B-V conversion parameters from config file
250
void initColorTableFromConfigFile(class QSettings* conf);
252
//! Contains the list of colors matching a given B-V index
253
static Vec3f colorTable[128];
255
//! The current Bortle Scale index
256
int bortleScaleIndex;
258
//! The scaling applied to input luminance before they are converted by the StelToneReproducer
261
// Variables used for GL optimization when displaying point sources
262
//! Buffer for storing the vertex array data
264
//! Buffer for storing the color array data
266
//! Buffer for storing the texture coordinate array data
268
//! Current number of sources stored in the buffers (still to display)
269
unsigned int nbPointSources;
270
//! Maximum number of sources which can be stored in the buffers
271
unsigned int maxPointSources;
273
//! The maximum transformed luminance to apply at the next update
275
//! The previously used world luminance
279
StelTextureSP texBigHalo;
280
StelTextureSP texSunHalo;
282
bool flagLuminanceAdaptation;
284
const StelPainter* sPainter;
287
#endif // _STELSKYDRAWER_HPP_