Esempio n. 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="items">Partitioning items</param>
        /// <param name="maxDepth">Maximum depth</param>
        public PickingQuadTree(IEnumerable <T> items, int maxDepth)
        {
            var bbox = GeometryUtil.CreateBoundingBox(items);

            this.BoundingBox = bbox;

            this.Root = PickingQuadTreeNode <T> .CreatePartitions(
                this, null,
                bbox, items,
                maxDepth,
                0);

            this.Root.ConnectNodes();
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the triangle list
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Triangle> GetTriangles()
        {
            if (getTrianglesFnc != null)
            {
                var tris = getTrianglesFnc();

                BoundingBox = GeometryUtil.CreateBoundingBox(tris);

                return(tris ?? new Triangle[] { });
            }
            else
            {
                return(new Triangle[] { });
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="items">Partitioning items</param>
        /// <param name="maxDepth">Maximum depth</param>
        public QuadTree(IEnumerable <T> items, int maxDepth)
        {
            var bbox = GeometryUtil.CreateBoundingBox(items);
            var bsph = GeometryUtil.CreateBoundingSphere(items);

            this.BoundingBox    = bbox;
            this.BoundingSphere = bsph;

            int nodeCount = 0;

            this.Root = QuadTreeNode <T> .CreatePartitions(
                this, null,
                bbox, items,
                maxDepth,
                0,
                ref nodeCount);

            this.Root.ConnectNodes();
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new graph
        /// </summary>
        /// <param name="settings">Settings</param>
        /// <returns>Returns the new graph</returns>
        public override IGraph CreateGraph(PathFinderSettings settings)
        {
            var grid = new Grid
            {
                Input         = this,
                BuildSettings = settings as GridGenerationSettings
            };

            var triangles = this.GetTriangles();

            var bbox = GeometryUtil.CreateBoundingBox(triangles);

            Dictionary <Vector2, GridCollisionInfo[]> dictionary = new Dictionary <Vector2, GridCollisionInfo[]>();

            float fxSize = (bbox.Maximum.X - bbox.Minimum.X) / grid.BuildSettings.NodeSize;
            float fzSize = (bbox.Maximum.Z - bbox.Minimum.Z) / grid.BuildSettings.NodeSize;

            int xSize = fxSize > (int)fxSize ? (int)fxSize + 1 : (int)fxSize;
            int zSize = fzSize > (int)fzSize ? (int)fzSize + 1 : (int)fzSize;

            for (float x = bbox.Minimum.X; x < bbox.Maximum.X; x += grid.BuildSettings.NodeSize)
            {
                for (float z = bbox.Minimum.Z; z < bbox.Maximum.Z; z += grid.BuildSettings.NodeSize)
                {
                    GridCollisionInfo[] info = null;

                    Ray ray = new Ray()
                    {
                        Position  = new Vector3(x, bbox.Maximum.Y + 0.01f, z),
                        Direction = Vector3.Down,
                    };

                    bool intersects = Intersection.IntersectAll(
                        ray, triangles, true,
                        out Vector3[] pickedPoints,
                        out Triangle[] pickedTriangles,