Box2D.Collision.Broadphase.DynamicTree.MoveProxy C# (CSharp) Метод

MoveProxy() публичный Метод

Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the proxy is removed from the tree and re-inserted. Otherwise the function returns immediately.
public MoveProxy ( int proxyId, AABB aabb, Vec2 displacement ) : bool
proxyId int
aabb AABB
displacement Box2D.Common.Vec2
Результат bool
        public bool MoveProxy(int proxyId, AABB aabb, Vec2 displacement)
        {
            Debug.Assert(0 <= proxyId && proxyId < m_nodeCapacity);
            TreeNode node = m_nodes[proxyId];
            Debug.Assert(node.Leaf);

            if (node.AABB.Contains(aabb))
            {
                return false;
            }

            RemoveLeaf(proxyId);

            // Extend AABB
            Vec2 lowerBound = aabb.LowerBound;
            Vec2 upperBound = aabb.UpperBound;
            lowerBound.X -= Settings.AABB_EXTENSION;
            lowerBound.Y -= Settings.AABB_EXTENSION;
            upperBound.X += Settings.AABB_EXTENSION;
            upperBound.Y += Settings.AABB_EXTENSION;

            // Predict AABB displacement.
            float dx = displacement.X * Settings.AABB_MULTIPLIER;
            float dy = displacement.Y * Settings.AABB_MULTIPLIER;
            if (dx < 0.0f)
            {
                lowerBound.X += dx;
            }
            else
            {
                upperBound.X += dx;
            }

            if (dy < 0.0f)
            {
                lowerBound.Y += dy;
            }
            else
            {
                upperBound.Y += dy;
            }
            node.AABB.LowerBound.X = lowerBound.X;
            node.AABB.LowerBound.Y = lowerBound.Y;
            node.AABB.UpperBound.X = upperBound.X;
            node.AABB.UpperBound.Y = upperBound.Y;

            InsertLeaf(proxyId);
            return true;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Call MoveProxy as many times as you like, then when you are done call UpdatePairs to finalized
        /// the proxy pairs (for your time step).
        /// </summary>
        public void MoveProxy(int proxyId, AABB aabb, Vec2 displacement)
        {
            bool buffer = m_tree.MoveProxy(proxyId, aabb, displacement);

            if (buffer)
            {
                BufferMove(proxyId);
            }
        }