Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

core/StelSkyDrawer.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2007 Fabien Chereau
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 #ifndef _STELSKYDRAWER_HPP_
00021 #define _STELSKYDRAWER_HPP_
00022 
00023 #include "StelTextureTypes.hpp"
00024 #include "StelProjectorType.hpp"
00025 #include "VecMath.hpp"
00026 
00027 #include <QObject>
00028 
00029 class StelToneReproducer;
00030 class StelCore;
00031 class StelPainter;
00032 
00036 class StelSkyDrawer : public QObject
00037 {
00038     Q_OBJECT
00039 public:
00041     StelSkyDrawer(StelCore* core);
00043     ~StelSkyDrawer();
00044 
00046     void init();
00047 
00050     void update(double deltaTime);
00051 
00054     void preDrawPointSource(StelPainter* p);
00055 
00057     void postDrawPointSource(StelPainter* sPainter);
00058 
00064     bool drawPointSource(StelPainter* sPainter, const Vec3d& v, const float rcMag[2], unsigned int bV, bool checkInScreen=false)
00065         {return drawPointSource(sPainter, v, rcMag, colorTable[bV], checkInScreen);}
00066 
00067     bool drawPointSource(StelPainter* sPainter,const Vec3d& v, const float rcMag[2], const Vec3f& color, bool checkInScreen=false);
00068 
00075     void postDrawSky3dModel(StelPainter* sPainter, const Vec3d& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
00076 
00081     bool computeRCMag(float mag, float rcMag[2]) const;
00082 
00088     void reportLuminanceInFov(float lum, bool fastAdaptation=false);
00089 
00091     void preDraw();
00092 
00096     static float surfacebrightnessToLuminance(float sb);
00100     static float luminanceToSurfacebrightness(float lum);
00101 
00103     static inline float indexToBV(unsigned char bV)
00104     {
00105         return (float)bV*(4.f/127.f)-0.5f;
00106     }
00107 
00109     static inline const Vec3f& indexToColor(unsigned char bV)
00110     {
00111         return colorTable[bV];
00112     }
00113 
00114 public slots:
00116     void setRelativeStarScale(double b=1.0) {starRelativeScale=b;}
00118     float getRelativeStarScale() const {return starRelativeScale;}
00119 
00121     void setAbsoluteStarScale(double b=1.0) {starAbsoluteScaleF=b;}
00123     float getAbsoluteStarScale() const {return starAbsoluteScaleF;}
00124 
00126     void setTwinkleAmount(double b) {twinkleAmount=b;}
00128     float getTwinkleAmount() const {return twinkleAmount;}
00129 
00131     void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
00133     bool getFlagTwinkle() const {return flagStarTwinkle;}
00134 
00136     void setFlagPointStar(bool b) {flagPointStar=b;}
00138     bool getFlagPointStar() const {return flagPointStar;}
00139 
00143     void setBortleScale(int index);
00145     int getBortleScale() const {return bortleScaleIndex;}
00146 
00150     float getLimitMagnitude() const {return limitMagnitude;}
00151 
00155     float getLimitLuminance() const {return limitLuminance;}
00156 
00158     void setFlagLuminanceAdaptation(bool b) {flagLuminanceAdaptation=b;}
00160     bool getFlagLuminanceAdaptation(void) const {return flagLuminanceAdaptation;}
00161 
00162 private:
00163     // Debug
00164     float reverseComputeRCMag(float rmag) const;
00165 
00167     float computeLimitMagnitude() const;
00168 
00170     float computeLimitLuminance() const;
00171 
00173     float getMaxAdaptFov(void) const {return maxAdaptFov;}
00178     void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
00179 
00181     float getMinAdaptFov(void) const {return minAdaptFov;}
00186     void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
00187 
00189     void setInputScale(float in) {inScale = in;}
00191     float getInputScale() const {return inScale;}
00192 
00196     inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
00197 
00201     float pointSourceLuminanceToMag(float lum);
00202 
00206     float pointSourceMagToLnLuminance(float mag) const;
00207 
00210     float findWorldLumForMag(float mag, float targetRadius);
00211 
00212     StelCore* core;
00213     StelToneReproducer* eye;
00214 
00215     float maxAdaptFov, minAdaptFov, lnfovFactor;
00216     bool flagPointStar;
00217     bool flagStarTwinkle;
00218     float twinkleAmount;
00219 
00220     float starRelativeScale;
00221     float starAbsoluteScaleF;
00222 
00223     float starLinearScale;  // optimization variable
00224 
00226     float limitMagnitude;
00227 
00229     float limitLuminance;
00230 
00232     StelTextureSP texHalo;
00233 
00235     void initColorTableFromConfigFile(class QSettings* conf);
00236 
00238     static Vec3f colorTable[128];
00239 
00241     int bortleScaleIndex;
00242 
00244     float inScale;
00245 
00246     // Variables used for GL optimization when displaying point sources
00248     Vec2f* verticesGrid;
00250     Vec3f* colorGrid;
00252     Vec2f* textureGrid;
00254     unsigned int nbPointSources;
00256     unsigned int maxPointSources;
00257 
00259     float maxLum;
00261     float oldLum;
00262 
00264     StelTextureSP texBigHalo;
00265     StelTextureSP texSunHalo;
00266 
00267     bool flagLuminanceAdaptation;
00268 
00269     bool useShader;
00270     class QGLShaderProgram* starsShaderProgram;
00271 };
00272 
00273 #endif // _STELSKYDRAWER_HPP_

Generated on Mon Mar 22 09:55:38 2010 for Stellarium by  doxygen 1.5.5