#include "voxels.h" #include #include namespace deerith { } void sandbox::generate_voxel_cluster(deerith::voxel_cluster_t *cluster) { FastNoiseLite noise; noise.SetNoiseType(FastNoiseLite::NoiseType_Perlin); for (int x = 0; x < deerith::CLUSTER_SIZE; x++) { for (int z = 0; z < deerith::CLUSTER_SIZE; z++) { float world_x = static_cast(cluster->surface_id.x * deerith::CLUSTER_SIZE + x) * deerith::VOXEL_SIZE; float world_z = static_cast(cluster->surface_id.y * deerith::CLUSTER_SIZE + z) * deerith::VOXEL_SIZE; float noise_height_1 = noise.GetNoise(world_x, world_z); float noise_height_2 = noise.GetNoise(world_x * 5 + 101, world_z * 5 + 221); float noise_height_3 = noise.GetNoise(world_x * 8 - 1030, world_z * 8 - 540); // Terrain height in voxel units int terrain_height = static_cast(noise_height_1 * 240.0f * deerith::VOXEL_SIZE); terrain_height += static_cast(noise_height_2 * 20.0f * deerith::VOXEL_SIZE); terrain_height += static_cast(noise_height_3 * 5.0f * deerith::VOXEL_SIZE); // Cluster's bottom position in voxel units int cluster_bottom = cluster->layer * deerith::CLUSTER_SIZE; // Height relative to this cluster int relative_height = terrain_height - cluster_bottom; relative_height = std::clamp(relative_height, 0, deerith::CLUSTER_SIZE); for (int y = 0; y < relative_height; y++) { cluster->__data[x][y][z] = 1; } } } }