Exemple #1
0
 /// <summary>
 /// Casts a ray through the world and returns all intersections.
 /// </summary>
 /// <param name="objectTypes">
 /// Flags that define which objects to query for intersection with this ray.
 /// </param>
 /// <param name="flags">       Flags that define how to detect intersections.</param>
 /// <param name="maxHits">     Maximal number of hits to return.</param>
 /// <param name="skipEntities">An array of IPhysicalEntity handles.</param>
 /// <returns>Detected hits (solid and pierceable).</returns>
 public IEnumerable <RaycastHit> Cast
 (
     EntityQueryFlags objectTypes    = EntityQueryFlags.All,
     RayWorldIntersectionFlags flags = RayWorldIntersectionFlags.AnyHit,
     int maxHits           = 1,
     IntPtr[] skipEntities = null
 )
 {
     return(Ray.Cast(this.Position, this.Direction, objectTypes, flags, maxHits, skipEntities));
 }
Exemple #2
0
        /// <summary>
        /// Casts a ray through the world and returns all intersections.
        /// </summary>
        /// <param name="pos">         Position from which to cast a ray.</param>
        /// <param name="dir">         Direction of the ray to cast.</param>
        /// <param name="objectTypes">
        /// Flags that define which objects to query for intersection with this ray.
        /// </param>
        /// <param name="flags">       Flags that define how to detect intersections.</param>
        /// <param name="maxHits">     Maximal number of hits to return.</param>
        /// <param name="skipEntities">An array of IPhysicalEntity handles.</param>
        /// <returns>Detected hits (solid and pierceable).</returns>
        public unsafe static List <RaycastHit> Cast
        (
            Vector3 pos,
            Vector3 dir,
            EntityQueryFlags objectTypes    = EntityQueryFlags.All,
            RayWorldIntersectionFlags flags = RayWorldIntersectionFlags.AnyHit,
            int maxHits           = 1,
            IntPtr[] skipEntities = null
        )
        {
            if (maxHits < 1)
            {
                return(null);
            }
            List <RaycastHit> hits;

            // Allocate memory for entities to skip.
            using (NativeMemoryBlock skipEntitiesArray =
                       new NativeMemoryBlock(skipEntities == null ? 0 : skipEntities.Length, typeof(IntPtr)))
                // Allocate memory for ray-cast hits.
                using (NativeMemoryBlock hitsArray = new NativeMemoryBlock(maxHits, typeof(RaycastHit)))
                {
                    // Transfer handles of entities to skip to native memory.
                    if (!skipEntitiesArray.Disposed)
                    {
                        IntPtr *skipEntsPointer = (IntPtr *)skipEntitiesArray.Handle.ToPointer();
                        for (int i = 0; i < skipEntities.Length; i++)                           // Ignore that ReSharper warning.
                        {
                            skipEntsPointer[i] = skipEntities[i];
                        }
                    }
                    // Cast the ray.
                    int numberOfHits =
                        Native.PhysicsInterop.RayWorldIntersection
                        (
                            pos,
                            dir,
                            objectTypes,
                            flags,
                            maxHits,
                            skipEntitiesArray.Handle,
                            skipEntities == null ? 0 : skipEntities.Length,
                            hitsArray.Handle
                        );
                    // Transfer ray-cast hits from native memory.
                    RaycastHit *hitPointer = (RaycastHit *)hitsArray.Handle.ToPointer();
                    hits = new List <RaycastHit>(numberOfHits);
                    for (int i = 0; i < numberOfHits; i++)
                    {
                        hits.Add(hitPointer[i]);
                    }
                }
            return(hits);
        }
 internal static extern int RayWorldIntersection(Vec3 origin, Vec3 dir, EntityQueryFlags objFlags, RayWorldIntersectionFlags flags, out RaycastHit rayHit, int maxHits, object[] skipEnts);
 internal static extern int RayWorldIntersection(Vec3 origin, Vec3 dir, EntityQueryFlags objFlags, RayWorldIntersectionFlags flags, int maxHits, IntPtr[] skipEnts, out object[] hits);
 public static extern int RayWorldIntersection(Vector3 origin, Vector3 dir, EntityQueryFlags objFlags,
     RayWorldIntersectionFlags flags, int maxHits, IntPtr skipEnts, int skipCount, IntPtr hits);
 extern public static int RayWorldIntersection(Vec3 origin, Vec3 dir, EntityQueryFlags objFlags, RayWorldIntersectionFlags flags, int maxHits, IntPtr[] skipEnts, out object[] hits);
Exemple #7
0
 extern public static int RayWorldIntersection
     (Vector3 origin, Vector3 dir, EntityQueryFlags objFlags,
     RayWorldIntersectionFlags flags, int maxHits, IntPtr skipEnts, int skipCount, IntPtr hits);
Exemple #8
0
        public static IEnumerable <RaycastHit> Cast(Vec3 pos, Vec3 dir, EntityQueryFlags objectTypes = EntityQueryFlags.All, RayWorldIntersectionFlags flags = RayWorldIntersectionFlags.AnyHit, int maxHits = 1, IntPtr[] skipEntities = null)
        {
            var ray = new Ray(pos, dir);

            return(ray.Cast(objectTypes, flags, maxHits, skipEntities));
        }
Exemple #9
0
        /// <summary>
        /// Steps through the entity grid and raytraces entities
        /// traces a finite ray from org along dir
        /// </summary>
        /// <param name="objectTypes"></param>
        /// <param name="flags"></param>
        /// <param name="maxHits"></param>
        /// <param name="skipEntities">an array of IPhysicalEntity handles. <see cref="CryEngine.Native.NativeHandleExtensions.GetIPhysicalEntity"/></param>
        /// <returns>Detected hits (solid and pierceable)</returns>
        public IEnumerable <RaycastHit> Cast(EntityQueryFlags objectTypes = EntityQueryFlags.All, RayWorldIntersectionFlags flags = RayWorldIntersectionFlags.AnyHit, int maxHits = 1, IntPtr[] skipEntities = null)
        {
            if (skipEntities != null && skipEntities.Length == 0)
            {
                skipEntities = null;
            }

            object[] hits;
            var      numHits = Native.NativePhysicsMethods.RayWorldIntersection(Position, Direction, objectTypes, flags, maxHits, skipEntities, out hits);

            if (numHits > 0)
            {
                return(hits.Cast <RaycastHit>());
            }

            return(new List <RaycastHit>());
        }