/// <summary>
        /// Update the pairs. This results in pair callbacks. This can only add pairs.
        /// </summary>
        /// <param name="callback">The callback.</param>
        public void UpdatePairs(BroadphaseHandler callback)
        {
            // Reset pair buffer
            _pairCount = 0;

            // Perform tree queries for all moving proxies.
            for (int j = 0; j < _moveCount; ++j)
            {
                _queryProxyId = _moveBuffer[j];
                if (_queryProxyId == NullProxy)
                {
                    continue;
                }

                AABB fatAABB;

                // We have to query the tree with the fat AABB so that
                // we don't fail to create a pair that may touch later.
                _tree.GetFatAABB(_queryProxyId, out fatAABB);

                // Query tree, create pairs and add them pair buffer.
                _tree.Query(_queryCallback, ref fatAABB);
            }

            // Reset move buffer
            _moveCount = 0;

            // Sort the pair buffer to expose duplicates.
            Array.Sort(_pairBuffer, 0, _pairCount);

            // Send the pairs back to the client.
            int i = 0;

            while (i < _pairCount)
            {
                Pair         primaryPair = _pairBuffer[i];
                FixtureProxy userDataA   = _tree.GetUserData(primaryPair.ProxyIdA);
                FixtureProxy userDataB   = _tree.GetUserData(primaryPair.ProxyIdB);

                callback(ref userDataA, ref userDataB);
                ++i;

                // Skip any duplicate pairs.
                while (i < _pairCount)
                {
                    Pair pair = _pairBuffer[i];
                    if (pair.ProxyIdA != primaryPair.ProxyIdA || pair.ProxyIdB != primaryPair.ProxyIdB)
                    {
                        break;
                    }

                    ++i;
                }
            }

            // Try to keep the tree balanced.
            //_tree.Rebalance(4);
        }
Beispiel #2
0
        /// <summary>Update the pairs. This results in pair callbacks. This can only add pairs.</summary>
        /// <param name="callback">The callback.</param>
        public void UpdatePairs(BroadphaseHandler callback)
        {
            // Reset pair buffer
            pairCount = 0;

            // Perform tree queries for all moving proxies.
            for (int i = 0; i < moveCount; ++i)
            {
                queryProxyId = moveBuffer[i];
                if (queryProxyId == NullProxy)
                {
                    continue;
                }

                // We have to query the tree with the fat AABB so that
                // we don't fail to create a pair that may touch later.
                tree.GetFatAabb(queryProxyId, out Aabb fatAabb);

                // Query tree, create pairs and add them pair buffer.
                tree.Query(queryCallback, ref fatAabb);
            }

            for (int i = 0; i < pairCount; ++i)
            {
                Pair         primaryPair = pairBuffer[i];
                FixtureProxy userDataA   = tree.GetUserData(primaryPair.ProxyIdA);
                FixtureProxy userDataB   = tree.GetUserData(primaryPair.ProxyIdB);

                callback(ref userDataA, ref userDataB);
            }

            // Clear move flags
            for (int i = 0; i < moveCount; ++i)
            {
                int proxyId = moveBuffer[i];
                if (proxyId == NullProxy)
                {
                    continue;
                }

                tree.ClearMoved(proxyId);
            }

            // Reset move buffer
            moveCount = 0;
        }
 internal ContactManager(IBroadPhase broadPhase)
 {
     BroadPhase            = broadPhase;
     OnBroadphaseCollision = AddPair;
     ContactList           = new List <Contact>(128);
 }
Beispiel #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ContactManager" /> class
 /// </summary>
 /// <param name="broadPhase">The broad phase</param>
 internal ContactManager(IBroadPhase broadPhase)
 {
     BroadPhase            = broadPhase;
     OnBroadphaseCollision = AddPair;
 }