Generated first chunk of terrain data.

This commit is contained in:
Warwick 2022-08-09 13:41:55 +01:00
parent 5c135950e0
commit 9fa18286cb
3 changed files with 41 additions and 0 deletions

21
src/Terrain.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "Terrain.h"
Terrain::Terrain() {
// Create location to store noise values.
std::vector<float> noiseOutput(16 * 16 * 16);
// Generate noise to the outputs dimentions
this->fnGenerator->GenUniformGrid3D(noiseOutput.data(), 0, 0, 0, 16, 16, 16,
0.2f, 0);
int index = 0;
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
error.log(std::to_string(x) + " " + std::to_string(y) + " " +
std::to_string(z) + ": " +
std::to_string(noiseOutput[index++]));
}
}
}
}

16
src/Terrain.h Normal file
View file

@ -0,0 +1,16 @@
#pragma once
#include "Error.h"
#include <FastNoise/FastNoise.h>
#include <vector>
class Terrain {
private:
Error error = Error("Terrain");
// Favourite noise generated values using the NoiseTool for now:
FastNoise::SmartNode<> fnGenerator = FastNoise::NewFromEncodedNodeTree(
"DgAIAAAAAAAAQBkAAwAAAIA/AQcAAAAAAD8AAAAAAAAAAABA");
public:
Terrain();
};

View file

@ -12,6 +12,7 @@
// Objects
#include "Mesh.h"
#include "Model.h"
#include "Terrain.h"
// Include error class
#include "Error.h"
@ -95,6 +96,9 @@ int main(int argc, char **argv) {
// glCullFace(GL_FRONT);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
// Initialise terrain.
Terrain terrain = Terrain();
// Game loop
bool running = true;
while (running) {