Пример #1
0
        /// <summary>
        /// Finds the hits.
        /// </summary>
        /// <param name="viewport">The viewport.</param>
        /// <param name="position">The position.</param>
        /// <param name="hits">The hits.</param>
        /// <returns></returns>
        public static bool FindHits(this IViewport3DX viewport, Vector2 position, ref List <HitTestResult> hits)
        {
            hits?.Clear();
            if (viewport.CameraCore is ProjectionCameraCore && viewport.RenderHost != null)
            {
                if (!viewport.UnProject(position, out var ray))
                {
                    return(false);
                }
                if (hits == null)
                {
                    hits = new List <HitTestResult>();
                }

                foreach (var element in viewport.Renderables)
                {
                    element.HitTest(viewport.RenderHost.RenderContext, ray, ref hits);
                }
                hits.Sort();

                return(hits.Count > 0);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Uns the project 2D point onto a 3D plane.
 /// </summary>
 /// <param name="viewport">The viewport.</param>
 /// <param name="p">The p.</param>
 /// <param name="position">The position.</param>
 /// <param name="normal">The normal.</param>
 /// <param name="intersection">The intersection.</param>
 /// <returns></returns>
 public static bool UnProjectOnPlane(this IViewport3DX viewport, Vector2 p, Vector3 position, Vector3 normal, out Vector3 intersection)
 {
     if (viewport.UnProject(p, out Ray ray))
     {
         return(ray.PlaneIntersection(position, normal, out intersection));
     }
     else
     {
         intersection = Vector3.Zero;
         return(false);
     }
 }