Ejemplo n.º 1
0
        public void SubDivide()
        {
            float subWidth  = ((Bounds.Max - Bounds.Min) / 4).X;
            float subHeight = ((Bounds.Max - Bounds.Min) / 4).Y;

            subHeight = subWidth;

            //upper
            var nodeUFR = new OcTree(new Vector3(Center.X + subWidth, Center.Y - subWidth, Center.Z + subWidth), Size / 2);
            var nodeUFL = new OcTree(new Vector3(Center.X - subWidth, Center.Y - subWidth, Center.Z + subWidth), Size / 2);
            var nodeUBR = new OcTree(new Vector3(Center.X + subWidth, Center.Y - subWidth, Center.Z - subWidth), Size / 2);
            var nodeUBL = new OcTree(new Vector3(Center.X - subWidth, Center.Y - subWidth, Center.Z - subWidth), Size / 2);
            //lower
            var nodeLFR = new OcTree(new Vector3(Center.X + subWidth, Center.Y + subWidth, Center.Z + subWidth), Size / 2);
            var nodeLFL = new OcTree(new Vector3(Center.X - subWidth, Center.Y + subWidth, Center.Z + subWidth), Size / 2);
            var nodeLBR = new OcTree(new Vector3(Center.X + subWidth, Center.Y + subWidth, Center.Z - subWidth), Size / 2);
            var nodeLBL = new OcTree(new Vector3(Center.X - subWidth, Center.Y + subWidth, Center.Z - subWidth), Size / 2);

            //upper
            Nodes.Add(nodeUFR);
            Nodes.Add(nodeUFL);
            Nodes.Add(nodeUBR);
            Nodes.Add(nodeUBL);
            //lower
            Nodes.Add(nodeLFR);
            Nodes.Add(nodeLFL);
            Nodes.Add(nodeLBR);
            Nodes.Add(nodeLBL);

            foreach (var node in Nodes)
            {
                DebugEngine.AddBoundingBox(node.Bounds, Color.Yellow, 1000);
            }
        }
Ejemplo n.º 2
0
        public QuadTree(float size, Vector2 position, int maxObjects)
        {
            Size       = size;
            Position   = position;
            MaxObjects = maxObjects;

            Objects = new List <GameObject3D>();
            Nodes   = new List <QuadTree>();

            float   halfSize = size / 2;
            Vector3 min      = new Vector3(position.X - halfSize, position.Y - halfSize, 0);
            Vector3 max      = new Vector3(position.X + halfSize, position.Y + halfSize, 0);

            Bounds = new BoundingBox(min, max);

            DebugEngine.AddBoundingBox(Bounds, Color.Red, 1000);
            DebugEngine.AddBoundingSphere(new BoundingSphere(new Vector3(position, 0), 1), Color.Black, 1000);
        }
Ejemplo n.º 3
0
        public Octree(float size, Vector3 position, int maxObjects)
        {
            Size       = size;
            Position   = position;
            MaxObjects = maxObjects;

            Objects = new List <GameObject3D>();
            Nodes   = new List <Octree>();

            //TODO: create bounds of given size at given position
            float   halfSize = size / 2;
            Vector3 min      = new Vector3(position.X - halfSize, position.Y - halfSize, position.Z - halfSize);
            Vector3 max      = new Vector3(position.X + halfSize, position.Y + halfSize, position.Z + halfSize);

            Bounds = new BoundingBox(min, max);

            DebugEngine.AddBoundingBox(Bounds, Color.LimeGreen, 1000);
            DebugEngine.AddBoundingSphere(new BoundingSphere(new Vector3(position.X, position.Y, position.Z), 1), Color.Black, 1000);
        }