Пример #1
0
 public virtual void HandlePossibleIntersections(float dt, List <ICollidableBody> collidables)
 {
     if (collidables != null)
     {
         PhysicsState before = null;
         RemoveUnEffectable(collidables);
         int length = ray2DEffects.Count;
         for (int pos = 0; pos < length; ++pos)
         {
             RayICollidableBodyPair pair = GetIntersection(ray2DEffects[pos].RaySegment, collidables);
             if (pair != null && pair.BestIntersectInfo.Intersects)
             {
                 if (pair.ICollidableBody.CollisionState.GenerateRayEvents)
                 {
                     before = new PhysicsState(pair.ICollidableBody.Current);
                 }
                 ray2DEffects[pos].ApplyEffect(dt, pair);
                 if (pair.ICollidableBody.CollisionState.GenerateRayEvents)
                 {
                     pair.ICollidableBody.CollisionState.InterferenceInfos.Add(
                         new InterferenceInfo(new RayCollidableInterferenceInfo(this,
                                                                                pair.RaySegment2D,
                                                                                pair.BestIntersectInfo,
                                                                                before,
                                                                                new PhysicsState(pair.ICollidableBody.Current),
                                                                                pair.ICollidableBody)));
                 }
             }
         }
     }
 }
Пример #2
0
        protected RayICollidableBodyPair GetIntersection(RaySegment2D raySegment, List <ICollidableBody> collidables)
        {
            int collidablesCount = collidables.Count;

            if (collidablesCount == 0)
            {
                return(null);
            }
            float Smallestdistance             = raySegment.Length;
            RayICollidableBodyPair returnvalue = null;
            RayICollidableBodyPair pair;

            for (int pos = 0; pos < collidablesCount; ++pos)
            {
                pair = new RayICollidableBodyPair(raySegment, collidables[pos]);
                if (pair.TestIntersection())
                {
                    if (pair.BestIntersectInfo != null && Smallestdistance > pair.BestIntersectInfo.DistanceFromOrigin)
                    {
                        Smallestdistance = pair.BestIntersectInfo.DistanceFromOrigin;
                        returnvalue      = pair;
                    }
                }
            }
            return(returnvalue);
        }
Пример #3
0
 public override void ApplyEffect(float dt, RayICollidableBodyPair pair)
 {
     displayLength = pair.BestIntersectInfo.DistanceFromOrigin;
     effectApplied = true;
     if ((pair.ICollidableBody.Flags & ignoreFlags) == BodyFlags.None)
     {
         Vector2D point         = raySegment.GetPoint(pair.BestIntersectInfo) - pair.ICollidableBody.Current.Position.Linear;
         float    effectImpulse = impulse * dt;
         pair.ICollidableBody.ApplyImpulse(point, effectImpulse * raySegment.Direction);
     }
 }