#pragma once // ============================================================================ // terrain.h - 程序化地形 // ============================================================================ #include #include "../Rendering/mesh.h" #define TERRAIN_MAX_HEIGHTMAP_SIZE 256 typedef struct { float* data; int size; } TerrainHeightmap; typedef struct { int chunks_x; int chunks_z; int vertices_per_chunk; float chunk_size; float height_scale; float uv_scale; } TerrainConfig; typedef struct { TerrainConfig config; TerrainHeightmap heightmap; Mesh* mesh; ID3D11Device* device; } Terrain; // 默认配置 TerrainConfig terrain_default_config(void); // 高度图 TerrainHeightmap terrain_heightmap_create(int size); void terrain_heightmap_destroy(TerrainHeightmap* hm); void terrain_heightmap_fill_noise(TerrainHeightmap* hm, int seed, float scale, float amplitude); float terrain_heightmap_sample(const TerrainHeightmap* hm, float x, float z); // 地形对象 Terrain* terrain_create(ID3D11Device* dev, const TerrainConfig* config); void terrain_destroy(Terrain* terrain); // 从世界坐标采样高度 (用于相机/角色贴地) float terrain_get_height(const Terrain* terrain, float world_x, float world_z); // 网格生成 Mesh* terrain_mesh_create(ID3D11Device* dev, const TerrainHeightmap* hm, float size, float height_scale, float uv_scale); // 噪声工具(供分块管理器复用) float hash_noise(int x, int z, int seed); float fbm_noise(float x, float z, int seed, int octaves, float persistence);