📄 trpage_geom.h
字号:
/* ************************ Copyright Terrain Experts Inc. Terrain Experts Inc (TERREX) reserves all rights to this source code unless otherwise specified in writing by the President of TERREX. This copyright may be updated in the future, in which case that version supercedes this one. ------------------- Terrex Experts Inc. 4400 East Broadway #314 Tucson, AZ 85711 info@terrex.com Tel: (520) 323-7990 ************************ */#ifndef _trpage_geom_h_#define _trpage_geom_h_/* trpage_geom.h Geometry and node definitions. These are the objects that get read from and written to archives.*/#include <trpage_sys.h>#include <trpage_io.h>#include <trpage_swap.h>// Forward declarationsclass trpgMaterial;class trpgTextureEnv;class trpgMatTable;#define ISMASTER 1#define ISLOCAL 2/* This is the archive header structure. There is one per TerraPage archive. You don't write it directly, but instead fill it out and pass it to a trpgwArchive (if you're writing), or get it back from a trpgr_Archive (if you're reading). If you're putting together a reader, just use the default methods for reading this class. Since it's only read once, the overhead is low. {group:Read/Write Classes}*/TX_EXDECL class TX_CLDECL trpgHeader : public trpgReadWriteable{ public: trpgHeader(void); ~trpgHeader(void); // Set the TerraPage version info. void SetVersion(int major,int minor); // Set the database version info. void SetDbVersion(int major,int minor); /* Set the tile size for the given LOD. See GetTileSize for more info. Each LOD must have its size set, otherwise the trpgHeader won't be valid. You must set the number of LODs with SetNumLods first. You should use the AddLod method if you can, which handles all of this. */ void SetTileSize(int lod,const trpg2dPoint &size); // Origin defaults to 0,0,0 void SetOrigin(const trpg3dPoint &); // 2D archive extents. Must be set. void SetExtents(const trpg2dPoint &sw,const trpg2dPoint &ne); typedef enum {DatabaseLocal,Absolute,TileLocal} trpgTileType; // How the coordinates are treated with respect to real world values. void SetTileOriginType(trpgTileType); /* Number of terrain LODs. If you use this method when building a database you have to use the SetLodRange and SetLodSize methods on each LOD as well. It's better to use AddLod instead of calling these three methods. */ void SetNumLods(int); /* Number of tiles (x,y) for each LOD. The single argument version assumes lod = 0, num lods = 1. */ void SetLodSize(int lod,const trpg2iPoint &); void SetLodSize(const trpg2iPoint *); /* Set the range for the given terrain LOD. The single argument version assumes lod = 0, num lods = 1. */ void SetLodRange(int,float64); void SetLodRange(const float64 *); // Increase the number of terrain LODs, adding a new one with the given size and range void AddLod(const trpg2iPoint &size,const trpg2dPoint &ext,float64 range); // Set details for an LOD, resizing if necessary void SetLod(const trpg2iPoint &size,const trpg2dPoint &ext,float64 range,unsigned int lod); // Keep track of the maximum assigned group IDs (for tile paging) void SetMaxGroupID(int); /* Instead of keeping a count of all the group IDs you added and then calling SetMaxGroupID, you can call this function and it will return the next valid groupID to you. It will also keep track of the maximum. */ int AddGroupID(void); // Validity check bool isValid(void) const; // Resets the contents back to empty void Reset(void); // TerraVista version information is two integers. bool GetVersion(int &,int &) const; // Database version information is user defined. Put whatever you want here. bool GetDbVersion(int &,int &) const; /* This is the extents, in X/Y of a single tile. All tiles within an LOD should be the same size (although this is not enforced). It's also assumed that a given tile lives entirely within its own extents (as calculated with this value), although that's not enforced either. */ bool GetTileSize(int,trpg2dPoint &) const; /* The meaning of the database origin varies depending on the value returned by GetTileOriginType. If the database is Absolute, then this value will be the lower left corner. If the database is DatabaseLocal or TileLocal you can use this value to determine the real world coordinates. Just add origin + coordinate. */ bool GetOrigin(trpg3dPoint &) const; /* These are the 2D extents that the database covers. You can use this information to determine where the middle is, for example. */ bool GetExtents(trpg2dPoint &sw,trpg2dPoint &ne) const; /* The tile origin type tells you the coordinate system of each database tile. There are three type: * Absolute - All coordinate values are absolute. No translation is required. * DatabaseLocal - All coordinate values are local to the database. That is if you want to determine the real world value do: coord + origin. * TileLocal - Each tile has its own coordinate system starting from the lower left corner. We do this to get around floating point accuracy problems (although we can do Double coordinates if necessary, as well). To determine the real world coordinate value do: tileID*tileSize + coord. */ bool GetTileOriginType(trpgTileType &) const; /* Group IDs are used by TerraPage to hook level of detail structures together. A TerraPage database can have an arbitrary number of terrain LODs, each stored seperately. To hook them together we use trpgAttach nodes and number each group & LOD node. This returns the maximum group ID in the file, which is important to know if you're keeping an array of them. */ bool GetMaxGroupID(int &) const; /* A TerraPage archive can contain any number of terrain LODs (a typical number is 4). Each of these terrain LODs is accessed seperately (as are the tiles within them). This returns the number of terrain LODs in the file. It will be at least 1. See trpgAttach for instructions on how to hook the terrain LODs together. For version 2.1 and over, this number represent the depest lod that was found in the gaming area. With variable lod, tiles will not ncessarily fill out all of the gaming area for all of the lods. trpgAttach node are no longer used, instead see trpgChildRef */ bool GetNumLods(int32 &) const; /* A terrain LOD conceptually covers the entire database and is broken up into some X x Y set of tiles. We make no assumptions about the number of tiles in each terrain LOD. That's entirely up to the writer. This returns the number of tiles in 2D for a given terrain LOD. */ bool GetLodSize(int32,trpg2iPoint &) const; /* It's up to the TerraPage archive writer to make their terrain LOD structure work by using trpgAttach nodes. The scheme they're using may be quad-tree or replacement LOD or something where the highest LOD isn't even terrain. It really doesn't matter. However, the reader does need a hint as to when tiles for a given LOD must be pulled in. This returns that range in database coordinates (usually meters). */ bool GetLodRange(int32,float64 &) const; // Read/Write functions // Writes this class to a write buffer bool Write(trpgWriteBuffer &); // Reads this class from a read buffer bool Read(trpgReadBuffer &); // Prints this class to a print buffer bool Print(trpgPrintBuffer &) const; // {secret} bool ReadLodInfo(trpgReadBuffer &); void SetMaster(bool isMaster) { if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) { if(isMaster) flags |= ISMASTER;//set the master flag else flags &= ~ISMASTER;//clear the master flag } } bool GetIsMaster() const { return ((flags & ISMASTER)==ISMASTER); } void SetLocal(bool isLocal) { if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) { if(isLocal) flags |= ISLOCAL;//set the local flag else flags &= ~ISLOCAL;//clear the local flag } } bool GetIsLocal() const { return ((flags & ISLOCAL)==ISLOCAL); } void SetBlocks(int rows,int cols) { this->rows = rows; this->cols = cols; } void GetBlocks(int &rows,int &cols) { rows = this->rows; cols = this->cols; } protected: int verMinor,verMajor; int dbVerMinor,dbVerMajor; int maxGroupID; trpg2dPoint sw,ne; trpg3dPoint origin; trpgTileType tileType; int numLods; std::vector<trpg2dPoint> tileSize; std::vector<trpg2iPoint> lodSizes; std::vector<float64> lodRanges; int32 flags; int32 rows; int32 cols;};/* The Texture Environment is used by the trpgMaterial to define texture related parameters. A trpgTextureEnv is associated with each texture used in a trpgMaterial. So, for example, if there are 2 textures in a material, there will be two texture environments. Most of these parameters come straight from the OpenGL specification. It's best to consult that for an exact meaning. If you doing a TerraPage reader, expect to get a trpgTextureEnv when dealing with trpgMaterial definitions. If you're doing a writer, you'll need to build these in the course of building a trpgMaterial. {group:Read/Write Classes}*/TX_EXDECL class TX_CLDECL trpgTextureEnv : public trpgReadWriteable{ friend class trpgMatTable; public: trpgTextureEnv(void); ~trpgTextureEnv(void); // Environment mode values enum {Alpha,Blend,Decal,Modulate,AddDetail,ModulateDetail}; // Set the application mode for the texture. void SetEnvMode(int); // Values used by SetMinFilter and SetMagFilter enum {Point, Linear, MipmapPoint, MipmapLinear, MipmapBilinear, MipmapTrilinear, Nearest}; // Set the Minification filter for a texture void SetMinFilter(int); // Set the Magnification filter for a texture void SetMagFilter(int); // Values used by SetWrap enum {Clamp,Repeat}; // Set the texture wrapping for S and T, respectively void SetWrap(int,int); // Set the texture border color void SetBorderColor(const trpgColor &); /* The environment mode controls how the texture is applied. It can take the following values: Alpha - Used to change the alpha values on a polygon. Blend - Blended with the polygon color Decal - Doesn't take polygon color into account. Modulate - See openGL spec for definition. AddDetail - See openGL spec for definition. ModulateDetail - See openGL spec for definition. */ bool GetEnvMode(int32 &) const; /* The Minification and Magnification filters control how texture mipmap levels are used. We support the values: Point, Linear, MipmapPoint, MipmapLinear, MipmapBilinear, MipmapTrilinear, Nearest */ bool GetMinFilter(int32 &) const; // Get the magnification filter bool GetMagFilter(int32 &) const; /* Wrapping controls how textures are used near the edges. There are two valid values: Clamp, Repeat. */ bool GetWrap(int &,int &) const; /* This maps straight into the OpenGL definition of border color. */ bool GetBorderColor(trpgColor &) const; // Validity check bool isValid(void) const; // Resets the contents back to empty void Reset(void); // Writes this class to a write buffer bool Write(trpgWriteBuffer &); // Reads this class from a read buffer bool Read(trpgReadBuffer &); // Prints this class to a print buffer bool Print(trpgPrintBuffer &) const; protected: int envMode; int minFilter; int magFilter; int wrapS,wrapT; trpgColor borderCol;};/* The material definition for TerraPage encompasses those things that have to do with visual display that can be indexed and disassociated from the polygons themselves. This covers things like color, texture, alpha and a few more obscure ones. Materials are indexed centrally in a trpgMatTable. This material definition borrows heavily from the OpenGL specification. Please refer to that for a good definition of all the fields. If you're doing a TerraPage reader you'll need to deal with these in two places. First, is when you read the archive header and get a trpgMatTable back. You'll want to translate them into your own internal representation and keep track of the mapping. Later, when parsing trpgGeometry nodes, you'll run into them again. This time they will be material indices into a trpgMatTable. At that point you'll want to map these indices into your own material definition table. If you're doing a TerraPage writer you'll need to create one of these for every unique material-like object you have. Since trpgMaterial objects are indexed centrally in a TerraPage archive, you should take advantage of that and use as few as possible. After defining one, you'll want to add it to a trpgMatTable and keep track of the material index that returns. This will be the mapping from your own internal material table (or whatever you've got) into the archive's material table. A trpgMaterial sets up defaults that work pretty well, so just fill in what you need to use. {group:Read/Write Classes}*/TX_EXDECL class TX_CLDECL trpgMaterial : public trpgReadWriteable{ friend class trpgMatTable; public: trpgMaterial(void); ~trpgMaterial(void); // Set base material color void SetColor(const trpgColor &); // Ambient color void SetAmbient(const trpgColor &); // Diffuse color (the most commonly used) void SetDiffuse(const trpgColor &);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -