Beispiel #1
0
        public BroadphasePair(BroadphasePair other)
        {
            _proxyA = other._proxyA;
            _proxyB = other._proxyB;

            _algorithm = other._algorithm;
            _userInfo = null;
        }
Beispiel #2
0
        public BroadphasePair(BroadphaseProxy proxyA, BroadphaseProxy proxyB)
        {
            _proxyA = proxyA;
            _proxyB = proxyB;

            _algorithm = null;
            _userInfo = null;
        }
		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++;
		}
		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;
				}
			}
		}
Beispiel #5
0
        public override BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask)
        {
            if (_proxies.Count >= _maxProxies)
            {
                BulletDebug.Assert(false);
                return null; //should never happen, but don't let the game crash ;-)
            }
            BulletDebug.Assert(min.X <= max.X && min.Y <= max.Y && min.Z <= max.Z);

            SimpleBroadphaseProxy proxy = new SimpleBroadphaseProxy(min, max, shapeType, userData, collisionFilterGroup, collisionFilterMask);
            _proxies.Add(proxy);

            return proxy;
        }
		//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;
		}
 private SimpleBroadphaseProxy GetSimpleProxyFromProxy(BroadphaseProxy proxy)
 {
     return(proxy as SimpleBroadphaseProxy);
 }
		public abstract void SetAabb(BroadphaseProxy proxy, Microsoft.Xna.Framework.Vector3 aabbMin, Microsoft.Xna.Framework.Vector3 aabbMax);
Beispiel #9
0
 public abstract void DestroyProxy(BroadphaseProxy proxy);
Beispiel #10
0
 public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax)
 {
     SimpleBroadphaseProxy simpleProxy = GetSimpleProxyFromProxy(proxy);
     simpleProxy.Minimum = aabbMin;
     simpleProxy.Maximum = aabbMax;
 }
Beispiel #11
0
 public override void DestroyProxy(BroadphaseProxy proxy)
 {
     Handle handle = proxy as Handle;
     RemoveHandle(handle.HandleID);
 }
Beispiel #12
0
		private bool TestOverlap(BroadphaseProxy proxyA, BroadphaseProxy proxyB)
		{
			if (proxyA == null || proxyB == null)
				return false;

			Handle handleA = proxyA as Handle;
			Handle handleB = proxyB as Handle;

			for (int axis = 0; axis < 3; axis++)
			{
				if (handleA.MaxEdges[axis] < handleB.MinEdges[axis] ||
					handleB.MaxEdges[axis] < handleA.MinEdges[axis])
				{
					return false;
				}
			}
			return true;
		}
		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++;
				}
			}
		}
 public override void DestroyProxy(BroadphaseProxy proxy)
 {
     RemoveOverlappingPairsContainingProxy(proxy);
     _proxies.Remove(proxy as SimpleBroadphaseProxy);
 }
Beispiel #15
0
        public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax)
        {
            Handle handle = proxy as Handle;

            UpdateHandle(handle.HandleID, aabbMin, aabbMax);
        }
Beispiel #16
0
        public override void DestroyProxy(BroadphaseProxy proxy)
        {
            Handle handle = proxy as Handle;

            RemoveHandle(handle.HandleID);
        }
Beispiel #17
0
 public abstract void SetAabb(BroadphaseProxy proxy, MonoXnaCompactMaths.Vector3 aabbMin, MonoXnaCompactMaths.Vector3 aabbMax);
		public abstract BroadphaseProxy CreateProxy(MonoXnaCompactMaths.Vector3 min, MonoXnaCompactMaths.Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask);
		public abstract void SetAabb(BroadphaseProxy proxy, MonoXnaCompactMaths.Vector3 aabbMin, MonoXnaCompactMaths.Vector3 aabbMax);
Beispiel #20
0
        public ushort AddHandle(Vector3 aabbMin, Vector3 aabbMax, object owner, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask)
        {
            ushort[] min = new ushort[3], max = new ushort[3];
            Quantize(out min, aabbMin, 0);
            Quantize(out max, aabbMax, 1);

            ushort handle = AllocateHandle();
            Handle oHandle = GetHandle(handle);

            oHandle.HandleID = handle;
            oHandle.ClientData = owner;
            oHandle.CollisionFilterGroup = collisionFilterGroup;
            oHandle.CollisionFilterMask = collisionFilterMask;

            int limit = _numHandles * 2;

            // (Gluk    )
            //  ( Inside )
            for (int axis = 0; axis < 3; axis++)
            {
                _handles[0].MaxEdges[axis] += 2;

                _edges[axis][limit + 1].Position = _edges[axis][limit - 1].Position;
                _edges[axis][limit + 1].Handle = _edges[axis][limit - 1].Handle;

                _edges[axis][limit - 1].Position = min[axis];
                _edges[axis][limit - 1].Handle = handle;

                _edges[axis][limit].Position = max[axis];
                _edges[axis][limit].Handle = handle;

                oHandle.MinEdges[axis] = (ushort)(limit - 1);
                oHandle.MaxEdges[axis] = (ushort)limit;
            }

            SortMinDown(0, oHandle.MinEdges[0], false);
            SortMaxDown(0, oHandle.MaxEdges[0], false);
            SortMinDown(1, oHandle.MinEdges[1], false);
            SortMaxDown(1, oHandle.MaxEdges[1], false);
            SortMinDown(2, oHandle.MinEdges[2], true);
            SortMaxDown(2, oHandle.MaxEdges[2], true);

            return handle;
        }
Beispiel #21
0
		public void AddCollisionObject(CollisionObject collisionObject, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask)
		{
			//check that the object isn't already added
			if (!_collisionObjects.Contains(collisionObject))
			{
				_collisionObjects.Add(collisionObject);

				//calculate new AABB
				Matrix trans = collisionObject.WorldTransform;

				Vector3 minAabb;
				Vector3 maxAabb;
				collisionObject.CollisionShape.GetAabb(trans, out minAabb, out maxAabb);

				BroadphaseNativeTypes type = collisionObject.CollisionShape.ShapeType;
				collisionObject.Broadphase = Broadphase.CreateProxy(
					minAabb,
					maxAabb,
					type,
					collisionObject,
					collisionFilterGroup,
					collisionFilterMask
					);
			}
		}
Beispiel #22
0
        public override BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask)
        {
		    ushort handleId = AddHandle(min, max, userData, collisionFilterGroup, collisionFilterMask);
    		
		    Handle handle = GetHandle(handleId);
    				
		    return handle;
        }
		public bool NeedsBroadphaseCollision(BroadphaseProxy proxy0, BroadphaseProxy proxy1)
		{
			bool collides = (proxy0.CollisionFilterGroup & proxy1.CollisionFilterMask) != 0;
			collides = collides && ((proxy1.CollisionFilterGroup & proxy0.CollisionFilterMask) != 0);

			return collides;
		}
Beispiel #24
0
 public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax)
 {
     Handle handle = proxy as Handle;
     UpdateHandle(handle.HandleID, aabbMin, aabbMax);
 }
		public abstract BroadphaseProxy CreateProxy(Microsoft.Xna.Framework.Vector3 min, Microsoft.Xna.Framework.Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask);
Beispiel #26
0
 private SimpleBroadphaseProxy GetSimpleProxyFromProxy(BroadphaseProxy proxy)
 {
     return proxy as SimpleBroadphaseProxy;
 }
		public abstract void DestroyProxy(BroadphaseProxy proxy);
Beispiel #28
0
 public override void DestroyProxy(BroadphaseProxy proxy)
 {
     RemoveOverlappingPairsContainingProxy(proxy);
     _proxies.Remove(proxy as SimpleBroadphaseProxy);
 }
Beispiel #29
0
 public abstract void SetAabb(BroadphaseProxy proxy, Microsoft.Xna.Framework.Vector3 aabbMin, Microsoft.Xna.Framework.Vector3 aabbMax);