From 204ad4a59f782ce7faf2f0418b33538cf15a84cb Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 9 Jul 2025 03:46:18 -0600 Subject: Using the entity bounding box for something now --- src/world.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 94b6400..3d4682d 100644 --- a/src/world.c +++ b/src/world.c @@ -46,16 +46,16 @@ size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world) entities[index].position); overlapBox.min = Vector3Min( overlapBox.min, - entities[leaf.entities[innerIndex]].position); + entities[leaf.entities[innerIndex]].box.min); overlapBox.min = Vector3Min( overlapBox.min, - entities[index].position); + entities[index].box.min); overlapBox.max = Vector3Max( overlapBox.max, - entities[leaf.entities[innerIndex]].position); + entities[leaf.entities[innerIndex]].box.max); overlapBox.max = Vector3Max( overlapBox.max, - entities[index].position); + entities[index].box.max); } distance /= (float)leafIndex; @@ -100,8 +100,8 @@ size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world) } // Get bounding box. - leaf.box.min = world->entities[leaf.entities[0]].position; - leaf.box.max = world->entities[leaf.entities[0]].position; + leaf.box.min = world->entities[leaf.entities[0]].box.min; + leaf.box.max = world->entities[leaf.entities[0]].box.max; for (int index = 1; index < BVH_MAX; ++index) { @@ -112,10 +112,10 @@ size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world) leaf.box.min = Vector3Min( leaf.box.min, - world->entities[leaf.entities[index]].position); + world->entities[leaf.entities[index]].box.min); leaf.box.max = Vector3Max( leaf.box.max, - world->entities[leaf.entities[index]].position); + world->entities[leaf.entities[index]].box.max); } leafs[leafsSize] = leaf; @@ -193,10 +193,13 @@ World createWorld(int seed) FT_RANDOM16(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.z) + 1.0; + Vector3 position; + position.x = FT_RANDOM16(seed) % (int)world.size.x; + position.z = FT_RANDOM16(seed) % (int)world.size.z; + position.y = getWorldHeightAtLocation(&world, + position.x, position.z) + 1.0; + setEntityPosition(&entity, position); + world.entities[index] = entity; } -- cgit v1.2.3