public bool Intersect(OcTreeObject other) { var sqrDist = (Position - other.Position).SqrLength(); var sqrRad = (Radius + other.Radius); sqrRad *= sqrRad; return(sqrDist < sqrRad); }
public List <T> Overlap <T>(Vector2 pos, float rad) where T : PhysicalObject { var result = new List <OcTreeObject>(); var obj = new OcTreeObject(new PhysicalObject() { Position = pos, Radius = rad }); _mainNode.Overlap(obj, result); return(result.Select((o) => o.LinkedObject as T).ToList()); }
public void Overlap(OcTreeObject obj, List <OcTreeObject> result) { foreach (var item in Objects) { if (obj.Intersect(item)) { result.Add(item); } } foreach (var node in Nodes) { if (node.NodeBox.Intersect(obj.Box)) { node.Overlap(obj, result); } } }
public bool Intersect(OcTreeObject obj) { foreach (var item in Objects) { if (obj.LinkedObject != item.LinkedObject && obj.Intersect(item)) { return(true); } } foreach (var node in Nodes) { if (node.NodeBox.Intersect(obj.Box)) { if (node.Intersect(obj)) { return(true); } } } return(false); }