From 42d39f977255745d5c6e1d70f765e4a9eca29dca Mon Sep 17 00:00:00 2001 From: TheNumbat Date: Wed, 7 Apr 2021 12:44:13 -0700 Subject: [PATCH] use is leaf in bvh --- src/rays/bvh.h | 2 ++ src/student/bvh.inl | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rays/bvh.h b/src/rays/bvh.h index 47e7f74..aea67ba 100644 --- a/src/rays/bvh.h +++ b/src/rays/bvh.h @@ -31,9 +31,11 @@ public: private: class Node { + BBox bbox; size_t start, size, l, r; + // A node is a leaf if l == r, since all interior nodes must have distinct children bool is_leaf() const; friend class BVH; }; diff --git a/src/student/bvh.inl b/src/student/bvh.inl index 71f390e..59a6b53 100644 --- a/src/student/bvh.inl +++ b/src/student/bvh.inl @@ -77,6 +77,8 @@ template BVH BVH::copy() const { } template bool BVH::Node::is_leaf() const { + + // A node is a leaf if l == r, since all interior nodes must have distinct children return l == r; } @@ -145,7 +147,7 @@ size_t BVH::visualize(GL::Lines& lines, GL::Lines& active, size_t lev edge(Vec3{max.x, min.y, min.z}, Vec3{max.x, max.y, min.z}); edge(Vec3{max.x, min.y, min.z}, Vec3{max.x, min.y, max.z}); - if(node.l && node.r) { + if(!node.is_leaf()) { tstack.push({node.l, lvl + 1}); tstack.push({node.r, lvl + 1}); } else { -- GitLab