Ejemplo n.º 1
0
        public virtual void RemoveCollidableObject(ICollidable toRemove)
        {
            IBoxCollidable box = toRemove as IBoxCollidable;

            if ((box != null) && (_boxColliders.Contains(box)))
            {
                _boxColliders.Remove(box); return;
            }

            ICircularCollidable circle = toRemove as ICircularCollidable;

            if ((circle != null) && (_circularColliders.Contains(circle)))
            {
                _circularColliders.Remove(circle); return;
            }

            IPolygonCollidable poly = toRemove as IPolygonCollidable;

            if ((poly != null) && (_polygonColliders.Contains(poly)))
            {
                _polygonColliders.Remove(poly); return;
            }

            ICompoundPolygonCollidable compound = toRemove as ICompoundPolygonCollidable;

            if ((compound != null) && (_compoundPolygonColliders.Contains(compound)))
            {
                _compoundPolygonColliders.Remove(compound); return;
            }
        }
        public bool CircularCollidersHaveCollided(ICircularCollidable subject, ICircularCollidable target)
        {
            if (PositionedColliderBoundingCircleRequiresUpdate(subject)) { PositionCircularColliderBoundingCircle(subject); }
            if (PositionedColliderBoundingCircleRequiresUpdate(target)) { PositionCircularColliderBoundingCircle(target); }

            return subject.PositionedCollisionBoundingCircle.Intersects(target.PositionedCollisionBoundingCircle);
        }
Ejemplo n.º 3
0
        public virtual void AddCollidableObject(ICollidable toAdd)
        {
            IBoxCollidable box = toAdd as IBoxCollidable;

            if ((box != null) && (!_boxColliders.Contains(box)))
            {
                _boxColliders.Add(box); return;
            }

            ICircularCollidable circle = toAdd as ICircularCollidable;

            if ((circle != null) && (!_circularColliders.Contains(circle)))
            {
                _circularColliders.Add(circle); return;
            }

            IPolygonCollidable poly = toAdd as IPolygonCollidable;

            if ((poly != null) && (!_polygonColliders.Contains(poly)))
            {
                _polygonColliders.Add(poly); return;
            }

            ICompoundPolygonCollidable compound = toAdd as ICompoundPolygonCollidable;

            if ((compound != null) && (!_compoundPolygonColliders.Contains(compound)))
            {
                _compoundPolygonColliders.Add(compound); return;
            }
        }
Ejemplo n.º 4
0
        private bool PositionedColliderBoundingCircleRequiresUpdate(ICircularCollidable toCheck)
        {
            if (!toCheck.WorldPositionIsFixed)
            {
                return(true);
            }

            return((toCheck.PositionedCollisionBoundingCircle == Circle.Empty) || (toCheck.PositionedCollisionBoundingCircle == null));
        }
Ejemplo n.º 5
0
        private void PositionCircularColliderBoundingCircle(ICircularCollidable sourceCollidable)
        {
            if (sourceCollidable.PositionedCollisionBoundingCircle == null)
            {
                sourceCollidable.PositionedCollisionBoundingCircle = Circle.Empty;
            }

            sourceCollidable.PositionedCollisionBoundingCircle.Center = sourceCollidable.WorldPosition;
            sourceCollidable.PositionedCollisionBoundingCircle.Radius = sourceCollidable.CollisionBoundingCircle.Radius;
        }
Ejemplo n.º 6
0
        protected void CheckIndividualCircularColliderToAllTypes(ICircularCollidable subject)
        {
            if (subject.Collidable)
            {
                CheckIndividualCircularColliderToAllBoxColliders(subject);
                CheckIndividualCircularColliderToAllCircularColliders(subject);

                // TODO
                //CheckIndividualCircularColliderToAllPolygonColliders(_boxColliders[i]);
                //CheckIndividualCircularColliderToAllCompoundPolygonColliders(_boxColliders[i]);
            }
        }
Ejemplo n.º 7
0
        public bool CircularCollidersHaveCollided(ICircularCollidable subject, ICircularCollidable target)
        {
            if (PositionedColliderBoundingCircleRequiresUpdate(subject))
            {
                PositionCircularColliderBoundingCircle(subject);
            }
            if (PositionedColliderBoundingCircleRequiresUpdate(target))
            {
                PositionCircularColliderBoundingCircle(target);
            }

            return(subject.PositionedCollisionBoundingCircle.Intersects(target.PositionedCollisionBoundingCircle));
        }
Ejemplo n.º 8
0
 private void CheckIndividualCircularColliderToAllCircularColliders(ICircularCollidable subject)
 {
     if (subject.Collidable)
     {
         int circularColliderCount = _circularColliders.Count;
         for (int i = 0; i < circularColliderCount; i++)
         {
             if ((_circularColliders[i] != subject) && (_circularColliders[i].Collidable) && (CircularCollidersHaveCollided(subject, _circularColliders[i])))
             {
                 subject.HandleCollision(_circularColliders[i]);
                 _circularColliders[i].HandleCollision(subject);
             }
         }
     }
 }
Ejemplo n.º 9
0
 private void CheckIndividualCircularColliderToAllBoxColliders(ICircularCollidable subject)
 {
     if (subject.Collidable)
     {
         int boxColliderCount = _boxColliders.Count;
         for (int i = 0; i < boxColliderCount; i++)
         {
             if ((_boxColliders[i].Collidable) && (BoxAndCircularCollidersHaveCollided(_boxColliders[i], subject)))
             {
                 subject.HandleCollision(_boxColliders[i]);
                 _boxColliders[i].HandleCollision(subject);
             }
         }
     }
 }
        private bool PositionedColliderBoundingCircleRequiresUpdate(ICircularCollidable toCheck)
        {
            if (!toCheck.WorldPositionIsFixed) { return true; }

            return ((toCheck.PositionedCollisionBoundingCircle == Circle.Empty) || (toCheck.PositionedCollisionBoundingCircle == null));
        }
        private void PositionCircularColliderBoundingCircle(ICircularCollidable sourceCollidable)
        {
            if (sourceCollidable.PositionedCollisionBoundingCircle == null)
            {
                sourceCollidable.PositionedCollisionBoundingCircle = Circle.Empty;
            }

            sourceCollidable.PositionedCollisionBoundingCircle.Center = sourceCollidable.WorldPosition;
            sourceCollidable.PositionedCollisionBoundingCircle.Radius = sourceCollidable.CollisionBoundingCircle.Radius;
        }
 private void CheckIndividualCircularColliderToAllCircularColliders(ICircularCollidable subject)
 {
     if (subject.Collidable)
     {
         int circularColliderCount = _circularColliders.Count;
         for (int i = 0; i < circularColliderCount; i++)
         {
             if ((_circularColliders[i] != subject) && (_circularColliders[i].Collidable) && (CircularCollidersHaveCollided(subject, _circularColliders[i])))
             {
                 subject.HandleCollision(_circularColliders[i]);
                 _circularColliders[i].HandleCollision(subject);
             }
         }
     }
 }
 private void CheckIndividualCircularColliderToAllBoxColliders(ICircularCollidable subject)
 {
     if (subject.Collidable)
     {
         int boxColliderCount = _boxColliders.Count;
         for (int i = 0; i < boxColliderCount; i++)
         {
             if ((_boxColliders[i].Collidable) && (BoxAndCircularCollidersHaveCollided(_boxColliders[i], subject)))
             {
                 subject.HandleCollision(_boxColliders[i]);
                 _boxColliders[i].HandleCollision(subject);
             }
         }
     }
 }
        protected void CheckIndividualCircularColliderToAllTypes(ICircularCollidable subject)
        {
            if (subject.Collidable)
            {
                CheckIndividualCircularColliderToAllBoxColliders(subject);
                CheckIndividualCircularColliderToAllCircularColliders(subject);

                // TODO
                //CheckIndividualCircularColliderToAllPolygonColliders(_boxColliders[i]);
                //CheckIndividualCircularColliderToAllCompoundPolygonColliders(_boxColliders[i]);
            }
        }