aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-07-08 23:43:00 +0000
committernathan <nathansmith@disroot.org>2025-07-08 23:43:00 +0000
commit2e3b0eefc942bbf720baa153286141b7039f291b (patch)
tree46afe2111358cf4154105b4faa085bf253c825a1
parentf3a07a4e98444c7d98df8b3f3b57e2136477f87f (diff)
downloadFindThings-2e3b0eefc942bbf720baa153286141b7039f291b.tar.gz
FindThings-2e3b0eefc942bbf720baa153286141b7039f291b.tar.bz2
FindThings-2e3b0eefc942bbf720baa153286141b7039f291b.zip
Still sucks too much
-rw-r--r--src/player.c2
-rw-r--r--src/world.c48
-rw-r--r--src/world.h5
3 files changed, 37 insertions, 18 deletions
diff --git a/src/player.c b/src/player.c
index 9c66627..f6fdb7a 100644
--- a/src/player.c
+++ b/src/player.c
@@ -71,7 +71,7 @@ void updatePlayer(Player* player, Game* game)
player->velocity.x += -sinf(cameraAngle->x + (PI / 2.0));
}
- player->velocity = Vector3Scale(player->velocity, 10.0);
+ player->velocity = Vector3Scale(player->velocity, 20.0);
// Apply velocity.
player->position = Vector3Add(
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;
}
}
diff --git a/src/world.h b/src/world.h
index 4bf5d79..46bd248 100644
--- a/src/world.h
+++ b/src/world.h
@@ -7,8 +7,9 @@
#ifndef WORLD_H
#define WORLD_H
-#define BVH_MAX 2 // Max entities per node.
-#define BVH_LEAF_COUNT 500
+#define BVH_MAX 4 // Max entities per node.
+#define BVH_LEAF_COUNT 250
+#define BVH_OVERLAP_MULTIPLIER 100.0
#define WORLD_ENTITY_MAX 1000
#define WORLD_SIZE (Vector3){1000.0, 100.0, 1000.0}