Exemplo n.º 1
0
        public List <FBCollision <T> > GetAllCollisions(List <T> bodies, FBSpatialHash <T> bodiesHashed)
        {
            var allPossibleCollisions = GetAllPossibleCollisions(bodies, bodiesHashed);
            var firstCollisions       = FilterEarliestCollisions(allPossibleCollisions);

            return(firstCollisions);
        }
Exemplo n.º 2
0
        protected List <T> GetPotentialCollidingBodies(T body, FBSpatialHash <T> bodiesHashed)
        {
            List <T> potentialBodies = new List <T>();

            var sweptAABB = GetSweptAABB(body);
            var potentialCollisionBodies = bodiesHashed.GetRectangle(sweptAABB);

            foreach (var potentialBody in potentialCollisionBodies)
            {
                if (potentialBody != body)
                {
                    potentialBodies.Add(potentialBody);
                }
            }

            return(potentialBodies);
        }
Exemplo n.º 3
0
        protected List <FBCollision <T> > GetAllPossibleCollisions(List <T> bodies, FBSpatialHash <T> bodiesHashed)
        {
            List <FBCollision <T> > collisions = new List <FBCollision <T> >();

            var allPotentialCollisionPairs = GetPotentialCollisionPairs(bodies, bodiesHashed);

            foreach (var pair in allPotentialCollisionPairs)
            {
                if (pair.BodyA.Collider.WillCollideWith(pair.BodyA.MovementThisFrame, pair.BodyB.Collider, pair.BodyB.MovementThisFrame, out var bodyAMovementInfo, out var bodyBMovementInfo, true))
                {
                    var collision = new FBCollision <T>();
                    collision.BodyA     = pair.BodyA;
                    collision.BodyB     = pair.BodyB;
                    collision.AMovement = bodyAMovementInfo;
                    collision.BMovement = bodyBMovementInfo;

                    collisions.Add(collision);
                }
            }

            return(collisions);
        }
Exemplo n.º 4
0
 public void Initialize()
 {
     bodies     = new List <T>();
     bodiesHash = new FBSpatialHash <T>(100);
 }
Exemplo n.º 5
0
 public FBScene()
 {
     bodies           = new List <T>();
     bodiesHash       = new FBSpatialHash <T>(100);
     collisionChecker = new FBCollisionChecker <T>();
 }
Exemplo n.º 6
0
        protected List <FBPotentialCollisionPair <T> > GetPotentialCollisionPairs(List <T> bodies, FBSpatialHash <T> bodiesHashed)
        {
            var pairs = new List <FBPotentialCollisionPair <T> >();

            foreach (var body in bodies)
            {
                var potentialCollidingBodies = GetPotentialCollidingBodies(body, bodiesHashed);
                foreach (var potentialCollidingBody in potentialCollidingBodies)
                {
                    pairs.Add(new FBPotentialCollisionPair <T>()
                    {
                        BodyA = body,
                        BodyB = potentialCollidingBody
                    });
                }
            }

            return(pairs);
        }