Add AABB collision check for BVH collision checks

This commit is contained in:
Yousef Khadadeh 2025-07-21 17:04:50 +03:00
parent f75a5133d5
commit 38a10e0ef4
2 changed files with 16 additions and 12 deletions

View file

@ -85,25 +85,29 @@ void DrawingProgramCache::traverse_bvh_collision_check(const SCollision::Collide
traverse_bvh_collision_check_recursive(bvhRoot, checkAgainstWorld, checkAgainstCam);
}
void DrawingProgramCache::traverse_bvh_collision_check_recursive_tiny(const std::shared_ptr<BVHNode>& bvhNode, bool collided) {
void DrawingProgramCache::traverse_bvh_collision_check_recursive_tiny(const std::shared_ptr<BVHNode>& bvhNode) {
if(bvhNode) {
for(auto& c : bvhNode->components)
c->obj->globalCollisionCheck = collided;
c->obj->globalCollisionCheck = true;
for(auto& p : bvhNode->children)
traverse_bvh_collision_check_recursive_tiny(p, collided);
traverse_bvh_collision_check_recursive_tiny(p);
}
}
void DrawingProgramCache::traverse_bvh_collision_check_recursive(const std::shared_ptr<BVHNode>& bvhNode, const SCollision::ColliderCollection<WorldScalar>& checkAgainstWorld, const SCollision::ColliderCollection<float>& checkAgainstCam) {
if(bvhNode) {
auto& camCoords = drawP.world.drawData.cam.c;
if((camCoords.inverseScale >> DRAWCOMP_COLLIDE_MIN_SHIFT_TINY) >= bvhNode->coords.inverseScale)
traverse_bvh_collision_check_recursive_tiny(bvhNode, SCollision::collide(checkAgainstCam, camCoords.to_space(bvhNode->bounds.min)));
else {
for(auto& c : bvhNode->components)
c->obj->globalCollisionCheck = c->obj->collides_with(drawP.world.drawData.cam.c, checkAgainstWorld, checkAgainstCam, drawP.colliderAllocated);
for(auto& p : bvhNode->children)
traverse_bvh_collision_check_recursive(p, checkAgainstWorld, checkAgainstCam);
if(SCollision::collide(checkAgainstWorld.bounds, bvhNode->bounds)) {
auto& camCoords = drawP.world.drawData.cam.c;
if((camCoords.inverseScale >> DRAWCOMP_COLLIDE_MIN_SHIFT_TINY) >= bvhNode->coords.inverseScale) {
if(SCollision::collide(checkAgainstCam, camCoords.to_space(bvhNode->bounds.min)))
traverse_bvh_collision_check_recursive_tiny(bvhNode);
}
else {
for(auto& c : bvhNode->components)
c->obj->globalCollisionCheck = c->obj->collides_with(drawP.world.drawData.cam.c, checkAgainstWorld, checkAgainstCam, drawP.colliderAllocated);
for(auto& p : bvhNode->children)
traverse_bvh_collision_check_recursive(p, checkAgainstWorld, checkAgainstCam);
}
}
}
}

View file

@ -47,7 +47,7 @@ class DrawingProgramCache {
void invalidate_cache_before_pos(uint64_t placementToInvalidateAt);
private:
void traverse_bvh_collision_check_recursive(const std::shared_ptr<BVHNode>& bvhNode, const SCollision::ColliderCollection<WorldScalar>& checkAgainstWorld, const SCollision::ColliderCollection<float>& checkAgainstCam);
void traverse_bvh_collision_check_recursive_tiny(const std::shared_ptr<BVHNode>& bvhNode, bool collided);
void traverse_bvh_collision_check_recursive_tiny(const std::shared_ptr<BVHNode>& bvhNode);
void build_bvh_node_coords_and_resolution(BVHNode& node);
void refresh_draw_cache(const std::shared_ptr<BVHNode>& bvhNode, const DrawData& drawData);