Ejemplo n.º 1
0
        public void RemoveCollision(Collision c)
        {
            if (!Enumerable.Contains(_collideables, c)) return;
            _collideables.Remove(c);

            _pairs.RemoveWhere(pair => pair.A.Equals(c) || pair.B.Equals(c));
        }
Ejemplo n.º 2
0
        public void AddCollision(Collision c)
        {
            //Check if the Collision is already in the list.
            if (Enumerable.Contains(_collideables, c)) return;
            _collideables.Add(c);

            //Generate our pairs
            ReconfigurePairs(c);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reconfigures the pairs for a Collision c
        /// </summary>
        /// <param name="c">A collision.</param>
        public void ReconfigurePairs(Collision c)
        {
            //Remove pairs with this collision in it
            foreach (var pair in _pairs.ToArray().Where(pair => pair.A.Equals(c) || pair.B.Equals(c)))
            {
                _pairs.Remove(pair);
            }

            //Recalculate pairs with this new collision
            foreach (var other in _collideables)
            {
                if (c.Equals(other)) continue;
                if (CanObjectsPair(c, other))
                {
                    var p = new Pair(c, other);
                    _pairs.Add(p);
                }
            }
        }
Ejemplo n.º 4
0
        //Collision resolver methods
        /// <summary>
        /// Uses a table to test collision between various shapes
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Manifold CheckCollision(Collision a, Collision b)
        {
            Shape aShape, bShape;
            aShape = a.GetDependency<Shape>(Collision.DEPENDENCY_SHAPE);
            bShape = b.GetDependency<Shape>(Collision.DEPENDENCY_SHAPE);

            Manifold manifold = new Manifold(a,b);

            if (aShape is AABB && bShape is AABB)
                AABBvsAABB((AABB)aShape, (AABB)bShape, ref manifold);
            else if (aShape is Circle && bShape is Circle)
                CircleVSCircle((Circle)aShape, (Circle)bShape, ref manifold);
            else
                throw new Exception("No existing methods for this kind of collision!");

            return manifold;
        }
Ejemplo n.º 5
0
 public static bool CanObjectsResolve(Collision resolver, Collision other)
 {
     return resolver.ResolutionGroupMask.HasMatchingBit(other.ResolutionGroupMask) //Compare the pair mask one sided.
         && resolver.Enabled && other.Enabled && !resolver.Immovable;
 }
Ejemplo n.º 6
0
 //Static methods
 /// <summary>
 /// Compares the masks and checks to see if they should be allowed to form a pair.
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns>Whether or not the the two objects should be paired</returns>
 public static bool CanObjectsPair(Collision a, Collision b)
 {
     return (a.GroupMask.HasMatchingBit(b.PairMask) || //Compare the pair masks to the group masks.
             a.PairMask.HasMatchingBit(b.GroupMask)) && a.Enabled && b.Enabled;
 }
Ejemplo n.º 7
0
 public Manifold(Collision a, Collision b)
     : this()
 {
     _pair = new Pair(a, b);
 }
Ejemplo n.º 8
0
 public void OnCollision(Collision c)
 {
     _collidedWith.Add(c);
     if (CollideEvent != null)
         CollideEvent(c);
 }