AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
terrain.h
1#pragma once
2
3#include <vector>
4#include <glm/glm.hpp>
5#include <glad/glad.h>
6#include <glm/gtc/matrix_transform.hpp>
7#include <glm/gtc/type_ptr.hpp> // For glm::value_ptr
8#include <stb_image.h>
9
10#include "../rendering/texture.h"
11#include "../rendering/shaderProgram.h"
12#include "../rendering/vao.h"
13#include "../rendering/buffer.h"
14#include "../rendering/camera.h"
15
16#include "texManager.h"
17
18#include "../utils/bbox.h"
19
20namespace Aire {
21
22 class WaterSurface;
23
27 class Terrain
28 {
29 public:
30 std::vector<glm::vec3> vertices;
31 std::vector<glm::vec2> uvs;
32 std::vector<unsigned int> indices;
34 glm::mat4 modelMatrix = glm::mat4(1.0f);
36 TexturePtr heightMap = nullptr;
37 TexturePtr diffuseMap = nullptr;
38 TexturePtr specularMap = nullptr;
39 TexturePtr normalMap = nullptr;
40 TexturePtr roughnessMap = nullptr;
42 glm::vec3 diffuseColor = glm::vec3(0.f, 0.1f, 0.f);
43 glm::vec3 specularColor = glm::vec3(0.05f, 0.05f, 0.05f);
44 float shininessValue = 1.f;
46 std::vector<Aire::WaterSurface*> waterSurfaces;
58 Terrain(TexturePtr heightMap, int numVertices = 200, const float xzScale = 50.f, const float yScale = 10.f,
59 TexturePtr diffuseMap = nullptr, TexturePtr normalMap = nullptr, TexturePtr roughnessmap = nullptr);
60
64 ~Terrain();
65
70 bool saveHeightData();
71
78 float getHeightAt(const float x, const float z);
79
84 float getXZScale() const {
85 return xzScale;
86 }
87
92 float getYScale() const {
93 return yScale;
94 }
95
101 void render(ShaderProgram& prog, Aire::Camera& camera);
102
109 void addWaterSurface(TextureManager* texManager, const Box2D& region, float height);
110
111 private:
113 int numVertices = 200;
114 float xzScale = 50.0f;
115 float yScale = 10.0f;
117 std::vector<std::vector<float>> heightData;
118 };
119
120} // namespace Aire
Definition camera.h:9
A linked OpenGL program.
Definition shaderProgram.h:16
A class that represents a terrain object.
Definition terrain.h:28
float shininessValue
Definition terrain.h:44
glm::mat4 modelMatrix
Definition terrain.h:34
std::vector< Aire::WaterSurface * > waterSurfaces
Definition terrain.h:46
TexturePtr roughnessMap
Definition terrain.h:40
glm::vec3 diffuseColor
Definition terrain.h:42
glm::vec3 specularColor
Definition terrain.h:43
~Terrain()
Destructor for the Terrain object.
Definition terrain.cpp:77
float getYScale() const
Gets the terrain scale factor in the y axis.
Definition terrain.h:92
void render(ShaderProgram &prog, Aire::Camera &camera)
Renders the terrain using a specified shader program and camera.
Definition terrain.cpp:155
Terrain(TexturePtr heightMap, int numVertices=200, const float xzScale=50.f, const float yScale=10.f, TexturePtr diffuseMap=nullptr, TexturePtr normalMap=nullptr, TexturePtr roughnessmap=nullptr)
Constructs a Terrain object with specified parameters.
Definition terrain.cpp:9
std::vector< glm::vec3 > vertices
Definition terrain.h:30
std::vector< glm::vec2 > uvs
Definition terrain.h:31
TexturePtr specularMap
Definition terrain.h:38
TexturePtr heightMap
Definition terrain.h:36
void addWaterSurface(TextureManager *texManager, const Box2D &region, float height)
Adds a water surface to the terrain.
Definition terrain.cpp:228
TexturePtr diffuseMap
Definition terrain.h:37
std::vector< unsigned int > indices
Definition terrain.h:32
float getXZScale() const
Gets the terrain scale factor in the x and z axes.
Definition terrain.h:84
TexturePtr normalMap
Definition terrain.h:39
bool saveHeightData()
Loads the height data from the height map texture.
Definition terrain.cpp:82
float getHeightAt(const float x, const float z)
Retrieves the height of the terrain at a given point in world space.
Definition terrain.cpp:114
Texture manager. Handles texture creation, storage, and deletion.
Definition texManager.h:20
Definition vao.h:8
Utility struct for a 2D bounding-box.
Definition bbox.h:6