bvh_misc.inc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. int _handle_get_tree_id(BVHHandle p_handle) const {
  2. if (USE_PAIRS) {
  3. int tree = 0;
  4. if (_extra[p_handle.id()].pairable) {
  5. tree = 1;
  6. }
  7. return tree;
  8. }
  9. return 0;
  10. }
  11. public:
  12. void _handle_sort(BVHHandle &p_ha, BVHHandle &p_hb) const {
  13. if (p_ha.id() > p_hb.id()) {
  14. BVHHandle temp = p_hb;
  15. p_hb = p_ha;
  16. p_ha = temp;
  17. }
  18. }
  19. private:
  20. void create_root_node(int p_tree) {
  21. // if there is no root node, create one
  22. if (_root_node_id[p_tree] == BVHCommon::INVALID) {
  23. uint32_t root_node_id;
  24. TNode *node = _nodes.request(root_node_id);
  25. node->clear();
  26. _root_node_id[p_tree] = root_node_id;
  27. // make the root node a leaf
  28. uint32_t leaf_id;
  29. TLeaf *leaf = _leaves.request(leaf_id);
  30. leaf->clear();
  31. node->neg_leaf_id = -(int)leaf_id;
  32. }
  33. }
  34. bool node_is_leaf_full(TNode &tnode) const {
  35. const TLeaf &leaf = _node_get_leaf(tnode);
  36. return leaf.is_full();
  37. }
  38. public:
  39. TLeaf &_node_get_leaf(TNode &tnode) {
  40. BVH_ASSERT(tnode.is_leaf());
  41. return _leaves[tnode.get_leaf_id()];
  42. }
  43. const TLeaf &_node_get_leaf(const TNode &tnode) const {
  44. BVH_ASSERT(tnode.is_leaf());
  45. return _leaves[tnode.get_leaf_id()];
  46. }
  47. private: