⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 terrain.h

📁 小型的3D游戏引擎
💻 H
字号:
#ifndef _TERRAIN_H_
#define _TERRAIN_H_

#include "../texture.h"
#include "../opengl/mem.h"
#include "../entity/entity.h"
#include "terrainnode.h"

class GcQuadtree;

class GcTerrain
{
public:
	GcTerrain();
	~GcTerrain();

	// Initialize the terrain
	bool Init(GcQuadtree *tree, char *heightFile, char *landTex, char *detailTex);
	bool Close();

	// Render the terrain
	void RenderSquare(uint arrayPos, uint squareWidth, uint squareHeight);
	void RenderSquareImmediate(uint x, uint z);


	/* Acessors */

	// Get the height of the terrain
	float Height(float x, float z);

	// Set the scales
	void SetScale(float sScale)		 { scale = sScale; }
	void SetHeightScale(float scale) { heightScale = scale; }

	// Get the scales
	float GetScale()		const	{ return scale; }
	float GetHeightScale() const	{ return heightScale; }

	// Get the widht of the map
	int GetMapWidth() const { return mapWidth; }

	// Get the total/displayed trinagle and square count
	int DrawnTrinagle() const { return drawnTri; }
	int TotalTriangles() const { return totalTri; }
	int DrawnSquares() const { return drawnSquares; }
	int TotalSquares() const { return totalSquares; }

	GcTexture * GetLandTexture() { return &landTexture; }

private:

	/* Initializing code */
	bool InitHeightField(char *heightFile);
	bool InitVertTextColArray();
	void InitIndexArray();
	void InitNormalArray();
	void InitFogArray();
	void InitNodes(GcQuadtree *tree);

	/* Misc code */
	void SetTexCoord(float x, float z);
	void SetupTexture(bool activate = true);
	void SetFogCoord(float height);
	uint CalcMemReq();

	// Terrain drawing vars
	float		*heightField;		// Contains the height field
	float		*vertexArray;		// Contains all map vertises
	float		*textArray;			// Contains all texture cordinates
	float		*normalArray;		// Contains the vertices normal
	float		*fogCoordArray;		// Contains the cordinates for the fog
	float		*colorArray;		// Contains all color info for the vertises
	ushort		*index;				// Contains the indices to draw the terrain
	uint		squareWidth;		// The width of the square to draw
	uint		numVertex;			// The number of elements to draw

	// Terrain information vars
	uint		mapWidth;			// The width of the map
	float		scale;				// The scale of the map
	float		heightScale;		// The height scale of the map

	// Textures
	GcTexture	landTexture;		// The land texture
	GcTexture	detailTexture;		// The detail texture

	// The memory pool for the varius arrays
	GcMem		memPool;

	// Misc statestic variables
	uint		numSquares;
	uint		numRows;
	uint		drawnTri;
	uint		totalTri;
	uint		totalSquares;
	uint		drawnSquares;

	uint		m_numTerrainNodes;
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -