~ubuntu-branches/debian/jessie/stellarium/jessie

« back to all changes in this revision

Viewing changes to src/core/StelSkyDrawer.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2009-03-13 20:07:22 UTC
  • mfrom: (1.1.8 upstream)
  • mto: (11.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090313200722-gbgujsmzsa8a02ty
Import upstream version 0.10.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Stellarium
 
3
 * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
18
 */
 
19
 
 
20
#ifndef _STELSKYDRAWER_HPP_
 
21
#define _STELSKYDRAWER_HPP_
 
22
 
 
23
#include "StelTextureTypes.hpp"
 
24
#include "StelProjectorType.hpp"
 
25
#include "VecMath.hpp"
 
26
 
 
27
#include <QObject>
 
28
 
 
29
class StelToneReproducer;
 
30
class StelCore;
 
31
class StelPainter;
 
32
 
 
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
 
37
{
 
38
        Q_OBJECT
 
39
public:
 
40
        //! Constructor
 
41
    StelSkyDrawer(StelCore* core);
 
42
        //! Destructor
 
43
    ~StelSkyDrawer();
 
44
 
 
45
        //! Init parameters from config file
 
46
        void init();
 
47
        
 
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);
 
51
        
 
52
        //! Get the painter currently used or NULL
 
53
        const StelPainter* getPainter() {return sPainter;}
 
54
        
 
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);
 
58
                
 
59
        //! Finalize the drawing of point sources
 
60
        void postDrawPointSource();
 
61
        
 
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]);}
 
70
        
 
71
        bool drawPointSource(double x, double y, const float rcMag[2], const Vec3f& color);
 
72
        
 
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);
 
82
        
 
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));
 
91
        
 
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;
 
97
        
 
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);
 
104
        
 
105
        //! To be called before the drawing stage starts
 
106
        void preDraw();
 
107
        
 
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);
 
116
        
 
117
        //! Convert quantized B-V index to float B-V
 
118
        static inline float indexToBV(unsigned char bV)
 
119
        {
 
120
                return (float)bV*(4.f/127.f)-0.5f;
 
121
        }
 
122
        
 
123
        //! Convert quantized B-V index to RGB colors
 
124
        static inline const Vec3f& indexToColor(unsigned char bV)
 
125
        {
 
126
                return colorTable[bV];
 
127
        }
 
128
        
 
129
public slots:
 
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;}
 
134
        
 
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;}
 
139
        
 
140
        //! Set source twinkle amount.
 
141
        void setTwinkleAmount(double b) {twinkleAmount=b;}
 
142
        //! Get source twinkle amount.
 
143
        double getTwinkleAmount(void) const {return twinkleAmount;}
 
144
        
 
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;}
 
149
        
 
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;}
 
154
        
 
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;}
 
161
        
 
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;}
 
166
        
 
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;}
 
171
        
 
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;}
 
176
 
 
177
private:
 
178
        // Debug
 
179
        float reverseComputeRCMag(float rmag) const;
 
180
        
 
181
        //! Compute the current limit magnitude by dichotomy
 
182
        float computeLimitMagnitude() const;
 
183
                        
 
184
        //! Compute the current limit luminance by dichotomy
 
185
        float computeLimitLuminance() const;
 
186
        
 
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;}
 
194
        
 
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;}
 
202
        
 
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;}
 
207
        
 
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));}
 
212
        
 
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);
 
217
        
 
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;
 
222
        
 
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);
 
226
                        
 
227
        StelCore* core;
 
228
        StelToneReproducer* eye;
 
229
        
 
230
        float maxAdaptFov, minAdaptFov, lnfovFactor;
 
231
        bool flagPointStar;
 
232
        bool flagStarTwinkle;
 
233
        float twinkleAmount;
 
234
        
 
235
        float starRelativeScale;
 
236
        float starAbsoluteScaleF;
 
237
        
 
238
        float starLinearScale;  // optimization variable
 
239
        
 
240
        //! Current magnitude limit for point sources
 
241
        float limitMagnitude;
 
242
        
 
243
        //! Current magnitude luminance
 
244
        float limitLuminance;
 
245
        
 
246
        //! Little halo texture
 
247
        StelTextureSP texHalo;
 
248
        
 
249
        //! Load B-V conversion parameters from config file
 
250
        void initColorTableFromConfigFile(class QSettings* conf);
 
251
        
 
252
        //! Contains the list of colors matching a given B-V index
 
253
        static Vec3f colorTable[128];
 
254
        
 
255
        //! The current Bortle Scale index
 
256
        int bortleScaleIndex;
 
257
        
 
258
        //! The scaling applied to input luminance before they are converted by the StelToneReproducer
 
259
        double inScale;
 
260
        
 
261
        // Variables used for GL optimization when displaying point sources
 
262
        //! Buffer for storing the vertex array data
 
263
        Vec2f* verticesGrid;
 
264
        //! Buffer for storing the color array data
 
265
        Vec3f* colorGrid;
 
266
        //! Buffer for storing the texture coordinate array data
 
267
        Vec2f* textureGrid;
 
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;
 
272
        
 
273
        //! The maximum transformed luminance to apply at the next update
 
274
        float maxLum;
 
275
        //! The previously used world luminance
 
276
        float oldLum;
 
277
        
 
278
        //! Big halo texture
 
279
        StelTextureSP texBigHalo;
 
280
        StelTextureSP texSunHalo;
 
281
 
 
282
        bool flagLuminanceAdaptation;
 
283
        
 
284
        const StelPainter* sPainter;
 
285
};
 
286
 
 
287
#endif // _STELSKYDRAWER_HPP_