summaryrefslogtreecommitdiff
path: root/common/terrain.h
blob: fabedefe5cf70aff9922ce64720a4e70bd9ffbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
//	terrain.h
////////////////////////////////////////////////////

#ifndef _TERRAIN_H_
#define _TERRAIN_H_

#include "defines.h"

class File;
class Camera;
class Texture;

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

	float control[48]; // 4x4 grid
	unsigned short steps;

	float* vertex;
	float* normals;
	float* coords;
	unsigned short* index;

	bool visible;

	void InitBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ);
	bool BoxIsOutside(const float plane[4]) const;
	void Tesselate(bool bNormals);
	void FreeMemory();

protected:
	float corners[8][3];
};

class Terrain
{
public:
	Terrain();
	~Terrain();
	Terrain& operator=(const Terrain& source);

	void LoadTexture(bool bLinear);
	void Render(Camera* pCam, float aspect);
	void LoadDefaults(bool bLinear);
	void SetSize(float uSize, float vSize);
	void GetSize(float *uSize, float *vSize);
	void FileLoad(File* file);
	void FileSave(File* file);
	void Tesselate();
	void SetControlPoints();
	void GenerateRandom();

	void SetPatchCount(int uPatches, int vPatches);
	void GetPatchCount(int *uCount, int *vCount);
	int GetCountU()
		{ return m_uPatches != 0 ? m_uPatches*3 + 1 : 0; }
	int GetCountV()
		{ return m_vPatches != 0 ? m_vPatches*3 + 1 : 0; }
	float** GetControlPoints()
		{ return m_pControl; }

	unsigned long m_nOptions;
	char m_strTexture[LC_MAXPATH];
	float m_fColor[3];

protected:
	void FreeMemory();
	void FindVisiblePatches(Camera* pCam, float aspect);

	float** m_pControl;
	TerrainPatch** m_Patches;
	int m_uPatches;
	int m_vPatches;
	float m_uSize;
	float m_vSize;
	Texture* m_pTexture;
};

#endif // _TERRAIN_H_