-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrain.h
53 lines (43 loc) · 889 Bytes
/
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
#pragma once
#define HEIGHT_MAP 20.0
class Terrain : public PrimitiveObject
{
private:
int w; //Width
int l; //Length
float** hs; //Heights
glm::vec3** normals;
bool computedNormals; //Whether normals is up-to-date
public:
Terrain(const char * file, GLuint tex);
~Terrain();
int width()
{
return w;
}
int length()
{
return l;
}
//Sets the height at (x, z) to y
void setHeight(int x, int z, float y)
{
hs[z][x] = y;
computedNormals = false;
}
//Returns the height at (x, z)
float getHeight(int x, int z)
{
return hs[z][x];
}
//Computes the normals, if they haven't been computed yet
void computeNormals();
void pushTerrainVertex(GLuint x, GLuint z);
//Returns the normal at (x, z)
glm::vec3 getNormal(int x, int z) {
if (!computedNormals) {
computeNormals();
}
return normals[z][x];
}
};