From a859191288d7de81b52434cfa3cebcfd2aadab2b Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 8 Jul 2025 22:51:18 -0600 Subject: Slight changes --- src/world.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index c633e44..26ee3b9 100644 --- a/src/world.c +++ b/src/world.c @@ -21,7 +21,7 @@ void buildWorldBVH(World* world) for (int leafIndex = 0; leafIndex < BVH_MAX; ++leafIndex) { int closest = -1; - float closestDistance = world->size.x * world->size.z * 2.0; + float closestDistance = world->size.x; // Find closest. for (int index = 0; index < WORLD_ENTITY_MAX; ++index) @@ -131,7 +131,6 @@ void buildWorldBVH(World* world) world->bvhTest[world->bvhTestSize] = leaf; ++world->bvhTestSize; - printf("size: %d\n", world->bvhTestSize); } // test @@ -174,12 +173,14 @@ World createWorld(int seed) Entity entity = createEntity(seed % ENTITY_COUNT, Vector3Zero()); entity.position.x = FT_RANDOM16(seed) % (int)world.size.x; entity.position.z = FT_RANDOM16(seed) % (int)world.size.z; - entity.position.y = getWorldHeightAtLocation(world, entity.position.x, + entity.position.y = getWorldHeightAtLocation(&world, entity.position.x, entity.position.z) + 1.0; world.entities[index] = entity; } + double currentTime = GetTime(); buildWorldBVH(&world); + printf("%lf\n", GetTime() - currentTime); return world; } @@ -207,15 +208,15 @@ void freeWorld(World world) UnloadModel(world.heightmap); } -float getWorldHeightAtLocation(World world, float x, float y) +float getWorldHeightAtLocation(const World* world, float x, float y) { - float toMapX = (float)world.texture.width / world.size.x; - float toMapY = (float)world.texture.height / world.size.z; + float toMapX = (float)world->texture.width / world->size.x; + float toMapY = (float)world->texture.height / world->size.z; int pixelX = x * toMapX; int pixelY = y * toMapY; - int verticeStart = (pixelY * (world.texture.width - 1) + pixelX) * 18; - float* vertices = &world.heightmap.meshes[0].vertices[verticeStart]; + int verticeStart = (pixelY * (world->texture.width - 1) + pixelX) * 18; + float* vertices = &world->heightmap.meshes[0].vertices[verticeStart]; // Clamp x and y to prevent ray being out of bounds. Vector2 min = (Vector2){vertices[0], vertices[2]}; @@ -232,7 +233,7 @@ float getWorldHeightAtLocation(World world, float x, float y) Ray ray = (Ray){ .position = (Vector3){ Clamp(x, min.x, max.x), - FLT_MAX_EXP, + world->size.y + 10.0, Clamp(y, min.y, max.y)}, .direction = (Vector3){0.0, -1.0, 0.0} }; -- cgit v1.2.3