Skip to content

quadtree implementation for check 2D collitions with low CPU cost

License

Notifications You must be signed in to change notification settings

lowfriction/quadtree-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quadtree

Quadtree implementation for check 2D collisions with low CPU cost.

Demo here: http://jsfiddle.net/sombra2eternity/vNS7m/

  • Red squares represents Quadtree Sub-divisions.
  • Grey squares represents Quadtree registered items.
  • Green square represent the collision zone, It will follow mouse move.
  • White squares represents items that could collide with our collision zone.

Usage:

Create a new Quadtree. Params: width, height, top, left, depth

var quadtree = new _quadtree(400,400);

Insert an element in the Quadtree. (Extra params could be added to any item and will be retrieved)

quadtree.insert({
	x : 200,
	y : 150,
	w : 20,
	h : 20
});

Get elements near a collision zone defined by bounds.

var elements = quadtree.retrieve({
	x : 150,
	y : 100,
	w : 20,
	h : 20
});

Clear the Quadtree

quadtree.clear();

About

quadtree implementation for check 2D collitions with low CPU cost

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%