Ejemplo n.º 1
0
        //by default, Bullet will use this near callback
        public static void DefaultNearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo)
        {
            CollisionObject collisionObjectA = collisionPair.ProxyA.ClientData as CollisionObject;
            CollisionObject collisionObjectB = collisionPair.ProxyB.ClientData as CollisionObject;

            if (dispatcher.NeedsCollision(collisionObjectA, collisionObjectB))
            {
                //dispatcher will keep algorithms persistent in the collision pair
                if (collisionPair.CollisionAlgorithm == null)
                {
                    collisionPair.CollisionAlgorithm = dispatcher.FindAlgorithm(collisionObjectA, collisionObjectB);
                }

                if (collisionPair.CollisionAlgorithm != null)
                {
                    ManifoldResult contactPointResult = new ManifoldResult(collisionObjectA, collisionObjectB);

                    if (dispatchInfo.DispatchFunction == DispatchFunction.Discrete)
                    {
                        //discrete collision detection query
                        collisionPair.CollisionAlgorithm.ProcessCollision(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult);
                    }
                    else
                    {
                        //continuous collision detection query, time of impact (toi)
                        float timeOfImpact = collisionPair.CollisionAlgorithm.CalculateTimeOfImpact(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult);
                        if (dispatchInfo.TimeOfImpact > timeOfImpact)
                        {
                            dispatchInfo.TimeOfImpact = timeOfImpact;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public BroadphasePair(BroadphasePair other)
        {
            _proxyA = other._proxyA;
            _proxyB = other._proxyB;

            _algorithm = other._algorithm;
            _userInfo  = null;
        }
Ejemplo n.º 3
0
		public void RemoveOverlappingPair(BroadphasePair pair)
		{
			if (!_overlappingPairs.Contains(pair))
				return;

			CleanOverlappingPair(ref pair);
			_overlappingPairs.Remove(pair);
		}
Ejemplo n.º 4
0
        public BroadphasePair(BroadphasePair other)
        {
            _proxyA = other._proxyA;
            _proxyB = other._proxyB;

            _algorithm = other._algorithm;
            _userInfo = null;
        }
Ejemplo n.º 5
0
        public override void ProcessAllOverlappingPairs(IOverlapCallback callback)
        {
            OverlappingPairs.Sort(new Comparison <BroadphasePair>(BroadphasePair.ComparisonSort));

            if (_invalidPair != 0)
            {
                OverlappingPairs.RemoveRange(OverlappingPairs.Count - _invalidPair, _invalidPair);
            }
            _invalidPair = 0;

            BroadphasePair previousPair = new BroadphasePair();

            previousPair.ProxyA             = null;
            previousPair.ProxyB             = null;
            previousPair.CollisionAlgorithm = null;

            List <BroadphasePair> removal = new List <BroadphasePair>();

            for (int i = 0; i < OverlappingPairs.Count; i++)
            {
                bool isDuplicate = (OverlappingPairs[i] == previousPair);
                previousPair = OverlappingPairs[i];
                bool needsRemoval;
                if (!isDuplicate)
                {
                    bool hasOverlap = TestOverlap(previousPair.ProxyA, previousPair.ProxyB);
                    if (hasOverlap)
                    {
                        needsRemoval = callback.ProcessOverlap(ref previousPair);
                    }
                    else
                    {
                        needsRemoval = true;
                    }
                }
                else
                {
                    needsRemoval = true;
                    BulletDebug.Assert(previousPair.CollisionAlgorithm == null);
                }

                if (needsRemoval)
                {
                    removal.Add(previousPair);
                }
            }

            for (int i = 0; i < removal.Count; i++)
            {
                BroadphasePair pair = removal[i];
                CleanOverlappingPair(ref pair);
                pair.ProxyA = null;
                pair.ProxyB = null;
                _invalidPair++;
                OverlappingPairCount--;
            }
        }
Ejemplo n.º 6
0
 public void CleanOverlappingPair(ref BroadphasePair pair)
 {
     if (pair.CollisionAlgorithm != null)
     {
         if (pair.CollisionAlgorithm is IDisposable)
             (pair.CollisionAlgorithm as IDisposable).Dispose();
         pair.CollisionAlgorithm = null;
     }
 }
Ejemplo n.º 7
0
        public void RemoveOverlappingPair(BroadphasePair pair)
        {
            if (!_overlappingPairs.Contains(pair))
            {
                return;
            }

            CleanOverlappingPair(ref pair);
            _overlappingPairs.Remove(pair);
        }
Ejemplo n.º 8
0
 public void CleanOverlappingPair(ref BroadphasePair pair)
 {
     if (pair.CollisionAlgorithm != null)
     {
         if (pair.CollisionAlgorithm is IDisposable)
         {
             (pair.CollisionAlgorithm as IDisposable).Dispose();
         }
         pair.CollisionAlgorithm = null;
     }
 }
Ejemplo n.º 9
0
 public void RemoveOverlappingPairsContainingProxy(BroadphaseProxy proxy)
 {
     for (int i = _overlappingPairs.Count - 1; i >= 0; i--)
     {
         BroadphasePair pair = _overlappingPairs[i];
         if (pair.ProxyA == proxy ||
             pair.ProxyB == proxy)
         {
             RemoveOverlappingPair(pair);
             i++;
         }
     }
 }
Ejemplo n.º 10
0
 public void CleanProxyFromPairs(BroadphaseProxy proxy)
 {
     for (int i = 0; i < _overlappingPairs.Count; i++)
     {
         BroadphasePair pair = _overlappingPairs[i];
         if (pair.ProxyA == proxy ||
             pair.ProxyB == proxy)
         {
             CleanOverlappingPair(ref pair);
             _overlappingPairs[i] = pair;
         }
     }
 }
Ejemplo n.º 11
0
		public void AddOverlappingPair(BroadphaseProxy proxyA, BroadphaseProxy proxyB)
		{
			//don't add overlap with own
			bool test = proxyA != proxyB;
            BulletDebug.Assert(proxyA != proxyB);

			if (!NeedsBroadphaseCollision(proxyA, proxyB))
				return;

			BroadphasePair pair = new BroadphasePair(proxyA, proxyB);
			_overlappingPairs.Add(pair);
			_overlappingPairCount++;
		}
Ejemplo n.º 12
0
		public static int ComparisonSort(BroadphasePair a, BroadphasePair b)
		{
			int aAId = a.ProxyA != null ? a.ProxyA.ComparisonID : -1;
			int aBId = a.ProxyB != null ? a.ProxyB.ComparisonID : -1;
			int aCId = a.CollisionAlgorithm != null ? a.CollisionAlgorithm.ComparisonID : -1;
			int bAId = b.ProxyA != null ? b.ProxyA.ComparisonID : -1;
			int bBId = b.ProxyB != null ? b.ProxyB.ComparisonID : -1;
			int bCId = b.CollisionAlgorithm != null ? b.CollisionAlgorithm.ComparisonID : -1;
			
			if	(aAId > bAId ||
				(a.ProxyA == b.ProxyA && aBId > bBId) ||
				(a.ProxyA == b.ProxyA && a.ProxyB == b.ProxyB && aCId > bCId))
				return -1;
			else
				return 1;
		}
Ejemplo n.º 13
0
		//this FindPair becomes really slow. Either sort the list to speedup the query, or
		//use a different solution. It is mainly used for Removing overlapping pairs. Removal could be delayed.
		//we could keep a linked list in each proxy, and store pair in one of the proxies (with lowest memory address)
		//Also we can use a 2D bitmap, which can be useful for a future GPU implementation
		public BroadphasePair FindPair(BroadphaseProxy proxyA, BroadphaseProxy proxyB)
		{
			if (!NeedsBroadphaseCollision(proxyA, proxyB))
				return null;

			BroadphasePair pair = new BroadphasePair(proxyA, proxyB);
			for (int i = 0; i < _overlappingPairs.Count; i++)
			{
				if (_overlappingPairs[i] == pair)
				{
					return _overlappingPairs[i];
				}
			}

			return null;
		}
Ejemplo n.º 14
0
        public void AddOverlappingPair(BroadphaseProxy proxyA, BroadphaseProxy proxyB)
        {
            //don't add overlap with own
            bool test = proxyA != proxyB;

            BulletDebug.Assert(proxyA != proxyB);

            if (!NeedsBroadphaseCollision(proxyA, proxyB))
            {
                return;
            }

            BroadphasePair pair = new BroadphasePair(proxyA, proxyB);

            _overlappingPairs.Add(pair);
            _overlappingPairCount++;
        }
Ejemplo n.º 15
0
        //this FindPair becomes really slow. Either sort the list to speedup the query, or
        //use a different solution. It is mainly used for Removing overlapping pairs. Removal could be delayed.
        //we could keep a linked list in each proxy, and store pair in one of the proxies (with lowest memory address)
        //Also we can use a 2D bitmap, which can be useful for a future GPU implementation
        public BroadphasePair FindPair(BroadphaseProxy proxyA, BroadphaseProxy proxyB)
        {
            if (!NeedsBroadphaseCollision(proxyA, proxyB))
            {
                return(null);
            }

            BroadphasePair pair = new BroadphasePair(proxyA, proxyB);

            for (int i = 0; i < _overlappingPairs.Count; i++)
            {
                if (_overlappingPairs[i] == pair)
                {
                    return(_overlappingPairs[i]);
                }
            }

            return(null);
        }
Ejemplo n.º 16
0
        public virtual void ProcessAllOverlappingPairs(IOverlapCallback callback)
        {
            List <BroadphasePair> deleting = new List <BroadphasePair>();

            for (int i = 0; i < _overlappingPairs.Count; i++)
            {
                BroadphasePair p = _overlappingPairs[i];
                if (callback.ProcessOverlap(ref p))
                {
                    CleanOverlappingPair(ref p);
                    deleting.Add(p);
                    _overlappingPairCount--;
                }
            }

            for (int i = 0; i < deleting.Count; i++)
            {
                _overlappingPairs.Remove(deleting[i]);
            }
        }
Ejemplo n.º 17
0
        public static int ComparisonSort(BroadphasePair a, BroadphasePair b)
        {
            int aAId = a.ProxyA != null ? a.ProxyA.ComparisonID : -1;
            int aBId = a.ProxyB != null ? a.ProxyB.ComparisonID : -1;
            int aCId = a.CollisionAlgorithm != null ? a.CollisionAlgorithm.ComparisonID : -1;
            int bAId = b.ProxyA != null ? b.ProxyA.ComparisonID : -1;
            int bBId = b.ProxyB != null ? b.ProxyB.ComparisonID : -1;
            int bCId = b.CollisionAlgorithm != null ? b.CollisionAlgorithm.ComparisonID : -1;

            if (aAId > bAId ||
                (a.ProxyA == b.ProxyA && aBId > bBId) ||
                (a.ProxyA == b.ProxyA && a.ProxyB == b.ProxyB && aCId > bCId))
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        }
Ejemplo n.º 18
0
		//by default, Bullet will use this near callback
		public static void DefaultNearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo)
		{
			CollisionObject collisionObjectA = collisionPair.ProxyA.ClientData as CollisionObject;
			CollisionObject collisionObjectB = collisionPair.ProxyB.ClientData as CollisionObject;

			if (dispatcher.NeedsCollision(collisionObjectA, collisionObjectB))
			{
				//dispatcher will keep algorithms persistent in the collision pair
				if (collisionPair.CollisionAlgorithm == null)
				{
					collisionPair.CollisionAlgorithm = dispatcher.FindAlgorithm(collisionObjectA, collisionObjectB);
				}

				if (collisionPair.CollisionAlgorithm != null)
				{
					ManifoldResult contactPointResult = new ManifoldResult(collisionObjectA, collisionObjectB);

					if (dispatchInfo.DispatchFunction == DispatchFunction.Discrete)
					{
						//discrete collision detection query
						collisionPair.CollisionAlgorithm.ProcessCollision(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult);
					}
					else
					{
						//continuous collision detection query, time of impact (toi)
						float timeOfImpact = collisionPair.CollisionAlgorithm.CalculateTimeOfImpact(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult);
						if (dispatchInfo.TimeOfImpact > timeOfImpact)
							dispatchInfo.TimeOfImpact = timeOfImpact;
					}
				}
			}
		}
Ejemplo n.º 19
0
		public bool ProcessOverlap(ref BroadphasePair pair)
		{
			_dispatcher.NearCallback(ref pair, _dispatcher, _dispatchInfo);
			return false;
		}
Ejemplo n.º 20
0
		public override void ProcessAllOverlappingPairs(IOverlapCallback callback)
		{
			OverlappingPairs.Sort(new Comparison<BroadphasePair>(BroadphasePair.ComparisonSort));

			if (_invalidPair != 0)
				OverlappingPairs.RemoveRange(OverlappingPairs.Count - _invalidPair, _invalidPair);
			_invalidPair = 0;

			BroadphasePair previousPair = new BroadphasePair();
			previousPair.ProxyA = null;
			previousPair.ProxyB = null;
			previousPair.CollisionAlgorithm = null;

			List<BroadphasePair> removal = new List<BroadphasePair>();

			for (int i = 0; i < OverlappingPairs.Count; i++)
			{
				bool isDuplicate = (OverlappingPairs[i] == previousPair);
				previousPair = OverlappingPairs[i];
				bool needsRemoval;
				if (!isDuplicate)
				{
					bool hasOverlap = TestOverlap(previousPair.ProxyA, previousPair.ProxyB);
					if (hasOverlap)
					{
						needsRemoval = callback.ProcessOverlap(ref previousPair);
					}
					else
					{
						needsRemoval = true;
					}
				}
				else
				{
					needsRemoval = true;
					BulletDebug.Assert(previousPair.CollisionAlgorithm == null);
				}

				if (needsRemoval)
				{
					removal.Add(previousPair);
				}
			}

			for (int i = 0; i < removal.Count; i++)
			{
				BroadphasePair pair = removal[i];
				CleanOverlappingPair(ref pair);
				pair.ProxyA = null;
				pair.ProxyB = null;
				_invalidPair++;
				OverlappingPairCount--;
			}
		}
Ejemplo n.º 21
0
 public bool ProcessOverlap(ref BroadphasePair pair)
 {
     return (!SimpleBroadphase.AabbOverlap(pair.ProxyA as SimpleBroadphaseProxy, pair.ProxyB as SimpleBroadphaseProxy));
 }
Ejemplo n.º 22
0
 public bool ProcessOverlap(ref BroadphasePair pair)
 {
     _dispatcher.NearCallback(ref pair, _dispatcher, _dispatchInfo);
     return(false);
 }
Ejemplo n.º 23
0
 public bool ProcessOverlap(ref BroadphasePair pair)
 {
     return(!SimpleBroadphase.AabbOverlap(pair.ProxyA as SimpleBroadphaseProxy, pair.ProxyB as SimpleBroadphaseProxy));
 }