2021-04-10 14:08:20 +02:00
|
|
|
using System.Collections.Generic;
|
2021-04-11 14:12:55 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
2021-04-10 14:08:20 +02:00
|
|
|
|
|
|
|
|
namespace EvilSatellites.Quadtree
|
|
|
|
|
{
|
|
|
|
|
public class Quadtree<T> where T : Positional
|
|
|
|
|
{
|
|
|
|
|
public Vector3 Dimensions { get; set; }
|
|
|
|
|
public int MaxLevels;
|
|
|
|
|
public int MaxObjects;
|
|
|
|
|
public QuadtreeNode<T> Root;
|
|
|
|
|
public Quadtree(Vector3 dimensions, int maxLevels, int maxObjects)
|
|
|
|
|
{
|
|
|
|
|
Dimensions = dimensions;
|
|
|
|
|
this.MaxLevels = maxLevels;
|
|
|
|
|
this.MaxObjects = maxObjects;
|
|
|
|
|
this.Root = new QuadtreeNode<T>(new Vector3(0, 0, 0), Dimensions, MaxLevels, MaxObjects, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(T obj)
|
|
|
|
|
{
|
|
|
|
|
Root.Add(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
this.Root = new QuadtreeNode<T>(new Vector3(0, 0, 0), Dimensions, MaxLevels, MaxObjects, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<T> Find(Vector3 Position, Vector3 dimensions)
|
|
|
|
|
{
|
|
|
|
|
return Root.Find(Position, dimensions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<T> Find(Vector3 Position)
|
|
|
|
|
{
|
|
|
|
|
return Root.Find(Position, new Vector3(1, 1, 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|