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,20 +85,23 @@ void DrawingProgramCache::traverse_bvh_collision_check(const SCollision::Collide
traverse_bvh_collision_check_recursive(bvhRoot, checkAgainstWorld, checkAgainstCam); 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) { if(bvhNode) {
for(auto& c : bvhNode->components) for(auto& c : bvhNode->components)
c->obj->globalCollisionCheck = collided; c->obj->globalCollisionCheck = true;
for(auto& p : bvhNode->children) 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) { 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) { if(bvhNode) {
if(SCollision::collide(checkAgainstWorld.bounds, bvhNode->bounds)) {
auto& camCoords = drawP.world.drawData.cam.c; auto& camCoords = drawP.world.drawData.cam.c;
if((camCoords.inverseScale >> DRAWCOMP_COLLIDE_MIN_SHIFT_TINY) >= bvhNode->coords.inverseScale) 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))); if(SCollision::collide(checkAgainstCam, camCoords.to_space(bvhNode->bounds.min)))
traverse_bvh_collision_check_recursive_tiny(bvhNode);
}
else { else {
for(auto& c : bvhNode->components) for(auto& c : bvhNode->components)
c->obj->globalCollisionCheck = c->obj->collides_with(drawP.world.drawData.cam.c, checkAgainstWorld, checkAgainstCam, drawP.colliderAllocated); c->obj->globalCollisionCheck = c->obj->collides_with(drawP.world.drawData.cam.c, checkAgainstWorld, checkAgainstCam, drawP.colliderAllocated);
@ -107,6 +110,7 @@ void DrawingProgramCache::traverse_bvh_collision_check_recursive(const std::shar
} }
} }
} }
}
void DrawingProgramCache::traverse_bvh_run_function(const SCollision::AABB<WorldScalar>& aabb, std::function<bool(const std::shared_ptr<BVHNode> node, const std::vector<CollabListType::ObjectInfoPtr>& components)> f) { void DrawingProgramCache::traverse_bvh_run_function(const SCollision::AABB<WorldScalar>& aabb, std::function<bool(const std::shared_ptr<BVHNode> node, const std::vector<CollabListType::ObjectInfoPtr>& components)> f) {
f(nullptr, unsortedComponents); f(nullptr, unsortedComponents);

View file

@ -47,7 +47,7 @@ class DrawingProgramCache {
void invalidate_cache_before_pos(uint64_t placementToInvalidateAt); void invalidate_cache_before_pos(uint64_t placementToInvalidateAt);
private: 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(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 build_bvh_node_coords_and_resolution(BVHNode& node);
void refresh_draw_cache(const std::shared_ptr<BVHNode>& bvhNode, const DrawData& drawData); void refresh_draw_cache(const std::shared_ptr<BVHNode>& bvhNode, const DrawData& drawData);