• Create Account

### #Actualbelfegor

Posted 17 December 2012 - 10:51 AM

It got rid of overflow but i am doing something wrong in my create function (at least i suspect the problem is there) because i got only few objects displayed compared to what i can see with camera. Please help me further if you find time, thanks.

I can't think of right logic for this:
const std::size_t max_level = 5; // everything above 5 is to slow

void OcTree::create(std::shared_ptr<OcTree> _tree, std::size_t curr_level)
{

std::size_t cnt = 0;
const auto&amp; nodes = pSmgr->getNodes();
for(std::size_t i = 0; i < nodes.size(); ++i)
{
bool result = _tree->bbox.intersects(nodes[i]->getBBox());
if(result)
{
_tree->vNode.push_back(nodes[i]); // vNodes is vector of objects
++cnt;
}
}
if(cnt <= 1 || curr_level > max_level)
{
_tree->leaf = true;
return;
}
else
{
_tree->vNode.clear();
for(std::size_t i = 0; i < 8; ++i)
{
child[i] = std::shared_ptr<OcTree>(new OcTree(_tree->pSmgr, subdivide(_tree, i)));
create(child[i], curr_level + 1);
}
}
}


### #1belfegor

Posted 17 December 2012 - 10:47 AM

It got rid of overflow but i am doing something wrong in my create function (at least i suspect the problem is there) because i got only few objects displayed compared to what i can see with camera. Please help me further if you find time, thanks.

I can't think of right logic for this:
const std::size_t max_level = 5; // everything above 5 is to slow

void OcTree::create(std::shared_ptr<OcTree> _tree, std::size_t curr_level)
{
++levelCnt;
std::size_t cnt = 0;
const auto& nodes = pSmgr->getNodes();
for(std::size_t i = 0; i < nodes.size(); ++i)
{
bool result = _tree->bbox.intersects(nodes[i]->getBBox());
if(result)
{
_tree->vNode.push_back(nodes[i]); // vNodes is vector of objects
++cnt;
}
}
if(cnt <= 1 || curr_level > max_level)
{
_tree->leaf = true;
return;
}
else
{
_tree->vNode.clear();
for(std::size_t i = 0; i < 8; ++i)
{
child[i] = std::shared_ptr<OcTree>(new OcTree(_tree->pSmgr, subdivide(_tree, i)));
create(child[i], curr_level + 1);
}
}
}