diff options
| author | nathan <nathansmith@disroot.org> | 2026-01-11 13:13:36 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2026-01-11 13:13:36 +0000 |
| commit | e853966be38ae6c5319df137c3b04a86e52b562b (patch) | |
| tree | 76a7b271ac1795098ebb8d797a523fbcbfc54080 /src/world.c | |
| parent | 013ac4a2f4ae24d71f425f31edd77a8e29ed1da8 (diff) | |
| download | FindThings-e853966be38ae6c5319df137c3b04a86e52b562b.tar.gz FindThings-e853966be38ae6c5319df137c3b04a86e52b562b.tar.bz2 FindThings-e853966be38ae6c5319df137c3b04a86e52b562b.zip | |
Diffstat (limited to 'src/world.c')
| -rw-r--r-- | src/world.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/world.c b/src/world.c index 0096dbe..b53fb57 100644 --- a/src/world.c +++ b/src/world.c @@ -1065,7 +1065,7 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, bool allowAll, { for (int index = 0; index < BVH_MAX; ++index) { - if (node.entities[index] != -1 && + if (node.entities[index] != ENTITY_NONE && GetRayCollisionBox( ray, world->entities[node.entities[index]].box).hit) @@ -1080,6 +1080,10 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, bool allowAll, { continue; } + else if (world->entities[node.entities[index]].id == ENTITY_NONE) + { + continue; + } if (distance < *closestDistance) { @@ -1108,4 +1112,57 @@ WorldUID castRayAtWorld(const World* world, Ray ray, bool allowAll, return uid; } +// This turned out to not be needed lol. +WorldUID checkBoxCollisionBVH(const World* world, BVHNode node, + BoundingBox box, bool allowAll) +{ + if (!CheckCollisionBoxes(box, node.box)) + { + return ENTITY_NONE; + } + + // Leaf node. + if (node.branchCount == 0) + { + for (int index = 0; index < BVH_MAX; ++index) + { + if (node.entities[index] != ENTITY_NONE && + CheckCollisionBoxes( + box, + world->entities[node.entities[index]].box)) + { + // Don't include things that can't be selected. + if (!allowAll && + !entityCanBeSelected(world->entities[node.entities[index]].id)) + { + continue; + } + + return node.entities[index]; + } + } + } + else // Subtree. + { + for (int index = 0; index < node.branchCount; ++index) + { + WorldUID uid = checkBoxCollisionBVH(world, *node.branches[index], box, + allowAll); + + if (uid != ENTITY_NONE) + { + return uid; + } + } + } + + return ENTITY_NONE; +} + +WorldUID checkBoxCollisionWithWorld(const World* world, BoundingBox box, + bool allowAll) +{ + return checkBoxCollisionBVH(world, world->bvh, box, allowAll); +} + // Abortions are good. Get more abortions. |
