Пример #1
0
        public Island(int bodyCapacity, int contactCapacity, int jointCapacity, ContactListener listener)
        {
            _bodyCapacity    = bodyCapacity;
            _contactCapacity = contactCapacity;
            _jointCapacity   = jointCapacity;
            //__bodyCount = 0;
            //_contactCount = 0;
            //_jointCount = 0;

            _listener = listener;

            _bodies   = new Body[bodyCapacity];
            _contacts = new Contact[contactCapacity];
            _joints   = new Joint[jointCapacity];

            _velocities = new Velocity[_bodyCapacity];
            _positions  = new Position[_bodyCapacity];
        }
Пример #2
0
        public void Update(ContactListener listener)
        {
            Manifold oldManifold = _manifold.Clone();

            Evaluate();

            Body bodyA = _fixtureA.Body;
            Body bodyB = _fixtureB.Body;

            int oldCount = oldManifold.PointCount;
            int newCount = _manifold.PointCount;

            if (newCount == 0 && oldCount > 0)
            {
                bodyA.WakeUp();
                bodyB.WakeUp();
            }

            // Slow contacts don't generate TOI events.
            if (bodyA.IsStatic() || bodyA.IsBullet() || bodyB.IsStatic() || bodyB.IsBullet())
            {
                _flags &= ~CollisionFlags.Slow;
            }
            else
            {
                _flags |= CollisionFlags.Slow;
            }

            // Match old contact ids to new contact ids and copy the
            // stored impulses to warm start the solver.
            for (int i = 0; i < _manifold.PointCount; ++i)
            {
                ManifoldPoint mp2 = _manifold.Points[i];
                mp2.NormalImpulse  = 0.0f;
                mp2.TangentImpulse = 0.0f;
                ContactID id2 = mp2.ID;

                for (int j = 0; j < oldManifold.PointCount; ++j)
                {
                    ManifoldPoint mp1 = oldManifold.Points[j];

                    if (mp1.ID.Key == id2.Key)
                    {
                        mp2.NormalImpulse  = mp1.NormalImpulse;
                        mp2.TangentImpulse = mp1.TangentImpulse;
                        break;
                    }
                }
            }

            if (oldCount == 0 && newCount > 0)
            {
                _flags |= CollisionFlags.Touch;
                if (listener != null)
                {
                    listener.BeginContact(this);
                }
            }

            if (oldCount > 0 && newCount == 0)
            {
                _flags &= ~CollisionFlags.Touch;
                if (listener != null)
                {
                    listener.EndContact(this);
                }
            }

            if ((_flags & CollisionFlags.NonSolid) == 0)
            {
                if (listener != null)
                {
                    listener.PreSolve(this, oldManifold);
                }

                // The user may have disabled contact.
                if (_manifold.PointCount == 0)
                {
                    _flags &= ~CollisionFlags.Touch;
                }
            }
        }