diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/dynamic_bvh.cpp | 29 | ||||
-rw-r--r-- | core/math/dynamic_bvh.h | 35 |
2 files changed, 39 insertions, 25 deletions
diff --git a/core/math/dynamic_bvh.cpp b/core/math/dynamic_bvh.cpp index 4639a52278..200095d8cb 100644 --- a/core/math/dynamic_bvh.cpp +++ b/core/math/dynamic_bvh.cpp @@ -61,7 +61,7 @@ DynamicBVH::Node *DynamicBVH::_create_node_with_volume(Node *p_parent, const Vol void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { if (!bvh_root) { bvh_root = p_leaf; - p_leaf->parent = 0; + p_leaf->parent = nullptr; } else { if (!p_root->is_leaf()) { do { @@ -71,7 +71,7 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { } while (!p_root->is_leaf()); } Node *prev = p_root->parent; - Node *node = _create_node_with_volume(prev, p_leaf->volume.merge(p_root->volume), 0); + Node *node = _create_node_with_volume(prev, p_leaf->volume.merge(p_root->volume), nullptr); if (prev) { prev->childs[p_root->get_index_in_parent()] = node; node->childs[0] = p_root; @@ -85,7 +85,7 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { break; } node = prev; - } while (0 != (prev = node->parent)); + } while (nullptr != (prev = node->parent)); } else { node->childs[0] = p_root; p_root->parent = node; @@ -98,8 +98,8 @@ void DynamicBVH::_insert_leaf(Node *p_root, Node *p_leaf) { DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) { if (leaf == bvh_root) { - bvh_root = 0; - return (0); + bvh_root = nullptr; + return (nullptr); } else { Node *parent = leaf->parent; Node *prev = parent->parent; @@ -113,13 +113,14 @@ DynamicBVH::Node *DynamicBVH::_remove_leaf(Node *leaf) { prev->volume = prev->childs[0]->volume.merge(prev->childs[1]->volume); if (pb.is_not_equal_to(prev->volume)) { prev = prev->parent; - } else + } else { break; + } } return (prev ? prev : bvh_root); } else { bvh_root = sibling; - sibling->parent = 0; + sibling->parent = nullptr; _delete_node(parent); return (bvh_root); } @@ -262,10 +263,11 @@ DynamicBVH::Node *DynamicBVH::_node_sort(Node *n, Node *&r) { Node *s = p->childs[j]; Node *q = p->parent; ERR_FAIL_COND_V(n != p->childs[i], nullptr); - if (q) + if (q) { q->childs[p->get_index_in_parent()] = n; - else + } else { r = n; + } s->parent = n; p->parent = n; n->parent = q; @@ -307,8 +309,9 @@ void DynamicBVH::optimize_top_down(int bu_threshold) { } void DynamicBVH::optimize_incremental(int passes) { - if (passes < 0) + if (passes < 0) { passes = total_leaves; + } if (bvh_root && (passes > 0)) { do { Node *node = bvh_root; @@ -345,8 +348,9 @@ void DynamicBVH::_update(Node *leaf, int lookahead) { for (int i = 0; (i < lookahead) && root->parent; ++i) { root = root->parent; } - } else + } else { root = bvh_root; + } } _insert_leaf(root, leaf); } @@ -370,8 +374,9 @@ bool DynamicBVH::update(const ID &p_id, const AABB &p_box) { for (int i = 0; (i < lkhd) && base->parent; ++i) { base = base->parent; } - } else + } else { base = bvh_root; + } } leaf->volume = volume; _insert_leaf(base, leaf); diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h index c71db2d24d..3fb22515a2 100644 --- a/core/math/dynamic_bvh.h +++ b/core/math/dynamic_bvh.h @@ -87,14 +87,16 @@ private: _FORCE_INLINE_ Volume merge(const Volume &b) const { Volume r; for (int i = 0; i < 3; ++i) { - if (min[i] < b.min[i]) + if (min[i] < b.min[i]) { r.min[i] = min[i]; - else + } else { r.min[i] = b.min[i]; - if (max[i] > b.max[i]) + } + if (max[i] > b.max[i]) { r.max[i] = max[i]; - else + } else { r.max[i] = b.max[i]; + } } return r; } @@ -202,10 +204,11 @@ private: // int count_leaves() const { - if (is_internal()) + if (is_internal()) { return childs[0]->count_leaves() + childs[1]->count_leaves(); - else + } else { return (1); + } } bool is_left_of_axis(const Vector3 &org, const Vector3 &axis) const { @@ -254,31 +257,37 @@ private: tymin = (bounds[raySign[1]].y - rayFrom.y) * rayInvDirection.y; tymax = (bounds[1 - raySign[1]].y - rayFrom.y) * rayInvDirection.y; - if ((tmin > tymax) || (tymin > tmax)) + if ((tmin > tymax) || (tymin > tmax)) { return false; + } - if (tymin > tmin) + if (tymin > tmin) { tmin = tymin; + } - if (tymax < tmax) + if (tymax < tmax) { tmax = tymax; + } tzmin = (bounds[raySign[2]].z - rayFrom.z) * rayInvDirection.z; tzmax = (bounds[1 - raySign[2]].z - rayFrom.z) * rayInvDirection.z; - if ((tmin > tzmax) || (tzmin > tmax)) + if ((tmin > tzmax) || (tzmin > tmax)) { return false; - if (tzmin > tmin) + } + if (tzmin > tmin) { tmin = tzmin; - if (tzmax < tmax) + } + if (tzmax < tmax) { tmax = tzmax; + } return ((tmin < lambda_max) && (tmax > lambda_min)); } public: // Methods void clear(); - bool is_empty() const { return (0 == bvh_root); } + bool is_empty() const { return (nullptr == bvh_root); } void optimize_bottom_up(); void optimize_top_down(int bu_threshold = 128); void optimize_incremental(int passes); |