-
Notifications
You must be signed in to change notification settings - Fork 0
/
Terrain.h
117 lines (88 loc) · 3.3 KB
/
Terrain.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef TERRAIN_H
#define TERRAIN_H
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
#include "glext.h" // Header File for MultiTexturing
#include "BinTree.h" // Handcrafted Binary tree
#include "DiamondSquare.h" // Diamond Square Algorithm, Creates Heightmaps
#include "LinMaths.h" // Handcrafted Mathematical functions
#include "SurfaceCreator.h" // Generates the Terrain Textures
#include "Triangle.h" // Storage class for triangles
#include "Vector.h" // Vector Class
#include "3ds.h"
#define __ARB_ENABLE true
#define MAX_EXTENSION_SPACE 10240
#define MAX_EXTENSION_LENGTH 256
#define MAX_TEXTURES 100
// These are for our multitexture defines
#define GL_TEXTURE0_ARB 0x84C0
#define GL_TEXTURE1_ARB 0x84C1
#define GL_COMBINE_ARB 0x8570
#define GL_RGB_SCALE_ARB 0x8573
typedef struct {
GLubyte *imageData;
GLuint bpp;
GLuint width;
GLuint height;
GLuint texID;
} TextureImage;
struct Plane {
float a, b, c, d;
};
class Terrain {
public:
// Constructor
Terrain();
// Mutators
void DrawTerrain(Vector CurrentCamera,
const Vector viewFrustrum[]); // Draws the terrain and sets the camera points
void GenerateHeightMap(int Iterations, double Height, double HDecay); // Generates a new terrain
void DeleteHeightMap(); // Removes Heightmap from memory
private:
GLvoid BuildLists(double Ratio, int DList, t3DModel Model);
bool LoadTGA(TextureImage *texture, char *filename);
int LoadGLTextures(GLuint *texture, char *filename);
void DrawTriangleTree(Node *Next); // Draws the triangle tree
void ROAM(Node *T); // ROAM algorithm
void ForceSplit(Node *T);
void MergeNode(Node *T);
void SplitTriangle(Node *T);
void ForceMerge(Node *T, Node *End);
bool inFrustrum(const Vector &TestPoint);
double CalculateError(Vector &Left, Vector &Right);
void DrawWater();
void DrawSkyBox();
void DrawTerrainObjects(float x, float y, float z, int pos, int type);
void GenerateTerrainObjects(int Number, int types, int amounta, int amountb);
TextureImage SkyBoxTexture;
PFNGLMULTITEXCOORD1FARBPROC glMultiTexCoord1fARB;
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;
PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB;
BinTree TriangleTree;
DiamondSquare HeightMap;
// Terrain Parameters
Vector CameraEye;
Vector ViewFrustrum[4];
GLuint ShadowTexture;
GLuint SurfaceTexture;
GLuint WaterTexture;
bool isInString(char *string, const char *search);
bool initMultitexture(void);
bool multitextureSupported;
bool useMultitexture;
GLint maxTexelUnits;
float WaterRoll;
float SkyRoll;
Vector *Forests;
CLoad3DS g_Load3ds;
t3DModel g_3DModel;
t3DModel g_3DModel1;
GLuint Object1;
float O1Offset;
GLuint Object2;
float O2Offset;
};
#endif