Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Sky.h

Go to the documentation of this file.
00001 /*
00002  * Sky.h
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00045 #ifndef SKY_H
00046 #define SKY_H
00047 
00048 #include "FlyLegacy.h"
00049 #include "Ephemeris.h"
00050 #include "Ini.h"
00051 #include "Utility.h"
00052 #include <string>
00053 #include <vector>
00054 #include <map>
00055 
00056 
00057 //
00058 // CSkyLight class represents aspects of the sun and moon positions as they
00059 //   relate to sky and terrain lighting effects.  This class is derived from
00060 //   the FlightGear class fgLIGHT by Curt Olsen
00061 //
00062 class CSkyLight {
00063 public:
00064   // Constructor
00065   CSkyLight (void);
00066 
00067   // CSkyLight methods
00068   void Init (void);
00069   void Update (void);
00070 
00071 public:
00072   /*
00073    * Sun parameters
00074    */
00075 
00076   // Geocentric latitude/longitude
00077     double sun_gc_lon, sun_gc_lat;
00078 
00079   // Cartesian coordinates
00080   sgVec3  sunpos;
00081 
00082   // Sun angle, the angle between the sun and local horizontal (radians)
00083     double sun_angle;
00084 
00085   // Sun rotation, the angle between the sun's azimuth angle and due south
00086     double sun_rotation;
00087 
00088   /*
00089    * Moon parameters...TBD
00090    */
00091 
00092   
00093   /*
00094    * Derived lighting values
00095    */
00096 
00097   // Fog colour
00098   GLfloat fog_colour[4];
00099 
00100   // Clear sky colour
00101   GLfloat sky_colour[4];
00102 };
00103 
00104 
00105 //
00106 // CSkyDomeImage class implements the visual model for the background sky colour.
00107 //   The dome consists of a central vertex at the zenith and three concentric rings
00108 //   of vertices progressively down towards the horizon.  Applications can specify
00109 //   independent colours for the zenith, and for any azimuth point on the concentric
00110 //   rings.
00111 //
00112 
00113 typedef struct {
00114   float A, B, C, D, E;
00115 } SPerezCoefficients;
00116 
00117 typedef struct {
00118   float A[2], B[2], C[2], D[2], E[2];
00119 } SCoefficientParameters;
00120 
00121 typedef struct {
00122   float   A, B, C, D;
00123 } SLuminanceZenith;
00124 
00125 typedef struct {
00126   float   t2[4];
00127   float   t1[4];
00128   float   t0[4];
00129 } SChromaZenith;
00130 
00131 typedef struct {
00132   char          name[64];
00133   SCoefficientParameters  Y_curve;
00134   SCoefficientParameters  x_curve;
00135   SCoefficientParameters  y_curve;
00136   SLuminanceZenith        Y_zenith;
00137   SChromaZenith           x_zenith;
00138   SChromaZenith           y_zenith;
00139 } SPerezParameters;
00140 
00141 
00142 #define SKYDOME_SLICES  64
00143 #define SKYDOME_STACKS  32
00144 
00145 class CSkyDomeImage {
00146 public:
00147   CSkyDomeImage (double distance);
00148   ~CSkyDomeImage (void);
00149 
00150   // CSkyDome methods
00151   ssgEntity*    GetSSGEntity (void);
00152   void      Repaint (double solTheta, double solPhi);
00153   void      Reposition (double solPhi);
00154   void      Print (FILE *f);
00155 
00156 protected:
00157 //  void      InitPerezParameters (SPerezParameters* p,
00158 //                     CIniFile *inisky,
00159 //                     const char* name);
00160 protected:
00161   // Top-level SSG entities
00162   ssgTransform    *top;
00163 
00164   // Raw vertices
00165   sgVec3 vtx_zenith;
00166   sgVec3 vtx_ring[SKYDOME_STACKS][SKYDOME_SLICES];
00167 
00168   // Sky dome colour buffer for use in Repaint() method
00169   sgVec3 rgb_zenith;
00170   sgVec3 rgb_dome[SKYDOME_STACKS][SKYDOME_SLICES];
00171 
00172   // Parameters for sky dome shading with Perez functions
00173   double                                  prevTheta;      // Solar zenith angle at last repaint
00174   SPerezParameters                        *perezCurrent;  // Current Perez parameter set
00175   std::map<std::string,SPerezParameters*> perez;          // Map of Perez parameter sets
00176 };
00177 
00178 
00179 //
00180 // The following enum represents the various phases of darkness.
00181 //
00182 typedef enum {
00183   PHASE_INVALID     = -1,
00184   PHASE_DEEP_NIGHT    = 0,
00185   PHASE_NIGHT       = 1,
00186   PHASE_LATE_DUSK     = 2,
00187   PHASE_DUSK        = 3,
00188   PHASE_EARLY_DUSK    = 4,
00189   PHASE_LATE_TWILIGHT   = 5,
00190   PHASE_EARLY_TWILIGHT  = 6,
00191   PHASE_DAYLIGHT      = 7
00192 } EDarkPhase;
00193 
00194 
00195 typedef struct {
00196   char  name[64]; // Common name (optional)
00197   double  ra, dec;  // Celestial coordinates
00198   float mv;     // Visual magnitude
00199   float bv;     // B-V colour index
00200   int   hr;     // HR number, used to construct constellation figures
00201 } SStarData;
00202 
00203 typedef struct {
00204   char  name[64];     // Constellation name (abbreviation)
00205   int   star1, star2; // Line endpoints, indices into stars vector
00206 } SConstellationLine;
00207 
00208 
00209 //
00210 // CStarImages class implements the visual model for all star-like objects
00211 //   (including stars and planets) in the sky.  These are rendered as
00212 //   single points (or small clusters of points for very bright objects)
00213 //   with accurate colours.
00214 //
00215 class CStarImages {
00216 public:
00217   CStarImages (double distance);
00218   ~CStarImages (void);
00219 
00220   // CStarImages methods
00221   ssgEntity*    GetSSGEntity (void);
00222   void      Repaint (float limit, float factor);
00223   void      Reposition (sgVec3 pos, double lon, double lat, double lst);
00224 
00225 protected:
00226   void      LoadFlyDatabase (const char* dbFilename);
00227   void      LoadBSCDatabase (const char* bscFilename, float limit);
00228   void      LoadConstellations (const char* txtFilename);
00229   int       FindStarByHR (int hr);
00230 
00231 protected:
00232   std::vector<SStarData*>          stars;          
00233   std::vector<SConstellationLine*> constellations; 
00234 
00235   // SSG tree
00236   ssgTransform  *top;
00237 
00238   ssgLeaf     *stars_leaf;
00239   ssgVertexArray  *stars_va;
00240   ssgColourArray  *stars_rgba;
00241 
00242   ssgLeaf     *constellations_leaf;
00243   ssgVertexArray  *constellations_va;
00244   ssgColourArray  *constellations_rgba;
00245 };
00246 
00247 
00249 
00251 
00253 
00255 
00257 
00259 
00260 //
00261 // CMoonImage class implements the visual model for the moon
00262 //
00263 class CMoonImage {
00264 public:
00265   CMoonImage (double size);
00266   ~CMoonImage (void);
00267 
00268   // CMoonImage methods
00269   ssgEntity*    GetSSGEntity (void);
00270   void      Repaint (double angle, float age);
00271   void      Reposition (sgVec3 p, double theta, double lst, double lat,
00272                 double ra, double dec, double spin,
00273                 double distance);
00274 
00275 protected:
00276   // SSG tree
00277   ssgTransform  *top;
00278   ssgVtxTable   *orb;
00279 
00280   // Moon phase textures
00281   CRawImage*    texlist[17];
00282   int       phase;
00283 };
00284 
00285 
00286 //
00287 // CSolImage class implements the visual model for Sol (our sun)
00288 //
00289 class CSolImage {
00290 public:
00291   CSolImage (double size);
00292   ~CSolImage (void);
00293 
00294   // CSolImage methods
00295   GLuint  GetSunTexture (const char* filename, int w);
00296   void    Repaint (double angle);
00297   void    Reposition (sgVec3 pos, double lst, double lat, double ra, double dec, double distance);
00298   ssgEntity*  GetSSGEntity (void);
00299 
00300 protected:
00301   // SSG tree
00302   ssgTransform    *top;
00303   ssgColourArray  *rgba;
00304   ssgLeaf         *orb;
00305   ssgLeaf         *halo;
00306 //  ssgTransform  *orb_transform;
00307 //  ssgState    *orb_state;
00308 
00309 //  ssgEntity   *orb;
00310 //  ssgColourArray  *rgba;
00311 
00312   // Texture layers
00313 };
00314 
00315 
00316 //
00317 // CMercuryImage class implements the visual model for the planet Mercury
00318 //
00319 class CMercuryImage {
00320 public:
00321   CMercuryImage (void);
00322 
00323   // CMercuryImage methods
00324   void    Repaint (float mv, float limit, float factor);
00325   void    Reposition (sgVec3 pos, double lst, double lat,
00326                         double ra, double dec, double distance);
00327   ssgEntity*  GetSSGEntity (void);
00328 
00329 protected:
00330   // SSG tree
00331   ssgTransform  *top;
00332 
00333   ssgColourArray  *rgba;
00334   ssgVertexArray  *va;
00335 };
00336 
00337 
00338 //
00339 // CVenusImage class implements the visual model for the planet Venus
00340 //
00341 class CVenusImage {
00342 public:
00343   CVenusImage (void);
00344 
00345   // CVenusImage methods
00346   void    Repaint (float mv, float limit, float factor);
00347   void    Reposition (sgVec3 pos, double lst, double lat,
00348                         double ra, double dec, double distance);
00349   ssgEntity*  GetSSGEntity (void);
00350 
00351 protected:
00352   // SSG tree
00353   ssgTransform  *top;
00354 
00355   ssgColourArray  *rgba;
00356   ssgVertexArray  *va;
00357 };
00358 
00359 
00360 //
00361 // CMarsImage class implements the visual model for the planet Mars
00362 //
00363 class CMarsImage {
00364 public:
00365   CMarsImage (void);
00366 
00367   // CMarsImage methods
00368   void    Repaint (float mv, float limit, float factor);
00369   void    Reposition (sgVec3 pos, double lst, double lat,
00370                         double ra, double dec, double distance);
00371   ssgEntity*  GetSSGEntity (void);
00372 
00373 protected:
00374   // SSG tree
00375   ssgTransform  *top;
00376 
00377   ssgColourArray  *rgba;
00378   ssgVertexArray  *va;
00379 };
00380 
00381 
00382 //
00383 // CJupiterImage class implements the visual model for the planet Jupiter
00384 //
00385 class CJupiterImage {
00386 public:
00387   CJupiterImage (void);
00388 
00389   // CJupiterImage methods
00390   void    Repaint (float mv, float limit, float factor);
00391   void    Reposition (sgVec3 pos, double lst, double lat,
00392                         double ra, double dec, double distance);
00393   ssgEntity*  GetSSGEntity (void);
00394 
00395 protected:
00396   // SSG tree
00397   ssgTransform  *top;
00398 
00399   ssgColourArray  *rgba;
00400   ssgVertexArray  *va;
00401 };
00402 
00403 
00404 //
00405 // CSaturnImage class implements the visual model for the planet Saturn
00406 //
00407 class CSaturnImage {
00408 public:
00409   CSaturnImage (void);
00410 
00411   // CSaturnImage methods
00412   void    Repaint (float mv, float limit, float factor);
00413   void    Reposition (sgVec3 pos, double lst, double lat,
00414                         double ra, double dec, double distance);
00415   ssgEntity*  GetSSGEntity (void);
00416 
00417 protected:
00418   // SSG tree
00419   ssgTransform  *top;
00420 
00421   ssgColourArray  *rgba;
00422   ssgVertexArray  *va;
00423 };
00424 
00425 
00426 //
00427 // The CSkyManager class pulls all of the previous classes together into
00428 //   the top-level application interface to the sky visual model.
00429 //
00430 class CSkyManager {
00431 public:
00432     CSkyManager (void);
00433     ~CSkyManager (void);
00434 
00435   // CSkyManager methods
00436   void      Update (float dT);
00437   void      SetCamera (SPosition pos, SVector orient);
00438   void      PreDraw (void);
00439   void      Print (FILE *f);
00440 
00441 protected:
00442   // SSG tree
00443   ssgRoot     *pre_root;
00444   ssgSelector   *pre_selector;
00445   ssgTransform  *pre_transform;
00446 
00447   // Sky lighting model
00448   CSkyLight   *skylight;
00449 
00450   // Various sky object images
00451   CSkyDomeImage *domeimage;
00452   CStarImages   *starimage;
00453   CSolImage   *solimage;
00454   CMoonImage    *moonimage;
00455   CMercuryImage *mercuryimage;
00456   CVenusImage   *venusimage;
00457   CMarsImage    *marsimage;
00458   CJupiterImage *jupiterimage;
00459   CSaturnImage  *saturnimage;
00460 
00461   // Ephemeris calculators for the sun, moon and planets
00462   CSol      *sol;
00463   CMoon     *moon;
00464   CMercury    *mercury;
00465   CVenus      *venus;
00466   CMars     *mars;
00467   CJupiter    *jupiter;
00468   CSaturn     *saturn;
00469 
00470   // Darkness phase at last update
00471   EDarkPhase    old_phase;
00472 
00473   // Effective visibility, in feet
00474   float     effective_visibility;
00475   float     skyDistance;
00476 };
00477 
00478 #endif // SKY_H
00479 
SourceForge.net Logo Documentation generated by doxygen