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

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., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018  */
00019 
00020 #ifndef _STELSKYDRAWER_HPP_
00021 #define _STELSKYDRAWER_HPP_
00022 
00023 #include "StelProjectorType.hpp"
00024 #include "VecMath.hpp"
00025 #include "RefractionExtinction.hpp"
00026 
00027 #include "renderer/StelIndexBuffer.hpp"
00028 #include "renderer/StelVertexBuffer.hpp"
00029 
00030 #include <QObject>
00031 
00032 
00033 class StelToneReproducer;
00034 class StelCore;
00035 
00039 class StelSkyDrawer : public QObject
00040 {
00041     Q_OBJECT
00042 public:
00044     StelSkyDrawer(StelCore* core, class StelRenderer* renderer);
00046     ~StelSkyDrawer();
00047 
00049     void init();
00050 
00053     void update(double deltaTime);
00054 
00056     void preDrawPointSource();
00057 
00059     void postDrawPointSource(StelProjectorP projector);
00060 
00061 
00075     bool pointSourceVisible(StelProjector* projector, const Vec3f& v, const float rcMag[2],
00076                             bool checkInScreen, Vec3f& outWindowCoordinates)
00077     {
00078         // If radius is negative
00079         if (rcMag[0] <= 0.0f){return false;}
00080         return checkInScreen ? projector->projectCheck(v, outWindowCoordinates) 
00081                              : projector->project(v, outWindowCoordinates);
00082     }
00083 
00103     void drawPointSource(const Vec3f& win, const float rcMag[2], unsigned int bV)
00104     {
00105         return drawPointSource(win, rcMag, colorTable[bV]);
00106     }
00107 
00108     void drawPointSource(const Vec3f& win, const float rcMag[2], const Vec3f& bcolor);
00109 
00111     void drawSunCorona(StelProjectorP projector, const Vec3d& v, float radius, float alpha);
00112 
00119     void postDrawSky3dModel(StelProjectorP projector, const Vec3d& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
00120 
00125     bool computeRCMag(float mag, float rcMag[2]) const;
00126 
00132     void reportLuminanceInFov(float lum, bool fastAdaptation=false);
00133 
00135     void preDraw();
00136 
00140     static float surfacebrightnessToLuminance(float sb);
00144     static float luminanceToSurfacebrightness(float lum);
00145 
00147     static inline float indexToBV(unsigned char bV)
00148     {
00149         return (float)bV*(4.f/127.f)-0.5f;
00150     }
00151 
00153     static inline const Vec3f& indexToColor(unsigned char bV)
00154     {
00155         return colorTable[bV];
00156     }
00157 
00158 public slots:
00160     void setRelativeStarScale(double b=1.0) {starRelativeScale=b;}
00162     float getRelativeStarScale() const {return starRelativeScale;}
00163 
00165     void setAbsoluteStarScale(double b=1.0) {starAbsoluteScaleF=b;}
00167     float getAbsoluteStarScale() const {return starAbsoluteScaleF;}
00168 
00170     void setTwinkleAmount(double b) {twinkleAmount=b;}
00172     float getTwinkleAmount() const {return twinkleAmount;}
00173 
00175     void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
00177     bool getFlagTwinkle() const {return flagStarTwinkle;}
00178 
00180     void setDrawStarsAsPoints(bool b) {drawStarsAsPoints=b;}
00182     bool getDrawStarsAsPoints() const {return drawStarsAsPoints;}
00183 
00187     void setBortleScale(int index);
00189     int getBortleScale() const {return bortleScaleIndex;}
00190 
00194     float getLimitMagnitude() const {return limitMagnitude;}
00195 
00199     float getLimitLuminance() const {return limitLuminance;}
00200 
00202     void setFlagLuminanceAdaptation(bool b) {flagLuminanceAdaptation=b;}
00204     bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
00205 
00208     void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
00210     bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
00211 
00213     void setExtinctionCoefficient(double extCoeff) {extinction.setExtinctionCoefficient(extCoeff);}
00215     double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
00217     void setAtmosphereTemperature(double celsius) {refraction.setTemperature(celsius);}
00219     double getAtmosphereTemperature() const {return refraction.getTemperature();}
00221     void setAtmospherePressure(double mbar) {refraction.setPressure(mbar);}
00223     double getAtmospherePressure() const {return refraction.getPressure();}
00224 
00226     const Extinction& getExtinction() const {return extinction;}
00228     const Refraction& getRefraction() const {return refraction;}
00229 
00231     float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
00233     void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
00234     
00235 private:
00236     // Debug
00237     float reverseComputeRCMag(float rmag) const;
00238 
00240     float computeLimitMagnitude() const;
00241 
00243     float computeLimitLuminance() const;
00244 
00246     float getMaxAdaptFov(void) const {return maxAdaptFov;}
00251     void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
00252 
00254     float getMinAdaptFov(void) const {return minAdaptFov;}
00259     void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
00260 
00262     void setInputScale(float in) {inScale = in;}
00264     float getInputScale() const {return inScale;}
00265 
00269     inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
00270 
00274     float pointSourceLuminanceToMag(float lum);
00275 
00279     float pointSourceMagToLnLuminance(float mag) const;
00280 
00283     float findWorldLumForMag(float mag, float targetRadius);
00284 
00285     StelCore* core;
00286 
00288     class StelRenderer* renderer;
00289     StelToneReproducer* eye;
00290 
00291     Extinction extinction;
00292     Refraction refraction;
00293 
00294     float maxAdaptFov, minAdaptFov, lnfovFactor;
00295     bool drawStarsAsPoints;
00296     bool flagStarTwinkle;
00297     float twinkleAmount;
00298 
00301     bool flagHasAtmosphere;
00302 
00303 
00304     float starRelativeScale;
00305     float starAbsoluteScaleF;
00306 
00307     float starLinearScale;  // optimization variable
00308 
00310     float limitMagnitude;
00311 
00313     float limitLuminance;
00314 
00316     class StelTextureNew* texHalo;
00317 
00319     void initColorTableFromConfigFile(class QSettings* conf);
00320 
00322     static Vec3f colorTable[128];
00323 
00325     int bortleScaleIndex;
00326 
00328     float inScale;
00329 
00331     struct ColoredVertex
00332     {
00333         Vec2f position;
00334         Vec3f color;
00335         ColoredVertex(Vec2f position, Vec3f color):position(position), color(color){}
00336 
00337         VERTEX_ATTRIBUTES(Vec2f Position, Vec3f Color);
00338     };
00339 
00341     struct ColoredTexturedVertex
00342     {
00343         Vec2f position;
00344         Vec3f color;
00345         Vec2f texCoord;
00346         ColoredTexturedVertex(Vec2f position, Vec3f color, Vec2f texCoord)
00347             :position(position), color(color), texCoord(texCoord){}
00348 
00349         VERTEX_ATTRIBUTES(Vec2f Position, Vec3f Color, Vec2f TexCoord);
00350     };
00351 
00353     StelVertexBuffer<ColoredVertex>* starPointBuffer;
00354 
00356     StelVertexBuffer<ColoredTexturedVertex>* starSpriteBuffer;
00357 
00359     StelVertexBuffer<ColoredTexturedVertex>* bigHaloBuffer;
00360 
00362     StelVertexBuffer<ColoredTexturedVertex>* sunHaloBuffer;
00363 
00365     StelVertexBuffer<ColoredTexturedVertex>* coronaBuffer;
00366 
00368     bool drawing;
00369 
00371     float maxLum;
00373     float oldLum;
00374 
00376     class StelTextureNew* texBigHalo;
00377     class StelTextureNew* texSunHalo;
00378     class StelTextureNew* texCorona;
00379 
00380     bool flagLuminanceAdaptation;
00381 
00382     float big3dModelHaloRadius;
00383 
00384 
00386     bool statisticsInitialized;
00387 
00389     int bigHaloStatID;
00391     int sunHaloStatID;
00393     int starStatID;
00394 };
00395 
00396 #endif // _STELSKYDRAWER_HPP_
Generated on Thu Jan 31 14:05:40 2013 for Stellarium by  doxygen 1.6.3