コード例 #1
0
ファイル: BroadPhase.cs プロジェクト: vb0067/LGame
        /// Update the pairs. This results in pair callbacks. This can only add pairs.
        public void UpdatePairs(ContactManager 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.
                AABB fatAABB = _tree.GetFatAABB(_queryProxyId);

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

            // Reset move buffer
            _moveCount = 0;

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

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

            while (j < _pairCount)
            {
                Pair   primaryPair = _pairBuffer[j];
                object userDataA   = _tree.GetUserData(primaryPair.proxyIdA);
                object userDataB   = _tree.GetUserData(primaryPair.proxyIdB);

                callback.AddPair(userDataA, userDataB);
                ++j;

                // Skip any duplicate pairs.
                while (j < _pairCount)
                {
                    Pair pair = _pairBuffer[j];
                    if (pair.proxyIdA != primaryPair.proxyIdA || pair.proxyIdB != primaryPair.proxyIdB)
                    {
                        break;
                    }
                    ++j;
                }
            }
        }