Skip to content

A set of highly-optimized, flexible and powerful 2D spatial partitions for MonoGame

License

Notifications You must be signed in to change notification settings

DeanReynolds/Dcrew.Spatial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dcrew.Spatial

A set of highly-optimized, flexible and powerful 2D spatial partitions for MonoGame

Build

How to use

  1. Make a Quadtree variable
Quadtree tree = new Quadtree(x: 0, y: 0, width: 500, height: 500, maxItems: 100, maxDepth: 8);
  1. Add/Update an item(s)
tree.Update(0, x: 5, y: 5, width: 80, height: 25);
  1. Query an area(s)
foreach (int i in tree.Query(new Point(3, 4))) {
 // ...
}
foreach (int i in tree.Query(new Vector2(32.5f, 25))) {
 // ...
}
foreach (int i in tree.Query(new Rectangle(x: 7, y: 2, width: 32, height: 27))) {
 // ...
}
foreach (int i in tree.Query(new Rectangle(x: 7, y: 2, width: 32, height: 27), rotation: 0, origin: Vector2.Zero)) {
 // ...
}
foreach (int i in tree.Query(new Point(3, 4), radius: 10)) {
 // ...
}
foreach (int i in tree.Linecast(new Vector2(3, 4), new Vector2(8, 12), thickness: 3)) {
 // ...
}
foreach (int i in tree.Raycast(new Vector2(3, 4), direction: new Vector2(.5f, .75f), thickness: 3)) {
 // ...
}
foreach (int i in tree.Raycast(new Vector2(3, 4), rotation: MathF.PI, thickness: 3)) {
 // ...
}
  1. When an item moves, update it!
tree.Update(0, x: 5, y: 5, width: 80, height: 25);
  1. Did an entity despawn? Remove it!
tree.Remove(0);
  1. Call tree update at the end of every game update!
tree.Update();

About

A set of highly-optimized, flexible and powerful 2D spatial partitions for MonoGame

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages