aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathan@disroot.org>2025-07-09 04:51:18 +0000
committernathan <nathan@disroot.org>2025-07-09 04:51:18 +0000
commita859191288d7de81b52434cfa3cebcfd2aadab2b (patch)
tree4a6b0f632846d3b9a60f4f51c59339072f2df2eb
parent4819292821b51083538d4d4880e90d0d3314f839 (diff)
downloadFindThings-a859191288d7de81b52434cfa3cebcfd2aadab2b.tar.gz
FindThings-a859191288d7de81b52434cfa3cebcfd2aadab2b.tar.bz2
FindThings-a859191288d7de81b52434cfa3cebcfd2aadab2b.zip
Slight changes
-rw-r--r--src/entity.c4
-rw-r--r--src/player.c2
-rw-r--r--src/world.c19
-rw-r--r--src/world.h4
4 files changed, 17 insertions, 12 deletions
diff --git a/src/entity.c b/src/entity.c
index ac3606b..0fe6366 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -8,6 +8,10 @@ Entity createEntity(EntityId id, Vector3 position)
entity.id = id;
entity.position = position;
+ // Test boundingbox.
+ entity.box.min = Vector3SubtractValue(position, 1.0);
+ entity.box.max = Vector3AddValue(position, 1.0);
+
return entity;
}
diff --git a/src/player.c b/src/player.c
index f6fdb7a..de1eaa1 100644
--- a/src/player.c
+++ b/src/player.c
@@ -22,7 +22,7 @@ Player createPlayer()
void updatePlayerHeight(Player* player, Game* game)
{
float height = getWorldHeightAtLocation(
- game->world, player->position.x, player->position.z) + PLAYER_HEIGHT;
+ &game->world, player->position.x, player->position.z) + PLAYER_HEIGHT;
player->position.y = height;
}
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}
};
diff --git a/src/world.h b/src/world.h
index c086f1d..69c2015 100644
--- a/src/world.h
+++ b/src/world.h
@@ -11,7 +11,7 @@
#define BVH_LEAF_COUNT 250
#define BVH_OVERLAP_MULTIPLIER 100.0
-#define WORLD_ENTITY_MAX 3000
+#define WORLD_ENTITY_MAX 1000
#define WORLD_SIZE (Vector3){1000.0, 100.0, 1000.0}
#define WORLD_IMAGE_WIDTH 100
#define WORLD_IMAGE_HEIGHT 100
@@ -42,6 +42,6 @@ void updateWorld(World* world, Game* game);
void freeWorld(World world);
// Dam, I wanta live in a free world ):
-float getWorldHeightAtLocation(World world, float x, float y);
+float getWorldHeightAtLocation(const World* world, float x, float y);
#endif