If you have problems with an algorithm, it usually helps to give a short description of how you think the algorithm should work, and to also show examples where your implementation of the algorithm fails to behave like you expect it to.
Your Octree divides the world into same-sized octants, but you never seem to check the subdivision of an octant into smaller octants. This will not give you the benefit of using an octree at all.
You have left the interesting parts of the octree implementation empty or I can't find them. You don't really show where you insert objects into the world, and you don't describe what ->update and ->draw should do. You only need to update an octree if objects actually move between octants.
Your collision checker only checks the top level of the octree for collisions, but if you find a potential collision of the object with an octant, you need to look into the objects within that octant for further collisions.
In your situation, I would read a book that discusses the algorithms for spatial trees, and inserting elements and updating the octree, and then reimplement that in Perl. Maybe it is easier and more instructive to start with a "quadtree" that only subdivides the plane instead of 3D space.
For your code, what is this line supposed to do:
$self->{rootnodes}{$level} .= $obj;
In reply to Re: octtree using hashes
by Corion
in thread octtree using hashes
by holyghost
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |