CTerrain.h
上传用户:arsena_zhu
上传日期:2022-07-12
资源大小:399k
文件大小:3k
- /*
- Class Name:
- CTerrain.
- Created by:
- Allen Sherrod (Programming Ace of www.UltimateGameProgramming.com).
- Description:
- This class is a base class used to load and save a terrain.
- */
- #ifndef _CTERRAIN_H_
- #define _CTERRAIN_H_
- #include "main.h"
- struct TextureRegions
- {
- int lowHeight; // Lowest height.
- int optimalHeight; // Ideal height.
- int highHeight; // Highest possible height.
- };
- struct TerrainTiles
- {
- TextureRegions regions[4]; // Texture regions.
- TGATexture texTiles[4]; // Texture tiles.
- int numTiles; // Total number of tiles.
- };
- class CTerrain
- {
- public:
- CTerrain();
- ~CTerrain();
- void SetDataHeight(int x, int z, float set);
- void SetHeight(int x, int z, float set);
- void SetVertex(int x, int z, int index, float set);
- float GetDataHeight(int x, int z);
- float GetHeight(int x, int z);
- float GetVertex(int x, int z, int index);
- float GetRealHeight(float x, float z);
- void AddToHeight(int x, int z, float add);
- void AddToVertex(int x, int z, int index, float add);
- int ConvertToI(int x, int z, int index);
- float GetMaxHeight();
- float GetMinHeight();
- void SetHeightScale(int val);
- void CreatePlaneFromTri(float tri[9], float *plane);
- float *GetTriangle(float x, float z);
- void ConvertMesh();
- void CreateTerrainMesh();
- void CreateTexCoords();
- bool LoadMap(char *filename, int detailRepeats=0);
- bool SaveMap(char *filename);
- float RegionPercent(int tileType, float height);
- void GetTexCoords(GLuint texWidth, GLuint texHeight, GLuint x,
- GLuint z, float &tu, float &tv);
- float InterpolateDataHeight(int x, int z, float textureMapRatio);
- float InterpolateHeight(int x, int z, float textureMapRatio);
- unsigned char *GenerateTextureMap(GLuint imageSize);
- bool LoadTile(int tileType, char *filename);
- void ShutDown();
- float *hMap;
- int side;
- int side_; // side-1
- float fScale;
- bool bInvert;
- // A list of images used to generate terrain texture.
- TerrainTiles m_tiles;
- // Vertex list and vertex colors.
- float *pVertex;
- float *pTexCoords;
- float *pTexCoords2;
- int iVerts;
- int iTriangles;
- int iDetail;
- };
- class CTerrainData
- {
- public:
- CTerrainData();
- CTerrain *terr;
- GLuint iTexID;
-
- int mode; // rendering mode.. GL_LINES, etc
- TGATexture terrDetailTex;
- PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
- PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB;
- void Renderterrain();
- void RenderAll();
- void Destroy();
- bool InitExtensions();
- bool InitTextures();
- bool LoadDetailTexture(char *detail_tex);
- bool Init(CTerrain *tt);
- bool Generate(char *map, int detail, char *t0, char *t1, char *t2, char *t3, char *detail_tex);
- void SetMode(int m);
- };
- class CTerrainEdit
- {
- public:
- CTerrainEdit() {}
- void Init(CTerrain *terr_p) { t = terr_p; }
- CTerrain *t;
- float xPos, yPos;
- void Normalize(float scale);
- void Multiply(float m);
- void Flatten(float power);
- void Increase(float power);
- void Zero();
- void DoHill(int x, int z, int radius, float power);
- void CreateHill(int x, int y, int radius, int iters, float power=1);
- void GenerateTerrain(int iters, int max_radius, int max_iters);
- void GenerateIsland(int width_x, int width_z, int x_pos, int y_pos, int iters, int max_radius, int max_iters);
- };
-
- #endif
- // Copyright October 2004
- // All Rights Reserved!
- // Allen Sherrod
- // ProgrammingAce@UltimateGameProgramming.com
- // www.UltimateGameProgramming.com