Ejemplo n.º 1
0
 public World(AABB worldAABB, Vec2 gravity, bool doSleep)
 {
     this._destructionListener = null;
     this._boundaryListener = null;
     this._contactFilter = WorldCallback.DefaultFilter;
     this._contactListener = null;
     this._debugDraw = null;
     this._bodyList = null;
     this._contactList = null;
     this._jointList = null;
     this._bodyCount = 0;
     this._contactCount = 0;
     this._jointCount = 0;
     this._warmStarting = true;
     this._continuousPhysics = true;
     this._allowSleep = doSleep;
     this._gravity = gravity;
     this._lock = false;
     this._inv_dt0 = 0f;
     this._contactManager = new ContactManager();
     this._contactManager._world = this;
     this._broadPhase = new BroadPhase(worldAABB, this._contactManager);
     BodyDef def = new BodyDef();
     this._groundBody = this.CreateBody(def);
 }
Ejemplo n.º 2
0
        public void Update(ContactListener listener)
        {
            int oldCount = GetManifoldCount();

            Evaluate(listener);

            int newCount = GetManifoldCount();

            Body body1 = _shape1.GetBody();
            Body body2 = _shape2.GetBody();

            if (newCount == 0 && oldCount > 0)
            {
                body1.WakeUp();
                body2.WakeUp();
            }

            // Slow contacts don't generate TOI events.
            if (body1.IsStatic() || body1.IsBullet() || body2.IsStatic() || body2.IsBullet())
            {
                _flags &= ~CollisionFlags.Slow;
            }
            else
            {
                _flags |= CollisionFlags.Slow;
            }
        }
Ejemplo n.º 3
0
        public ContactManager()
        {
            _broadPhase = new BroadPhase();
            _defaultFilter = new ContactFilter();
            _defaultListener = new ContactListener();

            _contactList = null;
            _contactCount = 0;
            _contactFilter = _defaultFilter;
            _contactListener = _defaultListener;
        }
Ejemplo n.º 4
0
        public ContactManager()
        {
            _broadPhase      = new BroadPhase();
            _defaultFilter   = new ContactFilter();
            _defaultListener = new ContactListener();

            _contactList     = null;
            _contactCount    = 0;
            _contactFilter   = _defaultFilter;
            _contactListener = _defaultListener;
        }
Ejemplo n.º 5
0
 public Island(int bodyCapacity, int contactCapacity, int jointCapacity, ContactListener listener)
 {
     this._bodyCapacity    = bodyCapacity;
     this._contactCapacity = contactCapacity;
     this._jointCapacity   = jointCapacity;
     this._bodyCount       = 0;
     this._contactCount    = 0;
     this._jointCount      = 0;
     this._listener        = listener;
     this._bodies          = new Body[bodyCapacity];
     this._contacts        = new Contact[contactCapacity];
     this._joints          = new Joint[jointCapacity];
     this._velocities      = new Velocity[this._bodyCapacity];
     this._positions       = new Position[this._bodyCapacity];
 }
Ejemplo n.º 6
0
 public Island(int bodyCapacity, int contactCapacity, int jointCapacity, ContactListener listener)
 {
     this._bodyCapacity = bodyCapacity;
     this._contactCapacity = contactCapacity;
     this._jointCapacity = jointCapacity;
     this._bodyCount = 0;
     this._contactCount = 0;
     this._jointCount = 0;
     this._listener = listener;
     this._bodies = new Body[bodyCapacity];
     this._contacts = new Contact[contactCapacity];
     this._joints = new Joint[jointCapacity];
     this._velocities = new Velocity[this._bodyCapacity];
     this._positions = new Position[this._bodyCapacity];
 }
Ejemplo n.º 7
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];
        }
Ejemplo n.º 8
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];
        }
Ejemplo n.º 9
0
        public void Update(ContactListener listener)
        {
            int manifoldCount = this.GetManifoldCount();

            this.Evaluate(listener);
            int  manifoldCount2 = this.GetManifoldCount();
            Body body           = this._shape1.GetBody();
            Body body2          = this._shape2.GetBody();

            if (manifoldCount2 == 0 && manifoldCount > 0)
            {
                body.WakeUp();
                body2.WakeUp();
            }
            if (body.IsStatic() || body.IsBullet() || body2.IsStatic() || body2.IsBullet())
            {
                this._flags &= ~Contact.CollisionFlags.Slow;
            }
            else
            {
                this._flags |= Contact.CollisionFlags.Slow;
            }
        }
Ejemplo n.º 10
0
        public override void Evaluate(ContactListener listener)
        {
            Body b1 = _shape1.GetBody();
            Body b2 = _shape2.GetBody();

#warning "needfix"
            //memcpy(&m0, &m_manifold, sizeof(b2Manifold));
            Manifold m0 = _manifold.Clone();

            Collision.Collision.CollidePolygons(ref _manifold, (PolygonShape)_shape1, b1.GetXForm(),
                                                (PolygonShape)_shape2, b2.GetXForm());

            bool[] persisted = new bool[] { false, false };

            ContactPoint cp = new ContactPoint();
            cp.Shape1      = _shape1;
            cp.Shape2      = _shape2;
            cp.Friction    = Settings.MixFriction(_shape1.Friction, _shape2.Friction);
            cp.Restitution = Settings.MixRestitution(_shape1.Restitution, _shape2.Restitution);

            // Match contact ids to facilitate warm starting.
            if (_manifold.PointCount > 0)
            {
                // 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 mp = _manifold.Points[i];
                    mp.NormalImpulse  = 0.0f;
                    mp.TangentImpulse = 0.0f;
                    bool      found = false;
                    ContactID id    = mp.ID;

                    for (int j = 0; j < m0.PointCount; ++j)
                    {
                        if (persisted[j] == true)
                        {
                            continue;
                        }

                        ManifoldPoint mp0 = m0.Points[j];

                        if (mp0.ID.Key == id.Key)
                        {
                            persisted[j]      = true;
                            mp.NormalImpulse  = mp0.NormalImpulse;
                            mp.TangentImpulse = mp0.TangentImpulse;

                            // A persistent point.
                            found = true;

                            // Report persistent point.
                            if (listener != null)
                            {
                                cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
                                Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
                                Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
                                cp.Velocity   = v2 - v1;
                                cp.Normal     = _manifold.Normal;
                                cp.Separation = mp.Separation;
                                cp.ID         = id;
                                listener.Persist(cp);
                            }
                            break;
                        }
                    }

                    // Report added point.
                    if (found == false && listener != null)
                    {
                        cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
                        Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
                        Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
                        cp.Velocity   = v2 - v1;
                        cp.Normal     = _manifold.Normal;
                        cp.Separation = mp.Separation;
                        cp.ID         = id;
                        listener.Add(cp);
                    }
                }

                _manifoldCount = 1;
            }
            else
            {
                _manifoldCount = 0;
            }

            if (listener == null)
            {
                return;
            }

            // Report removed points.
            for (int i = 0; i < m0.PointCount; ++i)
            {
                if (persisted[i])
                {
                    continue;
                }

                ManifoldPoint mp0 = m0.Points[i];
                cp.Position = b1.GetWorldPoint(mp0.LocalPoint1);
                Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp0.LocalPoint1);
                Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp0.LocalPoint2);
                cp.Velocity   = v2 - v1;
                cp.Normal     = m0.Normal;
                cp.Separation = mp0.Separation;
                cp.ID         = mp0.ID;
                listener.Remove(cp);
            }
        }
Ejemplo n.º 11
0
        public void Update(ContactListener listener)
        {
            //Note: Manifold is a class, not a struct. It will reference the old manifest, not copy it - DONE
            Manifold oldManifold = new Manifold();

            oldManifold.LocalPlaneNormal = Manifold.LocalPlaneNormal;
            oldManifold.LocalPoint       = Manifold.LocalPoint;
            oldManifold.PointCount       = Manifold.PointCount;
            oldManifold.Points           = Manifold.Points;
            oldManifold.Type             = Manifold.Type;

            // Re-enable this contact.
            Flags &= ~ContactFlag.DisabledFlag;

            if (Collision.Collision.TestOverlap(_fixtureA.Aabb, _fixtureB.Aabb))
            {
                Evaluate();
            }
            else
            {
                Manifold.PointCount = 0;
            }

            Body bodyA = _fixtureA.GetBody();
            Body bodyB = _fixtureB.GetBody();

            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 |= ContactFlag.ContinuousFlag;
            }
            else
            {
                Flags &= ~ContactFlag.ContinuousFlag;
            }

            // 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 (newCount > 0)
            {
                Flags |= ContactFlag.TouchingFlag;
            }
            else
            {
                Flags &= ~ContactFlag.TouchingFlag;
            }

            if (oldCount == 0 && newCount > 0)
            {
                listener.BeginContact(this);
            }

            if (oldCount > 0 && newCount == 0)
            {
                listener.EndContact(this);
            }

            if ((Flags & ContactFlag.SensorFlag) == 0)
            {
                listener.PreSolve(this, oldManifold);
            }
        }
Ejemplo n.º 12
0
		public void Update(ContactListener listener)
		{
			int oldCount = GetManifoldCount();

			Evaluate(listener);

			int newCount = GetManifoldCount();

			Body body1 = _shape1.GetBody();
			Body body2 = _shape2.GetBody();

			if (newCount == 0 && oldCount > 0)
			{
				body1.WakeUp();
				body2.WakeUp();
			}

			// Slow contacts don't generate TOI events.
			if (body1.IsStatic() || body1.IsBullet() || body2.IsStatic() || body2.IsBullet())
			{
				_flags &= ~CollisionFlags.Slow;
			}
			else
			{
				_flags |= CollisionFlags.Slow;
			}
		}
Ejemplo n.º 13
0
		/// <summary>
		/// Construct a world object.
		/// </summary>
		/// <param name="worldAABB">A bounding box that completely encompasses all your shapes.</param>
		/// <param name="gravity">The world gravity vector.</param>
		/// <param name="doSleep">Improve performance by not simulating inactive bodies.</param>
		public World(AABB worldAABB, Vec2 gravity, bool doSleep)
		{
			_destructionListener = null;
			_boundaryListener = null;
			_contactFilter = WorldCallback.DefaultFilter;
			_contactListener = null;
			_debugDraw = null;

			_bodyList = null;
			_contactList = null;
			_jointList = null;

			_bodyCount = 0;
			_contactCount = 0;
			_jointCount = 0;

			_warmStarting = true;
			_continuousPhysics = true;

			_allowSleep = doSleep;
			_gravity = gravity;

			_lock = false;

			_inv_dt0 = 0.0f;

			_contactManager = new ContactManager();
			_contactManager._world = this;
			_broadPhase = new BroadPhase(worldAABB, _contactManager);

			BodyDef bd = new BodyDef();
			_groundBody = CreateBody(bd);
		}
Ejemplo n.º 14
0
 public void Update(ContactListener listener)
 {
     int manifoldCount = this.GetManifoldCount();
     this.Evaluate(listener);
     int manifoldCount2 = this.GetManifoldCount();
     Body body = this._shape1.GetBody();
     Body body2 = this._shape2.GetBody();
     if (manifoldCount2 == 0 && manifoldCount > 0)
     {
         body.WakeUp();
         body2.WakeUp();
     }
     if (body.IsStatic() || body.IsBullet() || body2.IsStatic() || body2.IsBullet())
     {
         this._flags &= ~Contact.CollisionFlags.Slow;
     }
     else
     {
         this._flags |= Contact.CollisionFlags.Slow;
     }
 }
Ejemplo n.º 15
0
        public override void Evaluate(ContactListener listener)
        {
            Body     body     = this._shape1.GetBody();
            Body     body2    = this._shape2.GetBody();
            Manifold manifold = this._manifold.Clone();

            Collision.Collision.CollideCircles(ref this._manifold, (CircleShape)this._shape1, body.GetXForm(), (CircleShape)this._shape2, body2.GetXForm());
            ContactPoint contactPoint = new ContactPoint();

            contactPoint.Shape1      = this._shape1;
            contactPoint.Shape2      = this._shape2;
            contactPoint.Friction    = Settings.MixFriction(this._shape1.Friction, this._shape2.Friction);
            contactPoint.Restitution = Settings.MixRestitution(this._shape1.Restitution, this._shape2.Restitution);
            if (this._manifold.PointCount > 0)
            {
                this._manifoldCount = 1;
                ManifoldPoint manifoldPoint = this._manifold.Points[0];
                if (manifold.PointCount == 0)
                {
                    manifoldPoint.NormalImpulse  = 0f;
                    manifoldPoint.TangentImpulse = 0f;
                    if (listener != null)
                    {
                        contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                        contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                        contactPoint.Normal     = this._manifold.Normal;
                        contactPoint.Separation = manifoldPoint.Separation;
                        contactPoint.ID         = manifoldPoint.ID;
                        listener.Add(contactPoint);
                    }
                }
                else
                {
                    ManifoldPoint manifoldPoint2 = manifold.Points[0];
                    manifoldPoint.NormalImpulse  = manifoldPoint2.NormalImpulse;
                    manifoldPoint.TangentImpulse = manifoldPoint2.TangentImpulse;
                    if (listener != null)
                    {
                        contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                        contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                        contactPoint.Normal     = this._manifold.Normal;
                        contactPoint.Separation = manifoldPoint.Separation;
                        contactPoint.ID         = manifoldPoint.ID;
                        listener.Persist(contactPoint);
                    }
                }
            }
            else
            {
                this._manifoldCount = 0;
                if (manifold.PointCount > 0 && listener != null)
                {
                    ManifoldPoint manifoldPoint2 = manifold.Points[0];
                    contactPoint.Position = body.GetWorldPoint(manifoldPoint2.LocalPoint1);
                    Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint1);
                    Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint2);
                    contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                    contactPoint.Normal     = manifold.Normal;
                    contactPoint.Separation = manifoldPoint2.Separation;
                    contactPoint.ID         = manifoldPoint2.ID;
                    listener.Remove(contactPoint);
                }
            }
        }
Ejemplo n.º 16
0
        public override void Evaluate(ContactListener listener)
        {
            Body     body     = this._shape1.GetBody();
            Body     body2    = this._shape2.GetBody();
            Manifold manifold = this._manifold.Clone();

            Collision.Collision.CollidePolygons(ref this._manifold, (PolygonShape)this._shape1, body.GetXForm(), (PolygonShape)this._shape2, body2.GetXForm());
            bool[]       array        = new bool[2];
            bool[]       array2       = array;
            ContactPoint contactPoint = new ContactPoint();

            contactPoint.Shape1      = this._shape1;
            contactPoint.Shape2      = this._shape2;
            contactPoint.Friction    = Settings.MixFriction(this._shape1.Friction, this._shape2.Friction);
            contactPoint.Restitution = Settings.MixRestitution(this._shape1.Restitution, this._shape2.Restitution);
            if (this._manifold.PointCount > 0)
            {
                for (int i = 0; i < this._manifold.PointCount; i++)
                {
                    ManifoldPoint manifoldPoint = this._manifold.Points[i];
                    manifoldPoint.NormalImpulse  = 0f;
                    manifoldPoint.TangentImpulse = 0f;
                    bool      flag = false;
                    ContactID iD   = manifoldPoint.ID;
                    for (int j = 0; j < manifold.PointCount; j++)
                    {
                        if (!array2[j])
                        {
                            ManifoldPoint manifoldPoint2 = manifold.Points[j];
                            if (manifoldPoint2.ID.Key == iD.Key)
                            {
                                array2[j] = true;
                                manifoldPoint.NormalImpulse  = manifoldPoint2.NormalImpulse;
                                manifoldPoint.TangentImpulse = manifoldPoint2.TangentImpulse;
                                flag = true;
                                if (listener != null)
                                {
                                    contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                                    Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                                    Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                                    contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                                    contactPoint.Normal     = this._manifold.Normal;
                                    contactPoint.Separation = manifoldPoint.Separation;
                                    contactPoint.ID         = iD;
                                    listener.Persist(contactPoint);
                                }
                                break;
                            }
                        }
                    }
                    if (!flag && listener != null)
                    {
                        contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                        contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                        contactPoint.Normal     = this._manifold.Normal;
                        contactPoint.Separation = manifoldPoint.Separation;
                        contactPoint.ID         = iD;
                        listener.Add(contactPoint);
                    }
                }
                this._manifoldCount = 1;
            }
            else
            {
                this._manifoldCount = 0;
            }
            if (listener != null)
            {
                for (int i = 0; i < manifold.PointCount; i++)
                {
                    if (!array2[i])
                    {
                        ManifoldPoint manifoldPoint2 = manifold.Points[i];
                        contactPoint.Position = body.GetWorldPoint(manifoldPoint2.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint2);
                        contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                        contactPoint.Normal     = manifold.Normal;
                        contactPoint.Separation = manifoldPoint2.Separation;
                        contactPoint.ID         = manifoldPoint2.ID;
                        listener.Remove(contactPoint);
                    }
                }
            }
        }
Ejemplo n.º 17
0
 public override void Evaluate(ContactListener listener)
 {
     Body body = this._shape1.GetBody();
     Body body2 = this._shape2.GetBody();
     Manifold manifold = this._manifold.Clone();
     Collision.Collision.CollideCircles(ref this._manifold, (CircleShape)this._shape1, body.GetXForm(), (CircleShape)this._shape2, body2.GetXForm());
     ContactPoint contactPoint = new ContactPoint();
     contactPoint.Shape1 = this._shape1;
     contactPoint.Shape2 = this._shape2;
     contactPoint.Friction = Settings.MixFriction(this._shape1.Friction, this._shape2.Friction);
     contactPoint.Restitution = Settings.MixRestitution(this._shape1.Restitution, this._shape2.Restitution);
     if (this._manifold.PointCount > 0)
     {
         this._manifoldCount = 1;
         ManifoldPoint manifoldPoint = this._manifold.Points[0];
         if (manifold.PointCount == 0)
         {
             manifoldPoint.NormalImpulse = 0f;
             manifoldPoint.TangentImpulse = 0f;
             if (listener != null)
             {
                 contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                 contactPoint.Velocity = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                 contactPoint.Normal = this._manifold.Normal;
                 contactPoint.Separation = manifoldPoint.Separation;
                 contactPoint.ID = manifoldPoint.ID;
                 listener.Add(contactPoint);
             }
         }
         else
         {
             ManifoldPoint manifoldPoint2 = manifold.Points[0];
             manifoldPoint.NormalImpulse = manifoldPoint2.NormalImpulse;
             manifoldPoint.TangentImpulse = manifoldPoint2.TangentImpulse;
             if (listener != null)
             {
                 contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                 contactPoint.Velocity = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                 contactPoint.Normal = this._manifold.Normal;
                 contactPoint.Separation = manifoldPoint.Separation;
                 contactPoint.ID = manifoldPoint.ID;
                 listener.Persist(contactPoint);
             }
         }
     }
     else
     {
         this._manifoldCount = 0;
         if (manifold.PointCount > 0 && listener != null)
         {
             ManifoldPoint manifoldPoint2 = manifold.Points[0];
             contactPoint.Position = body.GetWorldPoint(manifoldPoint2.LocalPoint1);
             Vec2 linearVelocityFromLocalPoint = body.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint1);
             Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint2);
             contactPoint.Velocity = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
             contactPoint.Normal = manifold.Normal;
             contactPoint.Separation = manifoldPoint2.Separation;
             contactPoint.ID = manifoldPoint2.ID;
             listener.Remove(contactPoint);
         }
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Register a contact event listener
 /// </summary>
 /// <param name="listener"></param>
 public void SetContactListener(ContactListener listener)
 {
     _contactManager._contactListener = listener;
 }
Ejemplo n.º 19
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];
        }
Ejemplo n.º 20
0
		public override void Evaluate(ContactListener listener)
		{
			Body b1 = _shape1.GetBody();
			Body b2 = _shape2.GetBody();
#warning "needfix"
			//memcpy(&m0, &m_manifold, sizeof(b2Manifold));
			Manifold m0 = _manifold.Clone();

			Collision.Collision.CollideCircles(ref _manifold, (CircleShape)_shape1, b1.GetXForm(), 
				(CircleShape)_shape2, b2.GetXForm());

			ContactPoint cp = new ContactPoint();
			cp.Shape1 = _shape1;
			cp.Shape2 = _shape2;
			cp.Friction = Settings.MixFriction(_shape1.Friction, _shape2.Friction);
			cp.Restitution = Settings.MixRestitution(_shape1.Restitution, _shape2.Restitution);

			if (_manifold.PointCount > 0)
			{
				_manifoldCount = 1;
				ManifoldPoint mp = _manifold.Points[0];

				if (m0.PointCount == 0)
				{
					mp.NormalImpulse = 0.0f;
					mp.TangentImpulse = 0.0f;

					if (listener!=null)
					{
						cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
						Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
						Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
						cp.Velocity = v2 - v1;
						cp.Normal = _manifold.Normal;
						cp.Separation = mp.Separation;
						cp.ID = mp.ID;
						listener.Add(cp);
					}
				}
				else
				{
					ManifoldPoint mp0 = m0.Points[0];
					mp.NormalImpulse = mp0.NormalImpulse;
					mp.TangentImpulse = mp0.TangentImpulse;

					if (listener!=null)
					{
						cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
						Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
						Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
						cp.Velocity = v2 - v1;
						cp.Normal = _manifold.Normal;
						cp.Separation = mp.Separation;
						cp.ID = mp.ID;
						listener.Persist(cp);
					}
				}
			}
			else
			{
				_manifoldCount = 0;
				if (m0.PointCount > 0 && listener!=null)
				{
					ManifoldPoint mp0 = m0.Points[0];
					cp.Position = b1.GetWorldPoint(mp0.LocalPoint1);
					Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp0.LocalPoint1);
					Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp0.LocalPoint2);
					cp.Velocity = v2 - v1;
					cp.Normal = m0.Normal;
					cp.Separation = mp0.Separation;
					cp.ID = mp0.ID;
					listener.Remove(cp);
				}
			}
		}
Ejemplo n.º 21
0
        public void Update(ContactListener listener)
        {
            //Note: Manifold is a class, not a struct. It will reference the old manifest, not copy it - DONE
            Manifold oldManifold = new Manifold();
            oldManifold.LocalPlaneNormal = Manifold.LocalPlaneNormal;
            oldManifold.LocalPoint = Manifold.LocalPoint;
            oldManifold.PointCount = Manifold.PointCount;
            oldManifold.Points = Manifold.Points;
            oldManifold.Type = Manifold.Type;

            // Re-enable this contact.
            Flags &= ~ContactFlag.DisabledFlag;

            if (Collision.Collision.TestOverlap(_fixtureA.Aabb, _fixtureB.Aabb))
            {
                Evaluate();
            }
            else
            {
                Manifold.PointCount = 0;
            }

            Body bodyA = _fixtureA.GetBody();
            Body bodyB = _fixtureB.GetBody();

            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 |= ContactFlag.ContinuousFlag;
            }
            else
            {
                Flags &= ~ContactFlag.ContinuousFlag;
            }

            // 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 (newCount > 0)
            {
                Flags |= ContactFlag.TouchingFlag;
            }
            else
            {
                Flags &= ~ContactFlag.TouchingFlag;
            }

            if (oldCount == 0 && newCount > 0)
            {
                listener.BeginContact(this);
            }

            if (oldCount > 0 && newCount == 0)
            {
                listener.EndContact(this);
            }

            if ((Flags & ContactFlag.SensorFlag) == 0)
            {
                listener.PreSolve(this, oldManifold);
            }
        }
Ejemplo n.º 22
0
		public abstract void Evaluate(ContactListener listener);
Ejemplo n.º 23
0
        public override void Evaluate(ContactListener listener)
        {
            Body b1 = _shape1.GetBody();
            Body b2 = _shape2.GetBody();

#warning "needfix"
            //memcpy(&m0, &m_manifold, sizeof(b2Manifold));
            Manifold m0 = _manifold.Clone();

            Collision.Collision.CollideCircles(ref _manifold, (CircleShape)_shape1, b1.GetXForm(),
                                               (CircleShape)_shape2, b2.GetXForm());

            ContactPoint cp = new ContactPoint();
            cp.Shape1      = _shape1;
            cp.Shape2      = _shape2;
            cp.Friction    = Settings.MixFriction(_shape1.Friction, _shape2.Friction);
            cp.Restitution = Settings.MixRestitution(_shape1.Restitution, _shape2.Restitution);

            if (_manifold.PointCount > 0)
            {
                _manifoldCount = 1;
                ManifoldPoint mp = _manifold.Points[0];

                if (m0.PointCount == 0)
                {
                    mp.NormalImpulse  = 0.0f;
                    mp.TangentImpulse = 0.0f;

                    if (listener != null)
                    {
                        cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
                        Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
                        Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
                        cp.Velocity   = v2 - v1;
                        cp.Normal     = _manifold.Normal;
                        cp.Separation = mp.Separation;
                        cp.ID         = mp.ID;
                        listener.Add(cp);
                    }
                }
                else
                {
                    ManifoldPoint mp0 = m0.Points[0];
                    mp.NormalImpulse  = mp0.NormalImpulse;
                    mp.TangentImpulse = mp0.TangentImpulse;

                    if (listener != null)
                    {
                        cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
                        Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
                        Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
                        cp.Velocity   = v2 - v1;
                        cp.Normal     = _manifold.Normal;
                        cp.Separation = mp.Separation;
                        cp.ID         = mp.ID;
                        listener.Persist(cp);
                    }
                }
            }
            else
            {
                _manifoldCount = 0;
                if (m0.PointCount > 0 && listener != null)
                {
                    ManifoldPoint mp0 = m0.Points[0];
                    cp.Position = b1.GetWorldPoint(mp0.LocalPoint1);
                    Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp0.LocalPoint1);
                    Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp0.LocalPoint2);
                    cp.Velocity   = v2 - v1;
                    cp.Normal     = m0.Normal;
                    cp.Separation = mp0.Separation;
                    cp.ID         = mp0.ID;
                    listener.Remove(cp);
                }
            }
        }
Ejemplo n.º 24
0
 public abstract void Evaluate(ContactListener listener);
Ejemplo n.º 25
0
 public override void Evaluate(ContactListener listener)
 {
 }
Ejemplo n.º 26
0
		public override void Evaluate(ContactListener listener) { }
Ejemplo n.º 27
0
		public override void Evaluate(ContactListener listener)
		{
			Body b1 = _shape1.GetBody();
			Body b2 = _shape2.GetBody();
#warning "needfix"
			//memcpy(&m0, &m_manifold, sizeof(b2Manifold));
			Manifold m0 = _manifold.Clone();

			Collision.Collision.CollidePolygons(ref _manifold, (PolygonShape)_shape1, b1.GetXForm(),
				(PolygonShape)_shape2, b2.GetXForm());

			bool[] persisted = new bool[] { false, false };

			ContactPoint cp = new ContactPoint();
			cp.Shape1 = _shape1;
			cp.Shape2 = _shape2;
			cp.Friction = Settings.MixFriction(_shape1.Friction, _shape2.Friction);
			cp.Restitution = Settings.MixRestitution(_shape1.Restitution, _shape2.Restitution);

			// Match contact ids to facilitate warm starting.
			if (_manifold.PointCount > 0)
			{
				// 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 mp = _manifold.Points[i];
					mp.NormalImpulse = 0.0f;
					mp.TangentImpulse = 0.0f;
					bool found = false;
					ContactID id = mp.ID;

					for (int j = 0; j < m0.PointCount; ++j)
					{
						if (persisted[j] == true)
						{
							continue;
						}

						ManifoldPoint mp0 = m0.Points[j];

						if (mp0.ID.Key == id.Key)
						{
							persisted[j] = true;
							mp.NormalImpulse = mp0.NormalImpulse;
							mp.TangentImpulse = mp0.TangentImpulse;

							// A persistent point.
							found = true;

							// Report persistent point.
							if (listener != null)
							{
								cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
								Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
								Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
								cp.Velocity = v2 - v1;
								cp.Normal = _manifold.Normal;
								cp.Separation = mp.Separation;
								cp.ID = id;
								listener.Persist(cp);
							}
							break;
						}
					}

					// Report added point.
					if (found == false && listener != null)
					{
						cp.Position = b1.GetWorldPoint(mp.LocalPoint1);
						Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
						Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
						cp.Velocity = v2 - v1;
						cp.Normal = _manifold.Normal;
						cp.Separation = mp.Separation;
						cp.ID = id;
						listener.Add(cp);
					}
				}

				_manifoldCount = 1;
			}
			else
			{
				_manifoldCount = 0;
			}

			if (listener == null)
			{
				return;
			}

			// Report removed points.
			for (int i = 0; i < m0.PointCount; ++i)
			{
				if (persisted[i])
				{
					continue;
				}

				ManifoldPoint mp0 = m0.Points[i];
				cp.Position = b1.GetWorldPoint(mp0.LocalPoint1);
				Vec2 v1 = b1.GetLinearVelocityFromLocalPoint(mp0.LocalPoint1);
				Vec2 v2 = b2.GetLinearVelocityFromLocalPoint(mp0.LocalPoint2);
				cp.Velocity = v2 - v1;
				cp.Normal = m0.Normal;
				cp.Separation = mp0.Separation;
				cp.ID = mp0.ID;
				listener.Remove(cp);
			}
		}
Ejemplo n.º 28
0
 public override void Evaluate(ContactListener listener)
 {
     Body body = this._shape1.GetBody();
     Body body2 = this._shape2.GetBody();
     Manifold manifold = this._manifold.Clone();
     Collision.Collision.CollidePolygonAndCircle(ref this._manifold, (PolygonShape)this._shape1, body.GetXForm(), (CircleShape)this._shape2, body2.GetXForm());
     bool[] array = new bool[2];
     bool[] array2 = array;
     ContactPoint contactPoint = new ContactPoint();
     contactPoint.Shape1 = this._shape1;
     contactPoint.Shape2 = this._shape2;
     contactPoint.Friction = Settings.MixFriction(this._shape1.Friction, this._shape2.Friction);
     contactPoint.Restitution = Settings.MixRestitution(this._shape1.Restitution, this._shape2.Restitution);
     if (this._manifold.PointCount > 0)
     {
         for (int i = 0; i < this._manifold.PointCount; i++)
         {
             ManifoldPoint manifoldPoint = this._manifold.Points[i];
             manifoldPoint.NormalImpulse = 0f;
             manifoldPoint.TangentImpulse = 0f;
             bool flag = false;
             ContactID iD = manifoldPoint.ID;
             for (int j = 0; j < manifold.PointCount; j++)
             {
                 if (!array2[j])
                 {
                     ManifoldPoint manifoldPoint2 = manifold.Points[j];
                     if (manifoldPoint2.ID.Key == iD.Key)
                     {
                         array2[j] = true;
                         manifoldPoint.NormalImpulse = manifoldPoint2.NormalImpulse;
                         manifoldPoint.TangentImpulse = manifoldPoint2.TangentImpulse;
                         flag = true;
                         if (listener != null)
                         {
                             contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                             Vec2 linearVelocityFromLocalPoint = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                             Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                             contactPoint.Velocity = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                             contactPoint.Normal = this._manifold.Normal;
                             contactPoint.Separation = manifoldPoint.Separation;
                             contactPoint.ID = iD;
                             listener.Persist(contactPoint);
                         }
                         break;
                     }
                 }
             }
             if (!flag && listener != null)
             {
                 contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                 contactPoint.Velocity = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                 contactPoint.Normal = this._manifold.Normal;
                 contactPoint.Separation = manifoldPoint.Separation;
                 contactPoint.ID = iD;
                 listener.Add(contactPoint);
             }
         }
         this._manifoldCount = 1;
     }
     else
     {
         this._manifoldCount = 0;
     }
     if (listener != null)
     {
         for (int i = 0; i < manifold.PointCount; i++)
         {
             if (!array2[i])
             {
                 ManifoldPoint manifoldPoint2 = manifold.Points[i];
                 contactPoint.Position = body.GetWorldPoint(manifoldPoint2.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint = body.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint2.LocalPoint2);
                 contactPoint.Velocity = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                 contactPoint.Normal = manifold.Normal;
                 contactPoint.Separation = manifoldPoint2.Separation;
                 contactPoint.ID = manifoldPoint2.ID;
                 listener.Remove(contactPoint);
             }
         }
     }
 }
Ejemplo n.º 29
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];
		}
Ejemplo n.º 30
0
		/// <summary>
		/// Register a contact event listener
		/// </summary>
		/// <param name="listener"></param>
		public void SetContactListener(ContactListener listener)
		{
			_contactListener = listener;
		}
Ejemplo n.º 31
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;
                }
            }
        }
Ejemplo n.º 32
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;
                }
            }
        }