diff options
author | nathan <nathan@disroot.org> | 2025-07-09 09:46:18 +0000 |
---|---|---|
committer | nathan <nathan@disroot.org> | 2025-07-09 09:46:18 +0000 |
commit | 204ad4a59f782ce7faf2f0418b33538cf15a84cb (patch) | |
tree | 263b6d149585ab6585b01cc7ca39a46ddac3f4d7 /src/world.c | |
parent | d594afee3b6c55f24ecf05663b688ea488f073e6 (diff) | |
download | FindThings-204ad4a59f782ce7faf2f0418b33538cf15a84cb.tar.gz FindThings-204ad4a59f782ce7faf2f0418b33538cf15a84cb.tar.bz2 FindThings-204ad4a59f782ce7faf2f0418b33538cf15a84cb.zip |
Using the entity bounding box for something now
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 27 |
1 files changed, 15 insertions, 12 deletions
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; } |