-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrain.h
34 lines (27 loc) · 1.03 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
#pragma once
#include "Mesh.h"
#include<vector>
#include<iostream>
#include<cmath>
class Terrain
{
public:
const float size ,maxHeight , x , z;
const int tilling;
int vertexCount=2;
int heightmapWidth, heightmapHeight;
std::vector<std::vector<float>> heights;
/*std::vector<std::vector<float>> heights(
vertexCount,
std::vector<float>(vertexCount));*/
Mesh mesh;
Terrain(int gridX, int gridZ ,const char* heightMap , const std::string& directory, vector<Texture2D> textures, int size, int maxHeight,int tiling);
Terrain(int gridX, int gridZ, const char* heightMap, const std::string& directory, int size, int maxHeight, int tiling);
float getTerrainHeight(float worldX, float worldZ);
private:
void generateTerrain(vector<Texture2D> textures, unsigned char* heightMap);
void generateTerrain(unsigned char* heightMap);
float getHeight(int x, int z, unsigned char* data, int channelCount);
glm::vec3 calcNormal(int x, int z, unsigned char* data);
float barryCentric(glm::vec3 p1, glm::vec3 p2, glm::vec3 p3, glm::vec2 pos);
};