Les arbres avec le seed.
This commit is contained in:
parent
732f74de91
commit
e3b59e37eb
@ -33,51 +33,45 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
if (iy < 20)
|
if (iy < 20)
|
||||||
{
|
{
|
||||||
//std::cout << "" << ynoiz << std::endl;
|
//std::cout << "" << ynoiz << std::endl;
|
||||||
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Blocs de montagnes
|
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
|
||||||
}
|
}
|
||||||
else if (iy == 20 || iy == 21) {
|
else if (iy == 20 || iy == 21) {
|
||||||
// Utilisez la partie décimale de la valeur de ynoiz pour déterminer le type de bloc
|
|
||||||
double fractionalPart = ynoiz - static_cast<int>(ynoiz);
|
double fractionalPart = ynoiz - static_cast<int>(ynoiz);
|
||||||
|
|
||||||
// Variation pour iy égal à 24
|
|
||||||
if (iy == 20) {
|
if (iy == 20) {
|
||||||
if (fractionalPart < 0.3) {
|
if (fractionalPart < 0.3) {
|
||||||
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Blocs de montagnes - Grass
|
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Blocs de montagnes - Metal
|
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Variation pour iy égal à 25
|
|
||||||
else if (iy == 21) {
|
else if (iy == 21) {
|
||||||
if (fractionalPart < 0.6) {
|
if (fractionalPart < 0.6) {
|
||||||
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Blocs de montagnes - Grass
|
SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Blocs de montagnes - Metal
|
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Grass des montagnes
|
SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Lacs
|
#pragma region Lacs
|
||||||
|
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix)
|
||||||
|
|
||||||
|
|
||||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs"
|
|
||||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||||
for (int iy = 0; iy < 13; ++iy) {
|
for (int iy = 0; iy < 13; ++iy) {
|
||||||
if (iy < 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
|
if (iy < 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
|
||||||
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); // Partie inférieure du lac
|
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
|
||||||
}
|
}
|
||||||
else if (iy >= 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
|
else if (iy >= 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
|
||||||
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); // Partie supérieure du lac (simulée avec de l'eau)
|
SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,16 +80,19 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
|
|
||||||
#pragma region Arbre
|
#pragma region Arbre
|
||||||
|
|
||||||
|
double valeurRnd = 0;
|
||||||
|
int treeheight = 10;
|
||||||
|
|
||||||
|
int lastTreeX = -1;
|
||||||
|
int lastTreeZ = -1;
|
||||||
|
|
||||||
|
int minDistanceBetweenTrees = 10; // Définir la distance minimale entre les arbres
|
||||||
|
|
||||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) {
|
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) {
|
||||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Vérifiez d'abord que le bloc n'est pas un lac
|
|
||||||
if (GetBlock(ix, 0, iz) != BTYPE_ICE) {
|
if (GetBlock(ix, 0, iz) != BTYPE_ICE) {
|
||||||
// Recalculez la hauteur en fonction de la topographie du terrain
|
float xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4796.;
|
||||||
float xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 5096.;
|
float ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4796.;
|
||||||
float ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 5096.;
|
|
||||||
double height = 0;
|
double height = 0;
|
||||||
for (int i = 0; i < 39; ++i) {
|
for (int i = 0; i < 39; ++i) {
|
||||||
height += simplex.eval(xnoiz, ynoiz);
|
height += simplex.eval(xnoiz, ynoiz);
|
||||||
@ -107,40 +104,48 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
height /= (CHUNK_SIZE_Y / 1.9);
|
height /= (CHUNK_SIZE_Y / 1.9);
|
||||||
height += 15.;
|
height += 15.;
|
||||||
|
|
||||||
|
if (GetBlock(ix, (int)height, iz) == BTYPE_GRASS || (GetBlock(ix, (int)height, iz) == BTYPE_METAL)) {
|
||||||
|
valeurRnd = simplex.eval(xnoiz, ynoiz);
|
||||||
|
|
||||||
double minInput = 3068.84;
|
int distanceThreshold = 20;
|
||||||
double maxInput = 3074.7;
|
|
||||||
double minOutput = 0.0;
|
|
||||||
double maxOutput = 100.0;
|
|
||||||
double valeurRnd = ((ynoiz - minInput) * (maxOutput - minOutput)) / (maxInput - minInput);
|
|
||||||
|
|
||||||
//std::cout << valeurRnd << std::endl;
|
// Vérifie si l'emplacement n'est pas à l'intérieur des lacs
|
||||||
|
bool isInsideLake = false;
|
||||||
|
for (int iy = 0; iy < 13; ++iy) {
|
||||||
|
if (GetBlock(ix, iy, iz) == BTYPE_ICE) {
|
||||||
|
isInsideLake = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInsideLake && ((valeurRnd > -0.4 && valeurRnd < -0.38) || (valeurRnd > -0.35 && valeurRnd < -0.31)
|
||||||
|
|| (valeurRnd > 0.3 && valeurRnd < 0.32) || (valeurRnd > 0.37 && valeurRnd < 0.39))
|
||||||
|
) {
|
||||||
|
if (lastTreeX == -1 || abs(ix - lastTreeX) > minDistanceBetweenTrees || abs(iz - lastTreeZ) > minDistanceBetweenTrees) {
|
||||||
|
if (valeurRnd < 0.1)
|
||||||
|
treeheight = 10;
|
||||||
|
else {
|
||||||
|
treeheight = valeurRnd * 20;
|
||||||
|
if (treeheight < 5)
|
||||||
|
treeheight = 5;
|
||||||
|
}
|
||||||
|
|
||||||
// Ajout des arbres uniquement sur des blocs de type BTYPE_GRASS et avec une probabilité réduite
|
PlaceTree(ix, height, iz, treeheight);
|
||||||
if (GetBlock(ix, 0, iz) != BTYPE_ICE && GetBlock(ix, (int)height, iz) == BTYPE_GRASS) {
|
|
||||||
// Vérifiez si vous souhaitez placer un arbre en fonction de votre logique de génération
|
|
||||||
if (valeurRnd < 20) {
|
|
||||||
// Calculez la position et la hauteur de l'arbre
|
|
||||||
|
|
||||||
// Exemple : Place un arbre à la position calculée avec une hauteur donnée
|
|
||||||
//
|
|
||||||
//PlaceTree(ix, height, iz, 10, 5 <= 5);
|
|
||||||
|
|
||||||
|
lastTreeX = ix;
|
||||||
|
lastTreeZ = iz;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//else {
|
//else {
|
||||||
// input.seekg(0, std::ios_base::end);
|
// input.seekg(0, std::ios_base::end);
|
||||||
// int size = input.tellg();
|
// int size = input.tellg();
|
||||||
@ -177,19 +182,18 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chunk::PlaceTree(int x, int y, int z, int height, int valeurRnd)
|
void Chunk::PlaceTree(int x, int y, int z, int height) {
|
||||||
{
|
|
||||||
// Place le tronc
|
for (int iy = 0; iy < height + 1; ++iy) {
|
||||||
for (int iy = 0; iy < height; ++iy) {
|
|
||||||
SetBlock(x, y + iy, z, BTYPE_LAST, nullptr);
|
SetBlock(x, y + iy, z, BTYPE_LAST, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place les feuilles autour du tronc
|
int foliageHeight = height / 2;
|
||||||
int foliageHeight = height - 2;
|
|
||||||
for (int dy = 1; dy < foliageHeight; ++dy) {
|
for (int dy = 1; dy < foliageHeight; ++dy) {
|
||||||
for (int dx = -2; dx <= 2; ++dx) {
|
for (int dx = -3; dx <= 3; ++dx) {
|
||||||
for (int dz = -2; dz <= 2; ++dz) {
|
for (int dz = -3; dz <= 3; ++dz) {
|
||||||
if (valeurRnd < 50) {
|
if (dx * dx + dy * dy + dz * dz < 10) {
|
||||||
SetBlock(x + dx, y + height + dy, z + dz, BTYPE_DIRT, nullptr);
|
SetBlock(x + dx, y + height + dy, z + dz, BTYPE_DIRT, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,6 +202,9 @@ void Chunk::PlaceTree(int x, int y, int z, int height, int valeurRnd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Chunk::~Chunk() {
|
Chunk::~Chunk() {
|
||||||
/*if (m_isModified) {
|
/*if (m_isModified) {
|
||||||
char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z];
|
char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z];
|
||||||
@ -254,6 +261,8 @@ void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Chunk::IsDirty() const { return m_isDirty; }
|
bool Chunk::IsDirty() const { return m_isDirty; }
|
||||||
|
|
||||||
void Chunk::MakeDirty() { m_isDirty = true; }
|
void Chunk::MakeDirty() { m_isDirty = true; }
|
||||||
|
@ -27,7 +27,7 @@ class Chunk {
|
|||||||
BlockType GetBlock(int x, int y, int z);
|
BlockType GetBlock(int x, int y, int z);
|
||||||
void CheckNeighbors(unsigned int x, unsigned int z, World* world);
|
void CheckNeighbors(unsigned int x, unsigned int z, World* world);
|
||||||
void GetPosition(unsigned int& x, unsigned int& y) const;
|
void GetPosition(unsigned int& x, unsigned int& y) const;
|
||||||
void PlaceTree(int x, int y, int z, int height,int valeurRnd);
|
void PlaceTree(int x, int y, int z, int height);
|
||||||
bool IsDirty() const;
|
bool IsDirty() const;
|
||||||
void MakeDirty();
|
void MakeDirty();
|
||||||
void MakeClean();
|
void MakeClean();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user