diff options
author | nathan <nathansmith@disroot.org> | 2025-07-06 18:57:20 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-07-06 18:57:20 +0000 |
commit | 1abde5cdf85269597b180d5e88e9d62798fc893c (patch) | |
tree | 02bc5c59660153b1d2c96b7d556b10d65dd13c78 | |
parent | 255c938a77f8a73229b1867aadd10f3bf9c44f2e (diff) | |
download | FindThings-1abde5cdf85269597b180d5e88e9d62798fc893c.tar.gz FindThings-1abde5cdf85269597b180d5e88e9d62798fc893c.tar.bz2 FindThings-1abde5cdf85269597b180d5e88e9d62798fc893c.zip |
Going wonderful (:
-rw-r--r-- | src/world.c | 22 | ||||
-rw-r--r-- | src/world.h | 2 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/world.c b/src/world.c index 3513042..1fdb1ce 100644 --- a/src/world.c +++ b/src/world.c @@ -4,16 +4,21 @@ World createWorld(const Assets* assets) { World world; - world.size = (Vector3){1000.0, 20.0, 1000.0}; - world.image = &assets->images[HEIGHT_MAP_IMAGE]; + world.size = (Vector3){1000.0, 100.0, 1000.0}; + + // Heightmap image. + Image image = GenImagePerlinNoise(1024, 1024, 0, 0, 2.0); // Heightmap. - Mesh mesh = GenMeshHeightmap(*world.image, world.size); + Mesh mesh = GenMeshHeightmap(image, world.size); world.heightmap = LoadModelFromMesh(mesh); + world.texture = LoadTextureFromImage(image); world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = - assets->textures[HEIGHT_MAP_TEXTURE]; + world.texture; + + UnloadImage(image); - uint32_t seed = 57; + int seed = 57; // Entities. for (int index = 0; index < WORLD_ENTITY_MAX; ++index) @@ -46,12 +51,13 @@ void updateWorld(World* world, Game* game) void freeWorld(World world) { + UnloadTexture(world.texture); UnloadModel(world.heightmap); } float getWorldPixelHeight(World world, int x, int y) { - int verticeStart = (y * (world.image->width - 1) + x) * 18; + int verticeStart = (y * (world.texture.width - 1) + x) * 18; float height = 0.0; int count = 0; @@ -66,8 +72,8 @@ float getWorldPixelHeight(World world, int x, int y) float getWorldHeightAtLocation(World world, float x, float y) { - float toMapX = (float)world.image->width / world.size.x; - float toMapY = (float)world.image->height / world.size.z; + float toMapX = (float)world.texture.width / world.size.x; + float toMapY = (float)world.texture.height / world.size.z; int pixelX = roundf((float)x * toMapX); int pixelY = roundf((float)y * toMapY); diff --git a/src/world.h b/src/world.h index 81512d0..980f315 100644 --- a/src/world.h +++ b/src/world.h @@ -24,7 +24,7 @@ typedef struct BVHNode { typedef struct { Vector3 size; - const Image* image; + Texture texture; Model heightmap; Entity entities[WORLD_ENTITY_MAX]; BVHNode bvh; |