You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

83 lines
2.2 KiB

/*
* =====================================================================================
*
* Filename: terraingen.cpp
*
* Description: Terrain generator source
*
* Version: 1.0
* Created: 05/08/2014 06:45:02 PM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include "terraingen.h"
#include "chunk.h"
#include "mathplus.h"
#include "terrain/noise.h"
#include "terrain/ygradient.h"
#include <iostream>
#include <time.h>
#include <glm/glm.hpp>
namespace vtk {
TerrainGen::TerrainGen() {
mNoise = new YGradient(0.0, 128.0);
mTerrainScale = 32.0;
}
void TerrainGen::generateChunk(Chunk* chunk) {
//first pass
for (int i = 0; i < 16; i++) { //x
for (int j = 0; j < 16; j++) { //y
for (int k = 0; k < 16; k++) { //z
double nVal = mNoise->get3D(
(double)(chunk->chunkPos.x * 16 + i),
(double)(chunk->chunkPos.y * 16 + j),
(double)(chunk->chunkPos.z * 16 + k));
if (nVal <= 0.0) {
chunk->setVoxelType(i,j,k,1);
} else {
chunk->setVoxelType(i,j,k,0);
}
/*
glm::dvec3 pos((double)(chunk->chunkPos.x * 16 + i) * terrainScale,
(double)(chunk->chunkPos.y * 16 + j) * terrainScale,
(double)(chunk->chunkPos.z * 16 + k) * terrainScale);
if (selectorMod.GetValue(pos.x, pos.y, pos.z) <= 0.0) {
if (selectorMod.GetValue(pos.x, (double)(chunk->chunkPos.y * 16 + j + 1) * terrainScale, pos.z) >= 0.0) {
chunk->setVoxelType(i,j,k,2);
} else {
chunk->setVoxelType(i,j,k,1);
}
}
*/
}
}
}
//grass on top
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
for (int k = 0; k < 16; k++) {
if (chunk->getVoxelType(i,j,k) != 0) {
//if (chunk->getVoxelType(i,j+1,k) == 0) {
// chunk->setVoxelType(i,j,k,2);
//}
}
}
}
}
}
}