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

Terrain.h

Go to the documentation of this file.
00001 /*
00002  * Terrain.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 
00031 #ifndef TERRAIN_H
00032 #define TERRAIN_H
00033 
00034 #include <stdarg.h>
00035 #include "FlyLegacy.h"
00036 #include "Utility.h"
00037 #include "QTR.h"
00038 #include "LogFile.h"
00039 #include <vector>
00040 #include <queue>
00041 #include <string>
00042 #include <set>
00043 
00044 //
00045 // Terrain debugging constants
00046 //
00047 #define TERRAIN_NO_DEBUG            0
00048 #define GLOBE_TILES                 1
00049 #define QUARTER_GLOBE_TILES         2
00050 #define SUPER_TILES                 3
00051 #define DETAIL_TILES                4
00052 #define SLICED_QUARTER_GLOBE_TILES  5
00053 #define SLICED_SUPER_TILES          6
00054 
00055 #define TERRAIN_DEBUG_LEVEL     TERRAIN_NO_DEBUG
00056 
00057 //
00058 // Terrain subdivision constants
00059 //
00060 #define TERRAIN_SUBDIVISION_BASE                   0
00061 #define TERRAIN_SUBDIVISION_QTR                    5
00062 #define TERRAIN_SUBDIVISION_GLOBE_TILE             8
00063 #define TERRAIN_SUBDIVISION_QUARTER_GLOBE_TILE     9
00064 #define TERRAIN_SUBDIVISION_SUPER_TILE            12
00065 #define TERRAIN_SUBDIVISION_DETAIL_TILE           14
00066 
00067 
00068 //
00069 // Enum type describing the format of elevation data within a CElevationBlock
00070 //
00071 typedef enum {
00072   ELEVATION_TYPE_UNKNOWN,
00073   ELEVATION_TYPE_CENTER,
00074   ELEVATION_TYPE_CORNER
00075 } EElevationType;
00076 
00077 //
00078 // CElevationBlock
00079 //
00080 // Abstract base class for all types of elevation data blocks
00081 //
00082 class CElevationBlock {
00083 public:
00084   // Constructors/Destructor
00085   CElevationBlock (int x, int z, int size);
00086   virtual ~CElevationBlock (void);
00087 
00088   // CElevationBlock methods
00089   virtual int    GetDetailTileResolution (void) = 0;
00090   virtual void   GetDetailTileElevations (int x, int z, float **data) = 0;
00091   EElevationType GetElevationType (void);
00092   virtual int    GetSize (void);
00093   virtual bool   DetailTileInBlock (int x, int z);
00094 
00095 protected:
00096   EElevationType  type;
00097   int             x, z;   // Detail tile indices of lower-left (SW) corner
00098   int             size;   // Size of the block, in detail tiles
00099 };
00100 
00101 //
00102 // CElevationBlockQTR
00103 //
00104 // Concrete class representing an elevation block stored in a QTR file
00105 //
00106 class CElevationBlockQTR : public CElevationBlock {
00107 public:
00108   // Constructors / Destructor
00109   CElevationBlockQTR (int x, int z, const char* qtrFilename);
00110   virtual ~CElevationBlockQTR (void);
00111 
00112   // CElevationBlock methods
00113   virtual int   GetDetailTileResolution (void);
00114   virtual void  GetDetailTileElevations (int x, int z, float **data);
00115 protected:
00116   CQTRFile      *qtrFile;
00117 };
00118 
00119 
00120 //
00121 // CElevationBlockBT
00122 //
00123 // Concrete class representing an elevation block stored in a .BT
00124 //   (Enviro) file format
00125 //
00126 class CElevationBlockBT : public CElevationBlock {
00127 public:
00128   // Constructors / Destructor
00129   CElevationBlockBT (int x, int z, const char* btFilename);
00130   virtual ~CElevationBlockBT (void);
00131 
00132   // CElevationBlock methods
00133   virtual int   GetDetailTileResolution (void);
00134   virtual void  GetDetailTileElevations (int x, int z, float **data);
00135 
00136   // CElevationBlockBT methods
00137   void          Load (const char* btFilename);
00138 
00139 protected:
00140 };
00141 
00142 //
00143 // CElevationBlockGrid
00144 //
00145 // Concrete class representing an elevation block stored as a simple
00146 //   array of float elevation values
00147 //
00148 class CElevationBlockGrid : public CElevationBlock {
00149 public:
00150   // Constructors / Destructor
00151   CElevationBlockGrid (int x, int z, int size, int resolution, float** data);
00152   virtual ~CElevationBlockGrid (void);
00153 
00154   // CElevationBlock methods
00155   virtual int   GetDetailTileResolution (void);
00156   virtual void  GetDetailTileElevations (int x, int z, float **data);
00157 
00158 protected:
00159   int           subdivision;    // Subdivision level per detail tile
00160   float         **data;         // Elevation array
00161 };
00162 
00163 //
00164 // Super tile TRN elevations
00165 //
00166 class CElevationTRNSuperTile {
00167 public:
00168   CElevationTRNSuperTile (int x, int z, int subdivision);
00169   ~CElevationTRNSuperTile (void);
00170 
00171 public:
00172   int                       x, z;         // Super tile indices
00173   int                       subdivision;  // Detail tile subdivision level
00174   CElevationBlockGrid       *elev;        // Base resolution elevations
00175   CElevationBlockGrid       ***dtArray;   // Array of high-detail elevations
00176 };
00177 
00178 //
00179 // Quarter Globe Tile TRN elevations
00180 //
00181 class CElevationTRNQuarterGlobeTile {
00182 public:
00183   CElevationTRNQuarterGlobeTile (int x, int z, int subdivision);
00184   ~CElevationTRNQuarterGlobeTile (void);
00185 
00186 public:
00187   int                       x, z;         // Quarter globe tile indices
00188   int                       subdivision;  // Super tile subdivision level
00189   CElevationTRNSuperTile    ***stArray;   // Array of super tile elevation data
00190 };
00191 
00192 
00193 //
00194 // CElevationLookup.  Applications performing lookups in the elevation database
00195 //  are returned an instance of this class
00196 //
00197 typedef struct {
00198   float     x, z;           // Relative location within tile, (0,0) = NW corner
00199   float     elevation;      // Elevation in feet
00200 } SElevationLookupPoint;
00201 
00202 class CElevationLookup {
00203 public:
00204   CElevationLookup (void);
00205   ~CElevationLookup (void);
00206 
00207 public:
00208   GLint       glType;       // GL_TRIANGLE_FAN or GL_TRIANGLE_STRIP
00209   union {
00210     struct {
00211       int                   nPoints;
00212     } fanData;
00213     struct {
00214       int                   nStrips;
00215       int                   stripSize;
00216     } stripData;
00217   } u;
00218   ulList      *points;      // List of SElevationLookupPoint
00219 };
00220 
00221 
00222 //
00223 // Elevation Database.  The database consists of a list of database chunks, and
00224 //   a lookup mechanism to quickly find the chunk with the highest level of detail.
00225 // Lookups are performed on a single detail tile basis.
00226 // Typically, a particular detail tile might have no elevations (in which case
00227 //   zeroes are returned), normal-detail global elevations (one elevation value
00228 //   per corner of the detail tile) or high-detail custom elevations (4x4 or higher
00229 //   grid of array values for the detail tile.
00230 //
00231 class CTileElevationDatabase {
00232 public:
00233   CTileElevationDatabase (void);
00234   ~CTileElevationDatabase (void);
00235 
00236   // CTileElevationDatabase methods
00237   CElevationLookup    *GetDetailTileElevations (int x, int z);
00238   void                AddQTRBlock (CElevationBlockQTR *block);
00239   bool                RemoveQTRBlock (CElevationBlockQTR *block);
00240   CElevationTRNQuarterGlobeTile *AddTRN (int x, int z, int subdivision);
00241   void                RemoveTRN (int x, int z);
00242 
00243 protected:
00244   int                 DetailTileToQtrTile (int x, int z);
00245   void                QtrBaseDetailTile (int qtr, int *x, int *z);
00246   EElevationType      GetElevationType (int x, int z);
00247   int                 GetDetailTileResolution (int x, int z);
00248   CElevationBlockBT  *LoadBT (int qtr);
00249   CElevationBlockQTR *LoadQTR (int qtr);
00250   CElevationBlock    *Search (int x, int z);
00251   CElevationTRNQuarterGlobeTile *SearchTRN (int x, int z);
00252 
00253 protected:
00254   ulList             *qtrList;          // List of CElevationBlockQTR*
00255   ulList             *btList;           // List of CElevationBlockBT*
00256   ulList             *trnList;          // List of CElevationTRNQuarterGlobeTile*
00257 };
00258 
00259 extern CTileElevationDatabase *tedb;    // Defined in Terrain.cpp
00260 
00261 
00262 //
00263 // Structure used to pass cartesian extents of tiles
00264 //
00265 typedef struct {
00266   SVector sw, nw, se, ne;
00267 } STileExtents;
00268 
00269 
00270 //
00271 // CGenericTileType
00272 //
00273 class CGenericTileType : public CStreamObject {
00274 public:
00275   // Constructors/destructors
00276   CGenericTileType (void);
00277 
00278   // CStreamObject methods
00279   int Read (SStream *stream, Tag tag);
00280   void ReadFinished (void);
00281 
00282 protected:
00283   int   pixl;     // Pixel value in generic tile type bitmap
00284   int   txti;     // Index value in texture name
00285   int   tilc;     // Tile count
00286 
00287   char  texture[80];  // Texture filename
00288 };
00289 
00290 
00291 //
00292 // CGenericTileDatabase
00293 //
00294 class CGenericTileDatabase : public CStreamObject {
00295 public:
00296   // Constructors/destructors
00297   CGenericTileDatabase (const char* gentiles);
00298 
00299   // CStreamObject methods
00300   int Read (SStream *stream, Tag tag);
00301 
00302 protected:
00303   char  schm[64];   // Texture naming scheme
00304   ulList  tile;     // List of CGenericTile*
00305 };
00306 
00307 
00308 extern CGenericTileDatabase *gtdb;    // Defined in Terrain.cpp
00309 
00310 
00311 
00312 typedef enum {
00313   TILE_DETAIL_UNDEFINED = -1, // Not applicable
00314   TILE_DETAIL_LOW = 0,    // Low-detail 64 x 64 resolution
00315   TILE_DETAIL_MEDIUM = 1,   // Medium-detail 128 x 128 resolution 
00316   TILE_DETAIL_HIGH = 2    // High-detail 256 x 256 resolution
00317 } ETileDetail;
00318 
00319 
00320 //
00321 // CTerrainTypeDatabase
00322 //
00323 class CTerrainTypeDatabase {
00324 public:
00325   CTerrainTypeDatabase (void);
00326   ~CTerrainTypeDatabase ();
00327 
00328   // CGroundTypeDatabase methods
00329   ETerrainType GetTerrainType (int x, int z);
00330 
00331 protected:
00332   PODFILE*    img;      // tiletype.img in Globe.pod
00333 };
00334 
00335 extern CTerrainTypeDatabase *ttdb;    // Defined in Terrain.cpp
00336 
00337 
00338 //
00339 // CDefaultTextureDatabase
00340 //
00341 class CDefaultTextureDatabase
00342 {
00343 public:
00344   CDefaultTextureDatabase (void);
00345   ~CDefaultTextureDatabase ();
00346 
00347   // CDefaultTextureDatabase methods
00348   void          Init (void);
00349   void          Purge (void);
00350   CRawImage*    GetBaseTexture (int x, int z, ETerrainType type, ETileDetail level);
00351   void          GetCompositeTextureName (unsigned int x, unsigned int z, char *textureName);
00352   CRawImage*    GetCompositeTexture (const char* textureName, ETileDetail level);
00353   CRawImage*    GetCompositeTexture (unsigned int x, unsigned int z, ETileDetail level);
00354   void          GetReliefShadingRGB (const float elev, float &r, float &g, float &b);
00355 
00356 protected:
00357   // Base texture cache
00358   CRawImage*    low[256];
00359   CRawImage*    med[256][4][4];
00360   CRawImage*    high[256][4][4];
00361 
00362   // Relief shading
00363   float         relief[256][3];
00364   float         maxElevation;
00365   int           negativeIndex, zeroIndex, baseIndex, maxIndex;
00366 
00367   // List of cached composite textures
00368   ulList        composite;
00369 };
00370 
00371 extern CDefaultTextureDatabase  *dtdb;    // Defined in Terrain.cpp
00372 
00373 
00374 //
00375 // CSceneryModelDatabase
00376 //
00377 
00378 typedef struct {
00379   char        filename[64];
00380   CModelSMF   *smf;
00381 } SSceneryModel;
00382 
00383 
00384 class CSceneryModelDatabase {
00385 public:
00386   ~CSceneryModelDatabase ();
00387 
00388   // CSceneryModelDatabase methods
00389   ssgEntity* GetSceneryModel (const char* filename);
00390 
00391 protected:
00392   ulList    model;    // List of SSceneryModel*
00393 };
00394 
00395 extern CSceneryModelDatabase  *smdb;    // Defined in Terrain.cpp
00396 
00397 
00398 //
00399 // CTransitionMaskDatabase
00400 //
00401 // This database provides a centralized interface for generic texture transition
00402 //   masks.  There are three types of masks -- "Right-side", "Bottom-side" and
00403 //   "Corner" transitions.  This implementation has only one transition of each
00404 //   type, but in future (when the MSK files are figured out) there will be
00405 //   multiple transitions of each type which will be randomly dispensed.
00406 //
00407 
00408 class CTransitionMaskDatabase {
00409 public:
00410   CTransitionMaskDatabase (void);
00411   ~CTransitionMaskDatabase (void);
00412 
00413   // CTransitionMaskDatabase methods
00414   CMaskImage *GetBottomTransition (ETileDetail detail);
00415   CMaskImage *GetRightTransition (ETileDetail detail);
00416   CMaskImage *GetCornerTransition (ETileDetail detail);
00417 
00418 protected:
00419   CMaskImage  *high_right, *med_right, *low_right;
00420   CMaskImage  *high_bottom, *med_bottom, *low_bottom;
00421   CMaskImage  *high_corner, *med_corner, *low_corner;
00422 };
00423 
00424 extern CTransitionMaskDatabase  *tmdb;    // Defined in Terrain.cpp
00425 
00426 
00427 //
00428 // CGtpTile
00429 //
00430 // Class representation of a default watermask ground tile, which is a component
00431 //   of a GTP default watermask file.  This class is used by CWatermaskDatabase
00432 //
00433 typedef struct {
00434   short     nPolyVerts;
00435   short     *pvlist;
00436 } SGtpPolygon;
00437 
00438 typedef struct {
00439   float x, z;
00440 } SGtpVertex;
00441 
00442 class CGtpTile {
00443 public:
00444   void    Print (FILE *f);
00445 
00446 public:
00447   int       x, z;
00448   short     nVertices;
00449   SGtpVertex    *vlist;
00450   short     nPolygons;
00451   SGtpPolygon   *plist;
00452 };
00453 
00454 
00455 //
00456 // CGtpFile
00457 //
00458 // Class representation of a default watermask globe tile (GTP) file.  This class
00459 //   is used by CWatermaskDatabase
00460 //
00461 typedef struct {
00462   unsigned short  x;
00463   unsigned short  z;
00464   unsigned long offset;
00465 } SGtpHeader;
00466 
00467 
00468 class CGtpFile {
00469 public:
00470   // Constructors/destructors
00471   CGtpFile (void);
00472   ~CGtpFile (void);
00473 
00474   // CGtpFile methods
00475   void    Print (FILE *f);
00476 
00477 public:
00478   int     x, z;
00479   short   nTiles;
00480   CGtpTile  *tile;
00481 };
00482 
00483 
00484 //
00485 // CWatermaskDatabase
00486 //
00487 
00488 class CWaterMaskDatabase {
00489 public:
00490   // Constructors/Destructor
00491   CWaterMaskDatabase (void);
00492   ~CWaterMaskDatabase (void);
00493 
00494   // CWaterMaskDatabase methods
00495   void    AddGlobeTile (int x, int z);
00496   void    DeleteGlobeTile (int x, int z);
00497   CGtpTile  *FindDetailTile (int dx, int dz);
00498 //  bool    DetailTileOffset (int dx, int dz, unsigned long *offset, int *index);
00499   CMaskImage  *GetWaterMask (int dx, int dz, ETileDetail detail);
00500   void    Print (FILE *f);
00501 
00502 protected:
00503   int     FindGlobeTile (int x, int z);
00504 
00505 protected:
00506   ulList    gtlist;     // List of *CGtpFile
00507 };
00508 
00509 extern CWaterMaskDatabase *wmdb;    // Defined in Terrain.cpp
00510 
00511 
00512 //
00513 // CScenerySet
00514 //
00515 // Implementation : ScenerySet.cpp
00516 //
00517 // A CScenerySet encompasses a chunk of sliced scenery of any arbitrary size.
00518 //   The stream file that defines a scenery set is located in a sub-directory
00519 //   of any \Scenery folder.
00520 //
00521 class CScenerySet : public CStreamObject {
00522 public:
00523   // Constructors / Destructor
00524   CScenerySet (const char* baseFolder, const char* scfFolder, const char* scfFilename);
00525   ~CScenerySet (void);
00526 
00527   // CStreamObject methods
00528   int Read (SStream *stream, Tag tag);
00529 
00530   // CScenerySet methods
00531   bool    InLoadRange (SPosition pos);
00532   bool    InCoverageRange (SPosition pos);
00533   bool    IsLoaded (void);
00534   void    Load (void);
00535   void    Unload (void);
00536   int     GetRefCount (void);
00537   void    IncRefCount (void);
00538   void    DecRefCount (void);
00539 
00540 protected:
00541   SPosition                 call, caur; // Coverage area lower-left / upper-right
00542   SPosition                 ldll, ldur; // Load area lower-left / upper-right
00543   std::vector<std::string>  podList;    // List of POD filenames
00544   char          baseFolder[1024];  // Base folder name
00545   char          scfFolder[1024];   // SCF folder name
00546   char          scfFilename[64];   // SCF filename
00547   PFS           *pfs;              // Pod filesystem containing files for the scenery
00548   bool          loaded;            // Whether scenery set is loaded
00549   int           refCount;          // Number of references
00550 };
00551 
00552 
00553 //
00554 // CScenerySetDatabase
00555 //
00556 
00557 class CScenerySetDatabase {
00558 public:
00559   // Constructors/Destructor
00560   CScenerySetDatabase (void);
00561   ~CScenerySetDatabase (void);
00562 
00563   // CScenerySetDatabase methods
00564   void    Purge (void);
00565   void    Init (void);
00566   void    LoadInFolder (const char* base, const char *path);
00567   void    Register (SPosition pos);
00568   void    Deregister (SPosition pos);
00569 
00570 protected:
00571   std::set<CScenerySet*>    setActive;    // Set of active scenery sets
00572   std::set<CScenerySet*>    setInactive;  // Set of inactive scenery sets
00573 };
00574 
00575 extern CScenerySetDatabase *ssdb;    // Defined in ScenerySet.cpp
00576 
00577 
00578 //
00579 // Construct texture name for a given detail tile
00580 //
00581 void GetDetailTileTextureName (int x, int z, char *textureName);
00582 
00583 //
00584 // This function compiles a customized generic detail tile texture.
00585 //   The composite texture is composed of up to four generic detail
00586 //   tile textures, properly transitioned based on the terrain type
00587 //   of the tile in question, and the terrain types of the tiles to
00588 //   the east, south and south-east.
00589 //
00590 CRawImage *GetDetailTileTexture (int x, int z, ETileDetail detail);
00591 
00592 
00593 typedef struct {
00594   GLuint            texid;
00595   float             lls;
00596   float             llt;
00597   float             urs;
00598   float             urt;
00599 } STileTextureInfo;
00600 
00601 
00602 //
00603 // Data structure representing the six plane equations of a viewing frustum.
00604 //
00605 typedef struct {
00606   sgVec4  plane[6];
00607 } SFrustumPlanes;
00608 
00609 
00610 //
00611 // Up to sixteen texture formats can possibly be supported.  
00612 //
00613 // 0 = 64x64    8-bit indexed
00614 // 4 = 128x128  8-bit indexed
00615 // 5 = 256x256  8-bit indexed
00616 //
00617 
00618 //
00619 // CTerrainTexture is an abstract base class for all terrain texture classes.
00620 //
00621 class CTerrainTexture {
00622 public:
00623   CTerrainTexture (void);
00624   virtual ~CTerrainTexture (void);
00625 
00626   // CTerrainTexture methods
00627           GLuint    GetTextureObject (void);
00628   virtual void      Load (const char* name, int level=0) = 0;
00629   virtual void      Unload (void);
00630 
00631 protected:
00632   GLuint            texid;    
00633   int               level;    
00634 };
00635 
00636 //
00637 // CTerrainTextureGeneric encapsulates generic textures which are composited from
00638 //   four individual generic sub-textures.  The texture name specification passed
00639 //   to the Load() function must be of the following form:
00640 //      "AABBXXYY"
00641 //
00642 class CTerrainTextureGeneric : public CTerrainTexture {
00643 public:
00644   CTerrainTextureGeneric (void);
00645   ~CTerrainTextureGeneric (void);
00646 
00647   // CTerrainTextureGeneric methods
00648 
00649 protected:
00650 };
00651 
00652 //
00653 // CTerrainTextureSliced encapsulates a sliced texture, which is loaded from
00654 //   a specific custom texture file.  A generic texture name may also be supplied
00655 //   which is used when a custom texture of the given detail level is not
00656 //   available.  If no texture is available then the texture will use the default
00657 //   GL texture.
00658 class CTerrainTextureSliced : public CTerrainTexture {
00659 public:
00660   CTerrainTextureSliced (void);
00661   ~CTerrainTextureSliced (void);
00662 
00663   // CTerrainTextureSliced methods
00664   void      Load (const char* slicedname, const char*defaultname, int level=0);
00665 
00666 protected:
00667 };
00668 
00669 //
00670 // CTerrainTextureDebug encapsulates a debugging texture.  Currently this is the
00671 //   texture name formatted in white text on a gray background.  The texture
00672 //   is also edged with a white border.
00673 //
00674 class CTerrainTextureDebug : public CTerrainTexture {
00675 public:
00676   CTerrainTextureDebug (void);
00677   ~CTerrainTextureDebug (void);
00678 
00679   // CTerrainTextureSliced methods
00680   void      Load (const char* slicedname, const char*defaultname, int level=0);
00681 
00682 protected:
00683 };
00684 
00685 
00686 //
00687 // CTerrainTile is an abstract class encapsulating attributes and functions common
00688 //   to all terrain tile types.  This class is subclassed below into the various
00689 //   types of tiles, i.e. Globe, Quarter Globe, Super and Detail Tiles
00690 //
00691 class CTerrainTile : public ssgTransform {
00692 public:
00693   CTerrainTile (void);
00694   virtual ~CTerrainTile (void);
00695 
00696   // ssgTransform methods
00697   virtual void print (FILE *fd = stderr, char *indent = "", int how_much = 2);
00698 
00699   // CTerrainTile methods
00700   virtual void  CalculateCenter (void);
00701   virtual void  SetBounds (SPosition sw, SPosition nw, SPosition ne, SPosition se);
00702   virtual void  SetCorners (double sw_lat, double sw_lon,
00703                             double ne_lat, double ne_lon);
00704   virtual void  FormatBounds (void);
00705 //  virtual bool  CheckVisibility (SPosition from, float vis);
00706   virtual void  Create (void);
00707   virtual void  Destroy (void);
00708   virtual bool  IsCreated (void);
00709   void          SetDetail (ETileDetail detail);
00710 
00711 protected:
00712   int           level;            // Subdivision level
00713   bool          created;          // Has renderable tile geometry been created
00714   GLuint        texid;            // GL texture ID
00715 
00716   SPosition     sw, nw, ne, se;   // Boundary lat/lon of the tile
00717   SPosition     c;                // Center lat/lon of the tile
00718   char          swBound[64];      // SW corner lat/lon in string format
00719   char          nwBound[64];      // NW corner lat/lon in string format
00720   char          neBound[64];      // NE corner lat/lon in string format
00721   char          seBound[64];      // SW corner lat/lon in string format
00722 };
00723 
00724 //
00725 // CDetailTile
00726 //
00727 // The Detail Tile (DT) is the lowest level of terrain tile decomposition.
00728 //
00729 class CDetailTile : public CTerrainTile {
00730 public:
00731   CDetailTile (unsigned int x, unsigned int z);
00732   virtual ~CDetailTile (void);
00733 
00734   // CTerrainTile methods
00735   virtual void    Create (void);
00736   virtual void    Destroy (void);
00737 
00738   // CDetailTile methods
00739   inline ssgEntity* GetSSGEntity (void) { return top; }
00740   void              LoadDefaultTexture (ETileDetail detail);
00741   void              SetDetail (ETileDetail detail);
00742   virtual void      Print (FILE *f) {}
00743   void              AssignDefaultTextureName (const char* name);
00744   void              AssignTexture (ETileDetail detail, STileTextureInfo &info);
00745 
00746 protected:
00747   void    CreateFanGeometry (CElevationLookup *elev);
00748   void    UpdateFanTexCoords (STileTextureInfo &info);
00749   void    CreateStripGeometry (CElevationLookup *elev);
00750   void    UpdateStripTexCoords (STileTextureInfo &info);
00751 
00752 protected:
00753   unsigned int    x, z;
00754   int             globe_x, globe_z; // Index of parent Globe Tile
00755   ssgBranch       *top;
00756 
00757 public:
00758   STileTextureInfo  texinfo[3];             // Texture info
00759   char              defaultTextureName[16];
00760   ETileDetail       detail;
00761   CElevationLookup *elevLookup;             // Results from elevation database lookup
00762 };
00763 
00764 /*
00765 //
00766 // CDefaultDetailTile
00767 //
00768 class CDefaultDetailTile : public CDetailTile {
00769 public:
00770   CDefaultDetailTile (unsigned int x, unsigned int z);
00771   virtual ~CDefaultDetailTile (void);
00772 
00773   // CTerrainTile methods
00774   void    Create (void);
00775   void    Destroy (void);
00776 
00777   // CDetailTile methods
00778   GLuint  LoadTexture (ETileDetail detail);
00779   void    SetDetail (ETileDetail detail);
00780   void    Print (FILE *f);
00781 };
00782 
00783 
00784 //
00785 // CSlicedDetailTile
00786 //
00787 class CSlicedDetailTile : public CDetailTile {
00788 public:
00789   CSlicedDetailTile (unsigned int x, unsigned int z, const char* texturename);
00790   virtual ~CSlicedDetailTile (void);
00791 
00792   // CTerrainTile methods
00793   void    Create (void);
00794   void    Destroy (void);
00795 
00796   // CDetailTile methods
00797   void            AssignTexture (ETileDetail detail, STileTextureInfo &info);
00798   virtual void    Print (FILE *f);
00799 
00800 protected:
00801 };
00802 */
00803 
00804 //
00805 // CSuperTile
00806 //
00807 // The Super Tile (ST) consists of a regular array (8x8 by default) of detail tiles
00808 //
00809 class CSuperTile : public CTerrainTile {
00810 public:
00811   CSuperTile (unsigned int supr_x, unsigned int supr_z);
00812   virtual ~CSuperTile (void);
00813 
00814   // CTerrainTile methods
00815 
00816   // CSuperTile methods
00817   virtual ssgEntity*    GetSSGEntity (void);
00818   virtual void          Print (FILE* f);
00819 //  virtual bool  CullAgainstFrustum (SFrustumPlanes f);
00820 
00821 protected:
00822   unsigned int  x, z;             // Absolute index of this super tile
00823   int           globe_x, globe_z; // Index of parent globe tile
00824 
00825   int           dimn;             // Dimension of detail tile array
00826 
00827   ssgBranch*    top;
00828 };
00829 
00830 
00831 //
00832 // CDefaultSuperTile
00833 //
00834 class CDefaultSuperTile : public CSuperTile {
00835 public:
00836   // Constructors
00837   CDefaultSuperTile (unsigned int supr_x, unsigned int supr_z);
00838   ~CDefaultSuperTile (void);
00839 
00840   // CTerrainTile methods
00841   void Create (void);
00842   void Destroy (void);
00843 
00844   // CDefaultSuperTile methods
00845   void    Print (FILE* f);
00846 
00847 protected:
00848   CDetailTile*   **dtArray;      // Array of child CDefaultDetailTile*
00849 };
00850 
00851 
00852 //
00853 // CSlicedTextureList
00854 //
00855 // This object is a member of the CSlicedSuperTile object
00856 //
00857 class CSlicedTextureList : public CStreamObject {
00858 public:
00859   // Constructors / Destructor
00860   CSlicedTextureList (void);
00861   ~CSlicedTextureList (void);
00862 
00863   // CStreamObject methods
00864   int Read (SStream *stream, Tag tag);
00865 
00866   // CSlicedTextureList methods
00867   char* TextureName (int i);
00868 
00869 protected:
00870   int     nTextureNames;
00871   char    **textureNames;
00872 };
00873 
00874 
00875 //
00876 // CHighDetailElevations
00877 //
00878 // This object is a member of the CSlicedSuperTile object, corresponding to
00879 //   and instance of the <hdtl> object type in a TRN file
00880 //
00881 class CHighDetailElevations : public CStreamObject {
00882 public:
00883   CHighDetailElevations (int base_x, int base_z, CElevationTRNSuperTile *stElev);
00884   virtual ~CHighDetailElevations (void);
00885 
00886   // CStreamObject methods
00887   int Read (SStream *stream, Tag tag);
00888 
00889 public:
00890   int                 base_x, base_z; // Reference detail tile indices of parent
00891   int                 dimn;           // Subtile dimensions
00892   int                 type;           // Tile type ?
00893   int                 prta_x, prta_z; // Dimensions within parent tile
00894 
00895   CElevationTRNSuperTile *stElev;     // Parent super tile elevations
00896   CElevationBlockGrid    *block;      // Elevation block
00897 };
00898 
00899 
00900 //
00901 // CSlicedSuperTile
00902 //
00903 class CSlicedSuperTile : public CSuperTile, public CStreamObject {
00904 public:
00905   // Constructors
00906   CSlicedSuperTile (unsigned int x, unsigned int z, CElevationTRNQuarterGlobeTile *trn);
00907   ~CSlicedSuperTile (void);
00908 
00909   // CStreamObject methods
00910   int Read (SStream *stream, Tag tag);
00911   void ReadFinished (void);
00912 
00913   // CTerrainTile methods
00914   void Create (void);
00915   void Destroy (void);
00916 
00917   // CSlicedSuperTile methods
00918   void    GetDetailTileElevations (int x, int z,
00919                                    int *xSize, int *zSize, float **data);
00920   void    AssignTexture (ETileDetail detail, STileTextureInfo &info);
00921   void    Print (FILE* f);
00922 
00923 protected:
00924   int                 prta_x, prta_z;  // Indices of this super tile in parent QGT
00925   int                 type;         // Texture type
00926   CSlicedTextureList  *textureList; // List of texture names
00927   int                 **tref;       // Array of texture references
00928 
00929   // Super tile elevations
00930   CElevationTRNQuarterGlobeTile *trn;
00931   CElevationBlockGrid *block;       // Base level elevation block
00932 
00933   CDetailTile*        **dtArray;    // Array of child CSlicedDetailTile*
00934 
00935   ETileDetail         detail;       // Texture detail level for this tile
00936   STileTextureInfo    texinfo[3];   // Texture info for low, medium and high detail
00937 };
00938 
00939 
00940 //
00941 // CSceneryModels
00942 //
00943 // This class reads world object specifications from a scenery (.Sxx) file
00944 //   and adds them to a top-level branch
00945 //
00946 class CSceneryModels : public CStreamObject {
00947 public:
00948   CSceneryModels (const char* sxxFilename);
00949   ~CSceneryModels (void);
00950 
00951   // CStreamObject methods
00952   int Read (SStream *stream, Tag tag);
00953 
00954   // CSceneryModels methods
00955   ssgEntity*      GetSSGEntity (void);
00956 
00957 protected:
00958   ssgBranch   *top;           // Top-level branch
00959   ulList      *wobjList;      // List of CWorldObject*
00960 };
00961 
00962 
00963 typedef enum {
00964   QGT_UNASSIGNED   = 0,
00965   QGT_ASSIGNED     = 1
00966 } EQgtState;
00967 
00968 
00969 //
00970 // CQuarterGlobeTile
00971 //
00972 // A Quarter Globe Tile (QGT) is the first level of terrain tile decomposition
00973 //   below the Globe Tile.
00974 //
00975 class CQuarterGlobeTile : public CTerrainTile {
00976 public:
00977   CQuarterGlobeTile (void);
00978 //  CQuarterGlobeTile (unsigned int x, unsigned int z);
00979   virtual ~CQuarterGlobeTile (void);
00980 
00981   // ssgTransform methods
00982   virtual void print (FILE *fd = stderr, char *indent = "", int how_much = 2);
00983 
00984   // CTerrainTile methods
00985   void      Create (void);
00986   void      Destroy (void);
00987 
00988   // CQuarterGlobeTile methods
00989   void            Initialize (void);
00990   void            AssignIndices (unsigned int x, unsigned int z);
00991   void            UnassignIndices (void);
00992   bool            IsAssigned (void);
00993   void            GetIndices (unsigned int &x, unsigned int &z);
00994   void            UpdatePosition (SPosition pos);
00995 //  virtual bool    CullAgainstFrustum (SFrustumPlanes f);
00996 
00997 protected:
00998   EQgtState       state;            // State of this QGT instance
00999   unsigned int    x, z;             // Absolute index of the QGT
01000   int             globe_x, globe_z; // Index of parent Globe Tile
01001 
01002   char            datapath[64];   // Path to data files for this QGT
01003 
01004   CSceneryModels  *sceneryModels;
01005 
01006   int             stArraySize;
01007   CSuperTile*     **stArray;      // Array of child CSuperTile*
01008 };
01009 
01010 /*
01011 //
01012 // CDefaultQuarterGlobeTile
01013 //
01014 class CDefaultQuarterGlobeTile : public CQuarterGlobeTile {
01015 public:
01016   // Constructors
01017   CDefaultQuarterGlobeTile (unsigned int x, unsigned int z);
01018   virtual ~CDefaultQuarterGlobeTile (void);
01019 
01020   // CTerrainTile methods
01021   void      Create (void);
01022   void      Destroy (void);
01023 
01024   // CDefaultQuarterGlobeTile methods
01025   void      Print (FILE* f);
01026 
01027 protected:
01028   int                   stArraySize;
01029   CDefaultSuperTile*    **stArray;      // Array of child CDefaultSuperTile*
01030 };
01031 
01032 
01033 //
01034 // CSlicedQuarterGlobeTile
01035 //
01036 class CSlicedQuarterGlobeTile : public CQuarterGlobeTile, public CStreamObject {
01037 public:
01038   // Constructors
01039   CSlicedQuarterGlobeTile (unsigned int x, unsigned int z, const char* folder);
01040   virtual ~CSlicedQuarterGlobeTile (void);
01041 
01042   // CTerrainTile methods
01043   void      Create (void);
01044   void      Destroy (void);
01045 
01046   // CStreamObject methods
01047   int Read (SStream *stream, Tag tag);
01048 
01049   // CSlicedQuarterGlobeTile methods
01050   void    Print (FILE* f);
01051 
01052 protected:
01053   unsigned int    half_x, half_z;
01054   unsigned int    lowr_x, lowr_z;
01055 
01056   CRawImage*      fulltex;       // Low-resolution texture
01057   GLuint          fulltexid;     // GL IDs for low-res texture
01058   float           fulltexOffset; // Tiling border width in texture coords
01059   float           ds, dt;        // Texture coordinates per super tile
01060 
01061   CElevationTRNQuarterGlobeTile *trnElevations;
01062 
01063   int                   stArraySize;
01064   CSlicedSuperTile*     **stArray;      // Array of child CSlicedSuperTile*
01065 };
01066 */
01067 /*
01068 //
01069 // Structure containing quarter globe tile references in a globe tile.
01070 //   The specific quarter globe tile subclass type must be known in orer
01071 //   to call the proper destructor
01072 //
01073 typedef enum {
01074   INVALID_QUARTER_GLOBE_TILE,
01075   DEFAULT_QUARTER_GLOBE_TILE,
01076   SLICED_QUARTER_GLOBE_TILE
01077 } EQGTType;
01078 
01079 typedef struct {
01080   EQGTType           type;
01081   CQuarterGlobeTile  *qgt;
01082 } SQGTReference;
01083 
01084 
01085 //
01086 // CGlobeTile
01087 //
01088 // The Globe Tile (GT) is the highest level of terrain tile decomposition.
01089 //
01090 class CGlobeTile : public CTerrainTile {
01091 public:
01092   CGlobeTile (unsigned int globe_x, unsigned int globe_z);
01093   virtual ~CGlobeTile (void);
01094 
01095   // CTerrainTile methods
01096   void        Create (void);
01097   void        Destroy (void);
01098 
01099   // CGlobeTile methods
01100   int         GetX (void);
01101   int         GetZ (void);
01102   void        TranslateFrom (int x, int z);
01103   void        UpdatePosition (SPosition pos, float vis);
01104 //  void        CheckQuarterTileVisibility (SPosition pos, float vis);
01105   virtual bool  CullAgainstFrustum (SFrustumPlanes f);
01106   ssgEntity*  GetSSGEntity (void);
01107   void        Print (FILE* f);
01108 
01109 protected:
01110   unsigned int    x, z;             // Globe tile indices
01111   char            dataFolder[64];   // Folder containing scenery data for this tile
01112 
01113   ssgTransform*   top;
01114 
01115   CQuarterGlobeTile*  qtArray[2][2];    // Array of child quarter globe tiles
01116 
01117 //  GLuint              defaultTexture;   // Default GT texture for debugging
01118 //  SQGTReference       qgtArray[2][2];   // Array of quarter globe tile references
01119 
01120   SNavaid             *navaidList;      // List of navaids in the GT for rendering
01123 };
01124 */
01125 
01126 //
01127 // CTerrainManager
01128 //
01129 // Implementation : TerrainManager.cpp
01130 //
01131 class CTerrainManager {
01132 public:
01133   CTerrainManager (void);
01134   ~CTerrainManager (void);
01135 
01136   // CTerrainManager methods
01137   void    SetCamera (SPosition pos, SPosition lookat, SVector orient);
01138   void    SetPosition (SPosition pos);
01139   void    AssignQgtArrayElement (int x, int z);
01140   float   GetMaxVisibility (void);
01141   float   GetMediumDetailRange (void);
01142   float   GetHighDetailRange (void);
01143   void    UpdateMaxVisibility (void);
01144   void    UpdateMediumDetailRange (void);
01145   void    UpdateHighDetailRange (void);
01146   void    Prepare (void);
01147   void    Draw (void);
01148   void    Log (const char *fmt, ...);
01149   void    Print (FILE* f);
01150 
01151   // Export various tile textures for troubleshooting/debugging
01152 //  void    ExportElevationTileTexture (int tile);
01153 //  void    ExportGlobeTileTexture (int x, int z, ETileDetail detail);
01154 
01155 public:
01156   int           debugLevel; 
01157 
01158 protected:
01159   ssgRoot       *root;      // Root for terrain scene graph
01160   ssgTransform  *top;       // Top-level transform for all terrain
01161 
01162   // Subtile related data members
01163   int xLast;
01164   int zLast;
01165   std::set<CQuarterGlobeTile*>   qFree;   
01166   std::set<CQuarterGlobeTile*>   qBusy;   
01167 
01168   // Visibility related data members
01169   float     visibility;     // Maximum terrain visibility in statute miles
01170   float     vis_feet;       // Maximum terrain visibility in feet
01171   float     vis_check;      // Terrain load/unload distance
01172   float     medium_detail;  // Medium texture detail range in feet
01173   float     high_detail;    // High texture detail range in feet
01174 
01175 private:
01176   CLogFile      *log;       
01177 };
01178 
01179 #endif // TERRAIN_H
SourceForge.net Logo Documentation generated by doxygen