transfered from codeberg

This commit is contained in:
2026-03-26 14:46:39 -05:00
parent 630f28bb7e
commit 5ed2173793
136 changed files with 14932 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
#include "private_terrain.h"
#include "perlin.h"
#include <math.h>
#include <stdbool.h>
#define base_noise_scale 0.01f
#define detail_noise_scale 0.05f
#define base_noise_amplitude 12.0f
#define detail_noise_amplitude 4.0f
#define global_ground_level 0.0f
/**
* Calculates the noise-based height value for the terrain surface
* at the given global world coordinates.
*/
float _get_terrain_height_at_coordinates(int32_t world_coordinate_x,
int32_t world_coordinate_z)
{
float noise_input_x = (float)world_coordinate_x;
float noise_input_z = (float)world_coordinate_z;
float base_elevation = stb_perlin_noise3(noise_input_x * base_noise_scale,
0.0f,
noise_input_z * base_noise_scale,
0,
0,
0);
float detail_variation = stb_perlin_noise3(
noise_input_x * detail_noise_scale,
100.0f,
noise_input_z * detail_noise_scale,
0, 0, 0
);
float calculated_final_height =
base_elevation * base_noise_amplitude +
detail_variation * detail_noise_amplitude +
global_ground_level;
return floorf(calculated_final_height);
}
/**
* Determines if a specific 3D coordinate should be empty (air) based
* on 3D noise patterns to create subterranean cave systems.
*/
bool _is_cave_present_at_coordinates(int32_t world_coordinate_x,
int32_t world_coordinate_y,
int32_t world_coordinate_z,
int32_t surface_height_at_location)
{
if (world_coordinate_y >= surface_height_at_location + 5)
{
return false;
}
float cave_noise_scale = 0.06f;
float noise_density_value = stb_perlin_noise3(
(float)world_coordinate_x * cave_noise_scale,
(float)world_coordinate_y * cave_noise_scale,
(float)world_coordinate_z * cave_noise_scale,
0, 0, 0
);
return noise_density_value > 0.3f;
}

View File

@@ -0,0 +1,23 @@
#ifndef private_terrain_h
#define private_terrain_h
#include <stdbool.h>
#include <stdint.h>
/**
* Calculates the noise-based height value for the terrain surface
* at the given global world coordinates.
*/
float _get_terrain_height_at_coordinates(int32_t world_coordinate_x,
int32_t world_coordinate_z);
/**
* Determines if a specific 3D coordinate should be empty (air) based
* on 3D noise patterns to create subterranean cave systems.
*/
bool _is_cave_present_at_coordinates(int32_t world_coordinate_x,
int32_t world_coordinate_y,
int32_t world_coordinate_z,
int32_t surface_height_at_location);
#endif