Esempio n. 1
0
        public bool Intersect(OcTreeObject other)
        {
            var sqrDist = (Position - other.Position).SqrLength();
            var sqrRad  = (Radius + other.Radius); sqrRad *= sqrRad;

            return(sqrDist < sqrRad);
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
        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);
        }