Exemplo n.º 1
0
        /// <summary>
        /// Gets first picking position of giving ray
        /// </summary>
        /// <param name="ray">Picking ray</param>
        /// <param name="rayPickingParams">Ray picking params</param>
        /// <param name="result">Picking result</param>
        /// <returns>Returns true if ground position found</returns>
        public virtual bool PickFirst(Ray ray, RayPickingParams rayPickingParams, out PickingResult <Triangle> result)
        {
            result = new PickingResult <Triangle>()
            {
                Distance = float.MaxValue,
            };

            var bsph = this.GetBoundingSphere();

            if (bsph.Intersects(ref ray))
            {
                bool facingOnly = !rayPickingParams.HasFlag(RayPickingParams.AllTriangles);
                var  triangles  = this.GetVolume(rayPickingParams.HasFlag(RayPickingParams.Geometry));

                if (triangles.Any() && Intersection.IntersectFirst(ray, triangles, facingOnly, out Vector3 p, out Triangle t, out float d))
                {
                    result.Position = p;
                    result.Item     = t;
                    result.Distance = d;

                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Pick ground positions
        /// </summary>
        /// <param name="ray">Ray</param>
        /// <param name="rayPickingParams">Ray picking params</param>
        /// <param name="results">Picking results</param>
        /// <returns>Returns true if picked position found</returns>
        public bool PickAll(Ray ray, RayPickingParams rayPickingParams, out PickingResult <Triangle>[] results)
        {
            bool res = false;

            results = null;

            bool facingOnly = !rayPickingParams.HasFlag(RayPickingParams.AllTriangles);

            if (this.groundPickingQuadtree != null && this.groundPickingQuadtree.PickAll(ray, facingOnly, out PickingResult <Triangle>[] gResults))
Exemplo n.º 3
0
        /// <summary>
        /// Get all picking positions of giving ray
        /// </summary>
        /// <param name="ray">Picking ray</param>
        /// <param name="rayPickingParams">Ray picking params</param>
        /// <param name="results">Picking results</param>
        /// <returns>Returns true if ground position found</returns>
        public virtual bool PickAll(Ray ray, RayPickingParams rayPickingParams, out PickingResult <Triangle>[] results)
        {
            results = null;

            var bsph = this.GetBoundingSphere();

            if (bsph.Intersects(ref ray))
            {
                bool facingOnly = !rayPickingParams.HasFlag(RayPickingParams.AllTriangles);
                var  triangles  = this.GetVolume(rayPickingParams.HasFlag(RayPickingParams.Geometry));

                if (triangles.Any() && Intersection.IntersectAll(ray, triangles, facingOnly, out Vector3[] p, out Triangle[] t, out float[] d))
Exemplo n.º 4
0
        /// <summary>
        /// Pick ground nearest position
        /// </summary>
        /// <param name="ray">Ray</param>
        /// <param name="rayPickingParams">Ray picking params</param>
        /// <param name="result">Picking result</param>
        /// <returns>Returns true if picked position found</returns>
        public bool PickNearest(Ray ray, RayPickingParams rayPickingParams, out PickingResult <Triangle> result)
        {
            bool res = false;

            result = new PickingResult <Triangle>()
            {
                Distance = float.MaxValue,
            };

            bool facingOnly = !rayPickingParams.HasFlag(RayPickingParams.AllTriangles);

            if (this.groundPickingQuadtree != null && this.groundPickingQuadtree.PickNearest(ray, facingOnly, out PickingResult <Triangle> gResult))
            {
                if (result.Distance > gResult.Distance)
                {
                    result = gResult;
                }

                res = true;
            }

            return(res);
        }