コード例 #1
0
        /// <summary>
        /// Gets the first intersection between a ray and the stored intersectable objects
        /// </summary>
        /// <param name="ray">Ray</param>
        /// <param name="options">Ray cast options</param>
        /// <returns>Intersection result (null if no intersection occurred)</returns>
        public Line3Intersection GetFirstIntersection( Ray3 ray, RayCastOptions options )
        {
            options = options ?? s_DefaultOptions;
            Line3Intersection closestIntersection = null;
            foreach ( IRay3Intersector intersector in m_Intersectors )
            {
                if ( !options.TestObject( intersector ) )
                {
                    continue;
                }
                Line3Intersection intersection = intersector.GetIntersection( ray );
                if ( intersection != null )
                {
                    if ( ( closestIntersection == null ) || ( closestIntersection.Distance >= intersection.Distance ) )
                    {
                        closestIntersection = intersection;
                    }
                }
            }

            return closestIntersection;
        }
コード例 #2
0
        /// <summary>
        /// Casts a ray
        /// </summary>
        /// <param name="ray">Ray to cast</param>
        /// <param name="options">Options for determining which layers to check, objects to exclude, maximum ray length (!) etc.</param>
        /// <returns>Returns an array of all intersections</returns>
        public Line3Intersection[] GetIntersections( Ray3 ray, RayCastOptions options )
        {
            options = options ?? s_DefaultOptions;
            List< Line3Intersection > intersections = new List< Line3Intersection >( 4 );

            foreach ( IRay3Intersector intersector in m_Intersectors )
            {
                if ( !options.TestObject( intersector ) )
                {
                    continue;
                }
                Line3Intersection intersection = intersector.GetIntersection( ray );
                if ( intersection != null )
                {
                    intersections.Add( intersection );
                }
            }

            return intersections.ToArray( );
        }