Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actuallwm

Posted 08 August 2012 - 12:06 PM

If you have an algorithm that returns all nodes in the quadtree using recursion, all you have to do is check if a child node is contained in/intersected by the area you want to retrieve entities from. If it is not, you can ignore that entire branch of the tree. Something along the lines of this should work.

getEntitiesInRectangle(Node node, Rectangle rect, List output)
  if node is leaf:
    for every entity e in node:
     if rect contains/intersects e: add e to output;
  else
    for every child n in node:
     if rect contains/intersects n:
      call getEntitiesInRectangle(n, rect, output)

#1lwm

Posted 08 August 2012 - 12:05 PM

If you have an algorithm that returns all nodes in the quadtree using recursion, all you have to do is check if a child node is contained in/intersected by the area you want to retrieve entities from. If it is not, you can ignore that entire branch of the tree. Something along the lines of this should work.

getEntitiesInRectangle(Node node, Rectangle rect, List output)
if node is leaf:
  for every entity e in node:
   if rect contains/intersects e: add e to output;
else
  for every child n in node:
   if rect contains/intersects n:
	call getEntitiesInRectangle(n, rect, output)

PARTNERS