diff options
author | nathan <nathansmith@disroot.org> | 2025-07-24 02:38:23 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-07-24 02:38:23 +0000 |
commit | 9d4afb36347a49251f0968e898089d4ff46390ed (patch) | |
tree | 9cf545983e9b213db6448a303995112f17547c54 | |
parent | 1edd7f510bb901726f4e47c7d132f1abb06c4b10 (diff) | |
download | FindThings-9d4afb36347a49251f0968e898089d4ff46390ed.tar.gz FindThings-9d4afb36347a49251f0968e898089d4ff46390ed.tar.bz2 FindThings-9d4afb36347a49251f0968e898089d4ff46390ed.zip |
Existance is stuppa
-rw-r--r-- | src/world.c | 46 | ||||
-rw-r--r-- | src/world.h | 2 |
2 files changed, 44 insertions, 4 deletions
diff --git a/src/world.c b/src/world.c index 7a3559e..52b91b1 100644 --- a/src/world.c +++ b/src/world.c @@ -489,11 +489,51 @@ float getWorldHeightAtLocation(const World* world, float x, float y) return 0.0; } -WorldUID castRayAtWorld(const World* world, Ray ray) +WorldUID castRayBVH(const World* world, BVHNode node, Ray ray, int* tests) { - WorldUID uid = -1; + if (!GetRayCollisionBox(ray, node.box).hit) + { + return -1; + } + + if (tests != NULL) + { + ++*tests; + } + + // Leaf node. + if (node.branchCount == 0) + { + for (int index = 0; index < BVH_MAX; ++index) + { + if (node.entities[index] != -1 && + GetRayCollisionBox( + ray, + world->entities[node.entities[index]].box).hit) + { + return node.entities[index]; + } + } + } + else // Subtree. + { + for (int index = 0; index < node.branchCount; ++index) + { + WorldUID uid = castRayBVH(world, *node.branches[index], ray, tests); - return uid; + if (uid != -1) + { + return uid; + } + } + } + + return -1; +} + +WorldUID castRayAtWorld(const World* world, Ray ray, int* tests) +{ + return castRayBVH(world, world->bvh, ray, tests); } // Abortions are good. Get more abortions. diff --git a/src/world.h b/src/world.h index 5482b0b..3c18e9f 100644 --- a/src/world.h +++ b/src/world.h @@ -42,6 +42,6 @@ void freeWorld(World world); // Dam, I wanta live in a free world ): float getWorldHeightAtLocation(const World* world, float x, float y); -WorldUID castRayAtWorld(const World* world, Ray ray); +WorldUID castRayAtWorld(const World* world, Ray ray, int* tests); #endif |