예제 #1
0
        /// <summary>
        /// Gets the picked position in world space from screen coordinates.
        /// </summary>
        public static bool TryPick(this IPickable pickable, Viewport viewport, int x, int y, Matrix view, Matrix projection, out Vector3 position)
        {
            Ray   pickRay  = viewport.CreatePickRay(x, y, view, projection);
            float?distance = pickable.Intersects(pickRay);

            if (distance == null)
            {
                position = Vector3.Zero;
                return(false);
            }
            position = pickRay.Position + pickRay.Direction * distance.Value;
            return(true);
        }