From 2e3b0eefc942bbf720baa153286141b7039f291b Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 8 Jul 2025 17:43:00 -0600 Subject: Still sucks too much --- src/world.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 902e6c1..e280015 100644 --- a/src/world.c +++ b/src/world.c @@ -47,37 +47,55 @@ void buildWorldBVH(World* world) continue; } + // Average out distances and find current bounding box. float distance = 0.0; + Vector3 min = entities[index].position; + Vector3 max = entities[index].position; for (int innerIndex = 0; innerIndex < leafIndex; ++innerIndex) { distance += Vector3Distance( entities[leaf->entities[innerIndex]].position, entities[index].position); + min = Vector3Min(min, entities[leaf->entities[innerIndex]].position); + min = Vector3Min(min, entities[index].position); + max = Vector3Max(max, entities[leaf->entities[innerIndex]].position); + max = Vector3Max(max, entities[index].position); } + BoundingBox overlapBox = (BoundingBox){min, max}; distance /= (float)leafIndex; - // Check for overlap. - for (int overlapNode = 0; overlapNode < nodeIndex; ++overlapNode) + // Check if laptop will be caused. + for (int overlapIndex = 0; overlapIndex < WORLD_ENTITY_MAX; + ++overlapIndex) { - Vector3 nodeLocation = Vector3Scale( - Vector3Add(world->bvhTest[overlapNode].box.min, - world->bvhTest[overlapNode].box.max), 0.5); + if (!grouped[overlapIndex]) + { + continue; + } - Ray ray = (Ray){ - .position = entities[index].position, - .direction = Vector3Normalize( - Vector3Subtract(nodeLocation, entities[index].position)) - }; + bool isPartOf = false; - RayCollision overlapResult = GetRayCollisionBox( - ray, world->bvhTest[overlapNode].box); + for (int partOfIndex = 0; partOfIndex < leafIndex + 1; ++partOfIndex) + { + if (overlapIndex == leaf->entities[partOfIndex]) + { + isPartOf = true; + break; + } + } + + if (isPartOf) + { + continue; + } - if (overlapResult.hit && overlapResult.distance < distance) + // TODO: Make use of entity bounding boxes. + if (CheckCollisionBoxSphere( + overlapBox, entities[overlapIndex].position, 0.5)) { - // Dont stop overlap but make it less likely. - distance *= 10.0; + distance *= BVH_OVERLAP_MULTIPLIER; break; } } -- cgit v1.2.3