コード例 #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>
        /// Sweeps a convex shape against the physics world reporting all hits on the path even if they ignore collisions, 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="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, List <SRaycastResult> outSweepResults)
        {
            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, physicsResults))
            {
                foreach (RayCastResult physicsResult in physicsResults)
                {
                    if (physicsResult.HitObject.Tag is CEntity gameEntity)
                    {
                        SRaycastResult gameResult = new SRaycastResult()
                        {
                            HitEntity   = gameEntity,
                            Location    = physicsResult.HitData.Location.ToSharp(),
                            Normal      = -physicsResult.HitData.Normal.ToSharp(),
                            Distance    = physicsResult.HitData.T,
                            bIsSolidHit = false
                        };
                        outSweepResults.Add(gameResult);
                    }
                }
                return(outSweepResults.Count > 0);
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Returns all overlapping objects of a given ray with the physics world, as no rules are given to this function all hits will be reported as non solid
        /// </summary>
        /// <param name="ray">Ray to test against</param>
        /// <param name="length">Maximum distance to test</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, List <SRaycastResult> outResults)
        {
            List <RayCastResult> physicsResults = new List <RayCastResult>();

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

            return(false);
        }
コード例 #4
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="group">Collision Group 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, CollisionGroup group, List <SRaycastResult> outResults)
        {
            List <RayCastResult> physicsResults = new List <RayCastResult>();

            if (m_physicSpace.RayCast(ray.ToBepu(), length, GetOverlapFilter(group), physicsResults))
            {
                foreach (RayCastResult physicsResult in physicsResults)
                {
                    if (physicsResult.HitObject.Tag is CEntity gameEntity)
                    {
                        CollisionRule  rule       = GetCollisionRuleWithGroup(physicsResult.HitObject, group);
                        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);
        }
コード例 #5
0
        /// <summary>
        /// Returns the first hit of a given ray tested against the physics world, does not filter anything even objects which are not collidable will be hit if they exist in the physics world
        /// </summary>
        /// <param name="ray">Ray to test against</param>
        /// <param name="length">Maximum distance to test</param>
        /// <param name="outHitResult">The hit that was found if any</param>
        /// <returns>True if any object was hit</returns>
        public bool Raycast(ref Ray ray, float length, ref SRaycastResult outHitResult)
        {
            if (m_physicSpace.RayCast(ray.ToBepu(), length, out RayCastResult result))
            {
                if (result.HitObject.Tag is CEntity gameEntity)
                {
                    outHitResult.HitEntity = gameEntity;
                    outHitResult.Location  = result.HitData.Location.ToSharp();
                    outHitResult.Normal    = result.HitData.Normal.ToSharp();
                    outHitResult.Distance  = result.HitData.T;
                    return(true);
                }

                return(false);
            }

            return(false);
        }
コード例 #6
0
        /// <summary>
        /// Sweeps a capsule against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long
        /// </summary>
        /// <param name="length">Length of the capsule</param>
        /// <param name="radius">Radius of the capsule</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="group">Collision group to filter the sweep hits, anything above "Normal" is ignored</param>
        /// <param name="outSweepResult">Closest hit to the start location</param>
        /// <returns>True if any object was hit</returns>
        public bool CapsuleSweep(float length, float radius, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionGroup group, ref SRaycastResult outSweepResult)
        {
            CapsuleShape capsuleShape = new CapsuleShape(length, radius);

            return(ConvexSweep(capsuleShape, ref startPos, ref rotation, ref sweep, group, ref outSweepResult));
        }
コード例 #7
0
        /// <summary>
        /// Sweeps a sphere against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long
        /// </summary>
        /// <param name="radius">Radius of the sphere</param>
        /// <param name="startPos">Location to start the sweep from</param>
        /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param>
        /// <param name="group">Collision group to filter the sweep hits, anything above "Normal" is ignored</param>
        /// <param name="outSweepResult">Closest hit to the start location</param>
        /// <returns>True if any object was hit</returns>
        public bool SphereSweep(float radius, ref SharpDX.Vector3 startPos, ref SharpDX.Vector3 sweep, CollisionGroup group, ref SRaycastResult outSweepResult)
        {
            SphereShape sphereShape = new SphereShape(radius);
            Quaternion  rotation    = Quaternion.Identity;

            return(ConvexSweep(sphereShape, ref startPos, ref rotation, ref sweep, group, ref outSweepResult));
        }
コード例 #8
0
        /// <summary>
        /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, 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="filter">Function to filter hits</param>
        /// <param name="outSweepResult">Closest hit to the start location</param>
        /// <returns>True if any object was hit</returns>
        public bool ConvexSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, Func <BroadPhaseEntry, bool> filter, ref SRaycastResult outSweepResult)
        {
            RigidTransform startTransform = new RigidTransform(startPos.ToBepu(), rotation.ToBepu());
            Vector3        sweepVector    = sweep.ToBepu();

            if (m_physicSpace.ConvexCast(shape, ref startTransform, ref sweepVector, filter, out RayCastResult result))
            {
                if (result.HitObject.Tag is CEntity gameEntity)
                {
                    outSweepResult.HitEntity   = gameEntity;
                    outSweepResult.Location    = result.HitData.Location.ToSharp();
                    outSweepResult.Normal      = -result.HitData.Normal.ToSharp();
                    outSweepResult.Distance    = result.HitData.T;
                    outSweepResult.bIsSolidHit = true;
                    return(true);
                }
            }

            return(false);
        }
コード例 #9
0
 /// <summary>
 /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, 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="group">Collision group to filter the sweep hits, anything above "Normal" is ignored</param>
 /// <param name="outSweepResult">Closest hit to the start location</param>
 /// <returns>True if any object was hit</returns>
 public bool ConvexSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionGroup group, ref SRaycastResult outSweepResult)
 {
     return(ConvexSweep(shape, ref startPos, ref rotation, ref sweep, GetSolidFilter(group), ref outSweepResult));
 }
コード例 #10
0
        /// <summary>
        /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, 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 "Normal" is ignored</param>
        /// <param name="outSweepResult">Closest hit to the start location</param>
        /// <returns>True if any object was hit</returns>
        public bool ConvexSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionRules sweepRules, ref SRaycastResult outSweepResult)
        {
            SimpleCollisionRulesOwner rulesOwner = new SimpleCollisionRulesOwner(sweepRules);

            return(ConvexSweep(shape, ref startPos, ref rotation, ref sweep, GetSolidFilter(rulesOwner), ref outSweepResult));
        }
コード例 #11
0
 /// <summary>
 /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long
 /// </summary>
 /// <param name="shape">Shape to sweep</param>
 /// <param name="startPosition">Location to start the sweep from</param>
 /// <param name="rotation">Rotation of the shape during the sweep</param>
 /// <param name="sweepDir">Direction in which to sweep</param>
 /// <param name="length">Length of the sweep</param>
 /// <param name="outSweepResult">Closest hit to the start location</param>
 /// <returns>True if any object was hit</returns>
 public bool ConvexSweep(ConvexShape shape, SharpDX.Vector3 startPosition, SharpDX.Quaternion rotation, SharpDX.Vector3 sweepDir, float length, ref SRaycastResult outSweepResult)
 {
     SharpDX.Vector3 sweep = sweepDir * length;
     return(ConvexSweep(shape, ref startPosition, ref rotation, ref sweep, ref outSweepResult));
 }
コード例 #12
0
 /// <summary>
 /// Returns the first hit of a given ray tested against the physics world, does filtering based on the given CollisionGroup only solid collisions will be reported
 /// </summary>
 /// <param name="ray">Ray to test against</param>
 /// <param name="length">Maximum distance to test</param>
 /// <param name="group">Collision Group to use for the ray, anything above "Normal" is ignored</param>
 /// <param name="outHitResult">The hit that was found if any</param>
 /// <returns>True if any object was hit</returns>
 public bool Raycast(ref Ray ray, float length, CollisionGroup group, ref SRaycastResult outHitResult)
 {
     return(Raycast(ref ray, length, GetSolidFilter(group), ref outHitResult));
 }
コード例 #13
0
        /// <summary>
        /// Returns the first hit of a given ray tested against the physics world, does filtering based on the given CollisionRules only solid collisions will be reported
        /// </summary>
        /// <param name="ray">Ray to test against</param>
        /// <param name="length">Maximum distance to test</param>
        /// <param name="raycastRules">Collision Rules to use for the ray, anything above "Normal" is ignored</param>
        /// <param name="outHitResult">The hit that was found if any</param>
        /// <returns>True if any object was hit</returns>
        public bool Raycast(ref Ray ray, float length, CollisionRules raycastRules, ref SRaycastResult outHitResult)
        {
            SimpleCollisionRulesOwner rulesOwner = new SimpleCollisionRulesOwner(raycastRules);

            return(Raycast(ref ray, length, GetSolidFilter(rulesOwner), ref outHitResult));
        }