Exemple #1
0
        /// <summary>
        /// Casts a convex shape against the collidable.
        /// </summary>
        /// <param name="castShape">Shape to cast.</param>
        /// <param name="startingTransform">Initial transform of the shape.</param>
        /// <param name="sweep">Sweep to apply to the shape.</param>
        /// <param name="filter">Test to apply to the entry. If it returns true, the entry is processed, otherwise the entry is ignored. If a collidable hierarchy is present
        /// in the entry, this filter will be passed into inner ray casts.</param>
        /// <param name="result">Hit data, if any.</param>
        /// <returns>Whether or not the cast hit anything.</returns>
        public bool ConvexCast(ConvexShape castShape, ref RigidTransform startingTransform, ref Vector3 sweep, Func <BroadPhaseEntry, bool> filter, out RayCastResult result)
        {
            var         outputOverlappedElements = PhysicsResources.GetCollidableList();
            BoundingBox boundingBox;

            castShape.GetSweptBoundingBox(ref startingTransform, ref sweep, out boundingBox);

            CollidableTree.GetOverlaps(boundingBox, outputOverlappedElements);
            result           = new RayCastResult();
            result.HitData.T = float.MaxValue;
            for (int i = 0; i < outputOverlappedElements.Count; ++i)
            {
                RayHit hit;
                if (outputOverlappedElements.Elements[i].ConvexCast(castShape, ref startingTransform, ref sweep, filter, out hit))
                {
                    if (hit.T < result.HitData.T)
                    {
                        result.HitData   = hit;
                        result.HitObject = outputOverlappedElements.Elements[i];
                    }
                }
            }
            PhysicsResources.GiveBack(outputOverlappedElements);
            return(result.HitData.T < float.MaxValue);
        }
Exemple #2
0
        /// <summary>
        /// Casts a convex shape against the collidable.
        /// </summary>
        /// <param name="castShape">Shape to cast.</param>
        /// <param name="startingTransform">Initial transform of the shape.</param>
        /// <param name="sweep">Sweep to apply to the shape.</param>
        /// <param name="filter">Test to apply to the entry. If it returns true, the entry is processed, otherwise the entry is ignored. If a collidable hierarchy is present
        /// in the entry, this filter will be passed into inner ray casts.</param>
        /// <param name="result">Data and hit object from the first impact, if any.</param>
        /// <returns>Whether or not the cast hit anything.</returns>
        public bool ConvexCast(ConvexShape castShape, ref RigidTransform startingTransform, ref Vector3 sweep, Func <BroadPhaseEntry, bool> filter, out RayCastResult result)
        {
            CompoundChild hitChild;
            RayHit        rayHit;
            bool          hit = ConvexCast(castShape, ref startingTransform, ref sweep, filter, out rayHit, out hitChild);

            result = new RayCastResult {
                HitData = rayHit, HitObject = hitChild.CollisionInformation
            };
            return(hit);
        }
Exemple #3
0
        /// <summary>
        /// Tests a ray against the compound.
        /// </summary>
        /// <param name="ray">Ray to test.</param>
        /// <param name="maximumLength">Maximum length, in units of the ray's direction's length, to test.</param>
        /// <param name="rayHit">Hit data and the hit child collidable, if any.</param>
        /// <param name="filter">Test to apply to the entry. If it returns true, the entry is processed, otherwise the entry is ignored. If a collidable hierarchy is present
        /// in the entry, this filter will be passed into inner ray casts.</param>
        /// <returns>Whether or not the ray hit the entry.</returns>
        public bool RayCast(Ray ray, float maximumLength, Func <BroadPhaseEntry, bool> filter, out RayCastResult rayHit)
        {
            RayHit        hitData;
            CompoundChild hitChild;
            bool          hit = RayCast(ray, maximumLength, filter, out hitData, out hitChild);

            rayHit = new RayCastResult {
                HitData = hitData, HitObject = hitChild.CollisionInformation
            };
            return(hit);
        }
Exemple #4
0
        /// <summary>
        /// <para>Casts a convex shape against the space.</para>
        /// <para>Convex casts are sensitive to length; avoid extremely long convex casts for better stability and performance.</para>
        /// </summary>
        /// <param name="castShape">Shape to cast.</param>
        /// <param name="startingTransform">Initial transform of the shape.</param>
        /// <param name="sweep">Sweep to apply to the shape. Avoid extremely long convex casts for better stability and performance.</param>
        /// <param name="filter">Delegate to prune out hit candidates before performing a cast against them. Return true from the filter to process an entry or false to ignore the entry.</param>
        /// <param name="castResult">Hit data, if any.</param>
        /// <returns>Whether or not the cast hit anything.</returns>
        public bool ConvexCast(ConvexShape castShape, ref RigidTransform startingTransform, ref Vector3 sweep, Func <BroadPhaseEntry, bool> filter, out RayCastResult castResult)
        {
            var  castResults = PhysicsResources.GetRayCastResultList();
            bool didHit      = ConvexCast(castShape, ref startingTransform, ref sweep, filter, castResults);

            castResult = castResults.Elements[0];
            for (int i = 1; i < castResults.Count; i++)
            {
                RayCastResult candidate = castResults.Elements[i];
                if (candidate.HitData.T < castResult.HitData.T)
                {
                    castResult = candidate;
                }
            }
            PhysicsResources.GiveBack(castResults);
            return(didHit);
        }
Exemple #5
0
        /// <summary>
        /// Tests a ray against the space.
        /// </summary>
        /// <param name="ray">Ray to test.</param>
        /// <param name="maximumLength">Maximum length of the ray in units of the ray direction's length.</param>
        /// <param name="filter">Delegate to prune out hit candidates before performing a ray cast against them. Return true from the filter to process an entry or false to ignore the entry.</param>
        /// <param name="result">Hit data of the ray, if any.</param>
        /// <returns>Whether or not the ray hit anything.</returns>
        public bool RayCast(Ray ray, float maximumLength, Func <BroadPhaseEntry, bool> filter, out RayCastResult result)
        {
            var  resultsList = PhysicsResources.GetRayCastResultList();
            bool didHit      = RayCast(ray, maximumLength, filter, resultsList);

            result = resultsList.Elements[0];
            for (int i = 1; i < resultsList.Count; i++)
            {
                RayCastResult candidate = resultsList.Elements[i];
                if (candidate.HitData.T < result.HitData.T)
                {
                    result = candidate;
                }
            }
            PhysicsResources.GiveBack(resultsList);

            return(didHit);
        }
Exemple #6
0
        /// <summary>
        /// Tests a ray against the collidable.
        /// </summary>
        /// <param name="ray">Ray to test.</param>
        /// <param name="maximumLength">Maximum length, in units of the ray's direction's length, to test.</param>
        /// <param name="result">Hit data, if any.</param>
        /// <returns>Whether or not the ray hit the entry.</returns>
        public bool RayCast(Ray ray, float maximumLength, out RayCastResult result)
        {
            var outputOverlappedElements = PhysicsResources.GetCollidableList();

            CollidableTree.GetOverlaps(ray, maximumLength, outputOverlappedElements);
            result           = new RayCastResult();
            result.HitData.T = float.MaxValue;
            for (int i = 0; i < outputOverlappedElements.Count; ++i)
            {
                RayHit hit;
                if (outputOverlappedElements.Elements[i].RayCast(ray, maximumLength, out hit))
                {
                    if (hit.T < result.HitData.T)
                    {
                        result.HitData   = hit;
                        result.HitObject = outputOverlappedElements.Elements[i];
                    }
                }
            }
            PhysicsResources.GiveBack(outputOverlappedElements);
            return(result.HitData.T < float.MaxValue);
        }
Exemple #7
0
 /// <summary>
 /// Tests a ray against the space.
 /// </summary>
 /// <param name="ray">Ray to test.</param>
 /// <param name="filter">Delegate to prune out hit candidates before performing a ray cast against them. Return true from the filter to process an entry or false to ignore the entry.</param>
 /// <param name="result">Hit data of the ray, if any.</param>
 /// <returns>Whether or not the ray hit anything.</returns>
 public bool RayCast(Ray ray, Func <BroadPhaseEntry, bool> filter, out RayCastResult result)
 {
     return(RayCast(ray, float.MaxValue, filter, out result));
 }
Exemple #8
0
 /// <summary>
 /// Tests a ray against the space.
 /// </summary>
 /// <param name="ray">Ray to test.</param>
 /// <param name="result">Hit data of the ray, if any.</param>
 /// <returns>Whether or not the ray hit anything.</returns>
 public bool RayCast(Ray ray, out RayCastResult result)
 {
     return(RayCast(ray, float.MaxValue, out result));
 }