Пример #1
0
        /// <summary>
        /// Sweeps a convex shape against the physics world reporting all hits on the path that are not ignored by the filter, beware convex sweeps can be very costly especially if they are long
        /// </summary>
        /// <param name="shape">Shape to sweep</param>
        /// <param name="startPos">Location to start the sweep from</param>
        /// <param name="rotation">Rotation of the shape during the sweep</param>
        /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param>
        /// <param name="sweepRules">Collision rules to filter the sweep hits, anything above "NoSolver" is ignored</param>
        /// <param name="outSweepResults">All overlaps on the sweep path</param>
        /// <returns>True if any object was hit</returns>
        public bool MultiSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionRules sweepRules, List <SRaycastResult> outSweepResults)
        {
            SimpleCollisionRulesOwner rulesOwner     = new SimpleCollisionRulesOwner(sweepRules);
            RigidTransform            startTransform = new RigidTransform(startPos.ToBepu(), rotation.ToBepu());
            Vector3 sweepVector = sweep.ToBepu();
            List <RayCastResult> physicsResults = new List <RayCastResult>();

            if (m_physicSpace.ConvexCast(shape, ref startTransform, ref sweepVector, GetOverlapFilter(rulesOwner), physicsResults))
            {
                foreach (RayCastResult physicsResult in physicsResults)
                {
                    if (physicsResult.HitObject.Tag is CEntity gameEntity)
                    {
                        CollisionRule  rule       = CollisionRules.GetCollisionRule(physicsResult.HitObject, rulesOwner);
                        SRaycastResult gameResult = new SRaycastResult()
                        {
                            HitEntity   = gameEntity,
                            Location    = physicsResult.HitData.Location.ToSharp(),
                            Normal      = -physicsResult.HitData.Normal.ToSharp(),
                            Distance    = physicsResult.HitData.T,
                            bIsSolidHit = rule <= CollisionRule.Normal
                        };
                        outSweepResults.Add(gameResult);
                    }
                }
                return(outSweepResults.Count > 0);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Returns all overlapping objects of a given ray with the physics world, the ray does NOT stop at solid hit but will report all overlaps and solid hits on the ray
        /// </summary>
        /// <param name="ray">Ray to test against</param>
        /// <param name="length">Maximum distance to test</param>
        /// <param name="rayRules">Collision Rules to use for the ray anything above "NoSolver" is ignored</param>
        /// <param name="outResults">All overlaps on the ray</param>
        /// <returns>True if any object was hit</returns>
        public bool RayOverlap(ref Ray ray, float length, CollisionRules rayRules, List <SRaycastResult> outResults)
        {
            SimpleCollisionRulesOwner rulesOwner     = new SimpleCollisionRulesOwner(rayRules);
            List <RayCastResult>      physicsResults = new List <RayCastResult>();

            if (m_physicSpace.RayCast(ray.ToBepu(), length, GetOverlapFilter(rulesOwner), physicsResults))
            {
                foreach (RayCastResult physicsResult in physicsResults)
                {
                    if (physicsResult.HitObject.Tag is CEntity gameEntity)
                    {
                        CollisionRule  rule       = CollisionRules.GetCollisionRule(physicsResult.HitObject, rulesOwner);
                        SRaycastResult gameResult = new SRaycastResult()
                        {
                            HitEntity   = gameEntity,
                            Location    = physicsResult.HitData.Location.ToSharp(),
                            Normal      = physicsResult.HitData.Normal.ToSharp(),
                            Distance    = physicsResult.HitData.T,
                            bIsSolidHit = rule <= CollisionRule.Normal
                        };
                        outResults.Add(gameResult);
                    }
                }
                return(outResults.Count > 0);
            }

            return(false);
        }
Пример #3
0
        private Func <BroadPhaseEntry, bool> GetOverlapFilter(ICollisionRulesOwner rulesOwner)
        {
            bool Filter(BroadPhaseEntry e)
            {
                CollisionRule rule = CollisionRules.GetCollisionRule(e, rulesOwner);

                return(rule <= CollisionRule.NoSolver);
            }

            return(Filter);
        }
Пример #4
0
 public bool IgnoreThis(BroadPhaseEntry entry)
 {
     if (entry is EntityCollidable ec && ec.Entity == Entity)
     {
         return(false);
     }
     if (CollisionRules.GetCollisionRule(entity.CollisionInformation, entry) == CollisionRule.NoBroadPhase)
     {
         return(false);
     }
     return(CollisionUtil.ShouldCollide(entry));
 }