protected void BufferContactPoint(ref ContactPoint point)
        {
            if (_iContactPointCount == _iMaxContatPoints)
                return;

            // Angel buffers contact points, I don't know why.  We don't.
            PhysicsActor pa1 = point.Shape1.Body.GetUserData() as PhysicsActor;
            PhysicsActor pa2 = point.Shape2.Body.GetUserData() as PhysicsActor;
            if (pa1 == null || pa2 == null)
                return;

            CollisionPair pair = new CollisionPair(pa1, pa2);
            if (!_currentTouches.ContainsKey(pair))
            {
                pa1.OnCollision(pa2, ref point);

                if (Switchboard.Instance["CollisionWith" + pa1.Name] != null)
                {
                    Switchboard.Instance.Broadcast(new Message("CollisionWith" + pa1.Name));
                    _currentTouches.Add(pair, true);
                }
            }

            pair = new CollisionPair(pa2, pa1);
            if (!_currentTouches.ContainsKey(pair))
            {
                pa2.OnCollision(pa1, ref point);

                if (Switchboard.Instance["CollisionWith" + pa2.Name] != null)
                {
                    Switchboard.Instance.Broadcast(new Message("CollisionWith" + pa2.Name));
                    _currentTouches.Add(pair, true);
                }
            }

            _iContactPointCount++;
        }
Ejemplo n.º 2
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.º 3
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.º 4
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);
                    }
                }
            }
        }
 /// <summary>
 /// Called when a contact point persists. This includes the geometry
 /// and the forces.
 /// </summary>
 public virtual void Persist(ContactPoint point)
 {
     return;
 }
Ejemplo n.º 6
0
 public virtual void Persist(ContactPoint point)
 {
 }
Ejemplo n.º 7
0
 public virtual void Remove(ContactPoint point)
 {
 }
        internal override void OnCollision(PhysicsActor otherActor, ref ContactPoint point)
        {
            if (otherActor is PhysicsEventActor)
            {
                AddCollision((PhysicsEventActor)otherActor);
            }

            base.OnCollision(otherActor, ref point);
        }
Ejemplo n.º 9
0
        public void Destroy(Contact c)
        {
            Shape        shape        = c.GetShape1();
            Shape        shape2       = c.GetShape2();
            Body         body         = shape.GetBody();
            Body         body2        = shape2.GetBody();
            ContactPoint contactPoint = new ContactPoint();

            contactPoint.Shape1      = shape;
            contactPoint.Shape2      = shape2;
            contactPoint.Friction    = Settings.MixFriction(shape.Friction, shape2.Friction);
            contactPoint.Restitution = Settings.MixRestitution(shape.Restitution, shape2.Restitution);
            int manifoldCount = c.GetManifoldCount();

            if (manifoldCount > 0 && this._world._contactListener != null)
            {
                Manifold[] manifolds = c.GetManifolds();
                for (int i = 0; i < manifoldCount; i++)
                {
                    Manifold manifold = manifolds[i];
                    contactPoint.Normal = manifold.Normal;
                    for (int j = 0; j < manifold.PointCount; j++)
                    {
                        ManifoldPoint manifoldPoint = manifold.Points[j];
                        contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint  = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                        Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                        contactPoint.Velocity   = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                        contactPoint.Separation = manifoldPoint.Separation;
                        contactPoint.ID         = manifoldPoint.ID;
                        this._world._contactListener.Remove(contactPoint);
                    }
                }
            }
            if (c._prev != null)
            {
                c._prev._next = c._next;
            }
            if (c._next != null)
            {
                c._next._prev = c._prev;
            }
            if (c == this._world._contactList)
            {
                this._world._contactList = c._next;
            }
            if (c._node1.Prev != null)
            {
                c._node1.Prev.Next = c._node1.Next;
            }
            if (c._node1.Next != null)
            {
                c._node1.Next.Prev = c._node1.Prev;
            }
            if (c._node1 == body._contactList)
            {
                body._contactList = c._node1.Next;
            }
            if (c._node2.Prev != null)
            {
                c._node2.Prev.Next = c._node2.Next;
            }
            if (c._node2.Next != null)
            {
                c._node2.Next.Prev = c._node2.Prev;
            }
            if (c._node2 == body2._contactList)
            {
                body2._contactList = c._node2.Next;
            }
            Contact.Destroy(c);
            this._world._contactCount--;
        }
Ejemplo n.º 10
0
 public void OnContactRemove(Box2DX.Collision.Shape _other, Box2DX.Collision.Shape _self, ContactPoint _point)
 {
     //      if (wheel == _self)
     {
         //only when the tile is left which was just hit
         if (_lastContact == _other)
         {
             isOnGround = false;
         }
     }
 }
Ejemplo n.º 11
0
 public void OnContact(Box2DX.Collision.Shape _other, Box2DX.Collision.Shape _self, ContactPoint _point)
 {
     if (wheel == _self)
     {
         _lastContact = _other;
         isOnGround = true;
         JumptimePassed = 0;
     }
     else if(head == _self && Physics.ContactManager.g_contactManager.isLethal(_other))
     {
         isDead = true;
     }
 }
Ejemplo n.º 12
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.º 13
0
 internal virtual void OnCollision(PhysicsActor otherActor, ref ContactPoint point)
 {
     if (Collision != null)
         Collision(this, otherActor, ref point);
 }
            public override void Persist(ContactPoint point)
            {
                // Test player collision with ground
                Shape shape1 = point.Shape1;
                Shape shape2 = point.Shape2;

                PhysicsObject object1 = shape1.GetBody().GetUserData() as PhysicsObject;
                PhysicsObject object2 = shape2.GetBody().GetUserData() as PhysicsObject;

                // set the normal vector from the object to the dude sensor - used for jumping
                if (!(
                    (shape1.GetBody().GetUserData() == world.dude && (ScrollingWorld.dudeSensorName).Equals(shape2.UserData))
                    ||
                    (shape2.GetBody().GetUserData() == world.dude && (ScrollingWorld.dudeSensorName).Equals(shape1.UserData))
                    ))
                {
                    if ((ScrollingWorld.dudeSensorName).Equals(shape1.UserData))
                    {
                        Vector2 b2dnormal = -Utils.Convert(point.Normal);
                        b2dnormal.Normalize();
                        world.dude.Normal = b2dnormal;
                    }
                    else if ((ScrollingWorld.dudeSensorName).Equals(shape2.UserData))
                    {
                        Vector2 b2dnormal = Utils.Convert(point.Normal);
                        b2dnormal.Normalize();
                        world.dude.Normal = b2dnormal;
                    }
                }

                if ((ScrollingWorld.dudeSensorName+"SLOPE").Equals(shape2.UserData) || ScrollingWorld.dudeSensorName.Equals(shape2.UserData))
                {
                    Shape temp = shape1;
                    shape1 = shape2;
                    shape2 = temp;
                }
                if (ScrollingWorld.dudeSensorName.Equals(shape1.UserData) &&
                    (world.dude != shape2.GetBody().GetUserData()))
                {
                    world.dude.Grounded = true;
                }
                if ((ScrollingWorld.dudeSensorName + "SLOPE").Equals(shape1.UserData) &&
                    (world.dude != shape2.GetBody().GetUserData()) && (shape1.GetBody() != shape2.GetBody()))
                {
                    //Console.WriteLine(shape2.UserData); // DEBUG
                    world.dude.OnSlope = true;
                }
                Dictionary<String, List<PhysicsObject>> objsDict = new Dictionary<String, List<PhysicsObject>>();
                objsDict.Add("BoxObject", new List<PhysicsObject>());
                objsDict.Add("PolygonObject", new List<PhysicsObject>());
                objsDict.Add("CircleObject", new List<PhysicsObject>());
                objsDict.Add("DudeObject", new List<PhysicsObject>());
                objsDict.Add("PaintedObject", new List<PhysicsObject>());
                objsDict.Add("SensorObject", new List<PhysicsObject>());
                objsDict.Add("HoleObject", new List<PhysicsObject>());
                objsDict.Add("AnimationObject", new List<PhysicsObject>());
                objsDict.Add("MovingObject", new List<PhysicsObject>());
                objsDict.Add("HorizontalMovingObject", new List<PhysicsObject>());
                objsDict.Add("SwitchObject", new List<PhysicsObject>());
                objsDict.Add("DeathObject", new List<PhysicsObject>());
                objsDict.Add("FailButtonObject", new List<PhysicsObject>());
                objsDict.Add("WinDoorObject", new List<PhysicsObject>());
                objsDict.Add("PistonObject", new List<PhysicsObject>());

                foreach (PhysicsObject po in this.world.Objects)
                {
                    if (po is BoxObject)
                    {
                        objsDict["BoxObject"].Add(po);
                    }
                    else if (po is PolygonObject)
                    {
                        objsDict["PolygonObject"].Add(po);
                    }
                    else if (po is CircleObject)
                    {
                        objsDict["CircleObject"].Add(po);
                    }

                    if (po is DudeObject)
                    {
                        objsDict["DudeObject"].Add(po);
                    }
                    else if (po is PaintedObject)
                    {
                        objsDict["PaintedObject"].Add(po);
                    }
                    else if (po is SensorObject)
                    {
                        objsDict["SensorObject"].Add(po);
                    }
                    else if (po is HoleObject)
                    {
                        objsDict["HoleObject"].Add(po);
                    }
                    else if (po is AnimationObject)
                    {
                        objsDict["AnimationObject"].Add(po);
                    }
                    else if (po is MovingObject)
                    {
                        objsDict["MovingObject"].Add(po);
                    }
                    else if (po is HorizontalMovingObject)
                    {
                        objsDict["HorizontalMovingObject"].Add(po);
                    }
                    else if (po is SwitchObject)
                    {
                        objsDict["SwitchObject"].Add(po);
                    }
                    else if (po is DeathPlatform)
                    {
                        objsDict["DeathObject"].Add(po);
                    }
                    else if (po is FailButtonObject)
                    {
                        objsDict["FailButtonObject"].Add(po);
                    }
                    else if (po is WinDoorObject)
                    {
                        objsDict["WinDoorObject"].Add(po);
                    }
                    else if (po is PistonObject)
                    {
                        objsDict["PistonObject"].Add(po);
                    }
                }
                foreach (PhysicsObject switchObj in objsDict["AnimationObject"])
                {
                    if ((object1 == switchObj && object2 == world.dude) ||
                        (object2 == switchObj && object1 == world.dude))
                    //(object1 == switchObj || object2 == switchObj)
                    {
                      AnimationObject temp = (AnimationObject)switchObj;
                      if (temp.checkDeathObject())
                        {

                           world.dude.setDead();
                          world.Fail();
                        }
                    }
                }

                foreach (PhysicsObject switchObj in objsDict["SwitchObject"])
                {
                    if ((object1 == switchObj && object2 == world.dude) ||
                        (object2 == switchObj && object1 == world.dude))
                        //(object1 == switchObj || object2 == switchObj)
                    {
                        ((SwitchObject)switchObj).switchOn = true;
                    }
                }
                foreach (PhysicsObject switchObj in objsDict["DeathObject"])
                {
                    if ((object1 == switchObj && object2 == world.dude) ||
                        (object2 == switchObj && object1 == world.dude))
                    {
                        ((DeathPlatform)switchObj).deadCosmo = true;
                        world.dude.setDead();
                        world.Fail();
                    }
                }
                foreach (PhysicsObject switchObj in objsDict["CircleObject"])
                {
                    if ((object1 == switchObj && object2 == world.dude) ||
                        (object2 == switchObj && object1 == world.dude))
                    {
                        if (((CircleObject)switchObj).TextureFilename.Equals("Art\\Objects\\CircleObjects\\gear"))
                        {
                            world.dude.setDead();
                            world.Fail();
                        }
                    }
                }
                foreach (PhysicsObject switchObj in objsDict["FailButtonObject"])
                {
                    if ((object1 == switchObj && object2 == world.dude) ||
                        (object2 == switchObj && object1 == world.dude))
                    {
                        ((FailButtonObject)switchObj).deadCosmo = true;
                        world.dude.setDead();
                        world.Fail();
                    }
                }

                foreach (PhysicsObject hMove in objsDict["HorizontalMovingObject"])
                {
                    if ((object1 == hMove && object2 == world.dude) ||
                        (object2 == hMove && object1 == world.dude))
                    {
                        if (world.dude.Grounded)
                        {

                                if (((HorizontalMovingObject)hMove).mySwitch != null)
                                {
                                    if (((HorizontalMovingObject)hMove).mySwitch.switchOn)
                                    {
                                        if (((HorizontalMovingObject)hMove).isMoving)
                                        {
                                            world.dude.Body.ApplyForce(Utils.Convert(new Vector2(10.5f, 0)), world.dude.Body.GetWorldCenter());
                                            // world.dude.Position += new Vector2(.035f, 0);

                                        }

                                        else
                                        {
                                            world.dude.Body.ApplyForce(Utils.Convert(new Vector2(-10.5f, 0)), world.dude.Body.GetWorldCenter());
                                            // world.dude.Position += new Vector2(-0.05f, 0);
                                        }

                                    }
                                }
                                else
                                {

                                    if (((HorizontalMovingObject)hMove).isMoving)
                                    {
                                        world.dude.Body.ApplyForce(Utils.Convert(new Vector2(10.5f, 0)), world.dude.Body.GetWorldCenter());
                                        // world.dude.Position += new Vector2(.035f, 0);

                                    }

                                    else
                                    {
                                        world.dude.Body.ApplyForce(Utils.Convert(new Vector2(-10.5f, 0)), world.dude.Body.GetWorldCenter());
                                        // world.dude.Position += new Vector2(-0.05f, 0);
                                    }
                                }

                        }
                    }
                }

                bool allHolesFilled = true;
                foreach (PhysicsObject hole in objsDict["HoleObject"])
                {
                    if (((HoleObject)hole).Filled < HoleObject.MAX_FILL)
                    {
                        allHolesFilled = false;
                    }
                }

                foreach (PhysicsObject door in objsDict["WinDoorObject"])
                {
                    if ((object1 == door && object2 == world.dude) ||
                        (object2 == door && object1 == world.dude))
                    {
                        if (allHolesFilled)
                        {
                            ((WinDoorObject)door).makeAnimate();
                            world.Win();
                        }
                    }
                }

                foreach (PhysicsObject piston in objsDict["PistonObject"])
                {
                    foreach (PhysicsObject circle in objsDict["CircleObject"])
                    {
                        if ((object1 == piston && object2 == circle) ||
                            (object1 == piston && object2 == circle))
                        {
                            if ((MathHelper.ToDegrees(object1.Angle) > -5) && (MathHelper.ToDegrees(object1.Angle) < 5))
                            { circle.Body.ApplyForce(Utils.Convert(new Vector2(500, 0)), circle.Body.GetWorldCenter()); }
                            else if ((MathHelper.ToDegrees(object1.Angle) > 85) && (MathHelper.ToDegrees(object1.Angle) < 95))
                            { circle.Body.ApplyForce(Utils.Convert(new Vector2(0, 500)), circle.Body.GetWorldCenter()); }
                            else if ((MathHelper.ToDegrees(object1.Angle) > -95) && (MathHelper.ToDegrees(object1.Angle) < -85))
                            { circle.Body.ApplyForce(Utils.Convert(new Vector2(0, -500)), circle.Body.GetWorldCenter()); }
                            else if ((MathHelper.ToDegrees(object1.Angle) > 175) && (MathHelper.ToDegrees(object1.Angle) < 185))
                            { circle.Body.ApplyForce(Utils.Convert(new Vector2(-500, 0)), circle.Body.GetWorldCenter()); }
                        }
                    }
                }
            }
Ejemplo n.º 15
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);
                }
            }
        }
        public void Destroy(Contact c)
        {
            Shape shape1 = c.GetShape1();
            Shape shape2 = c.GetShape2();
            Body body1 = shape1.GetBody();
            Body body2 = shape2.GetBody();

            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);

            // Inform the user that this contact is ending.
            int manifoldCount = c.GetManifoldCount();
            if (manifoldCount > 0 && _world._contactListener!=null)
            {
                Manifold[] manifolds = c.GetManifolds();

                for (int i = 0; i < manifoldCount; ++i)
                {
                    Manifold manifold = manifolds[i];
                    cp.Normal = manifold.Normal;

                    for (int j = 0; j < manifold.PointCount; ++j)
                    {
                        ManifoldPoint mp = manifold.Points[j];
                        cp.Position = body1.GetWorldPoint(mp.LocalPoint1);
                        Vec2 v1 = body1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
                        Vec2 v2 = body2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
                        cp.Velocity = v2 - v1;
                        cp.Separation = mp.Separation;
                        cp.ID = mp.ID;
                        _world._contactListener.Remove(cp);
                    }
                }
            }

            // Remove from the world.
            if (c._prev != null)
            {
                c._prev._next = c._next;
            }

            if (c._next != null)
            {
                c._next._prev = c._prev;
            }

            if (c == _world._contactList)
            {
                _world._contactList = c._next;
            }

            // Remove from body 1
            if (c._node1.Prev != null)
            {
                c._node1.Prev.Next = c._node1.Next;
            }

            if (c._node1.Next != null)
            {
                c._node1.Next.Prev = c._node1.Prev;
            }

            if (c._node1 == body1._contactList)
            {
                body1._contactList = c._node1.Next;
            }

            // Remove from body 2
            if (c._node2.Prev != null)
            {
                c._node2.Prev.Next = c._node2.Next;
            }

            if (c._node2.Next != null)
            {
                c._node2.Next.Prev = c._node2.Prev;
            }

            if (c._node2 == body2._contactList)
            {
                body2._contactList = c._node2.Next;
            }

            // Call the factory.
            Contact.Destroy(c);
            --_world._contactCount;
        }
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
		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.º 19
0
        public void Destroy(Contact c)
        {
            Shape shape1 = c.GetShape1();
            Shape shape2 = c.GetShape2();
            Body  body1  = shape1.GetBody();
            Body  body2  = shape2.GetBody();

            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);

            // Inform the user that this contact is ending.
            int manifoldCount = c.GetManifoldCount();

            if (manifoldCount > 0 && _world._contactListener != null)
            {
                Manifold[] manifolds = c.GetManifolds();

                for (int i = 0; i < manifoldCount; ++i)
                {
                    Manifold manifold = manifolds[i];
                    cp.Normal = manifold.Normal;

                    for (int j = 0; j < manifold.PointCount; ++j)
                    {
                        ManifoldPoint mp = manifold.Points[j];
                        cp.Position = body1.GetWorldPoint(mp.LocalPoint1);
                        Vec2 v1 = body1.GetLinearVelocityFromLocalPoint(mp.LocalPoint1);
                        Vec2 v2 = body2.GetLinearVelocityFromLocalPoint(mp.LocalPoint2);
                        cp.Velocity   = v2 - v1;
                        cp.Separation = mp.Separation;
                        cp.ID         = mp.ID;
                        _world._contactListener.Remove(cp);
                    }
                }
            }

            // Remove from the world.
            if (c._prev != null)
            {
                c._prev._next = c._next;
            }

            if (c._next != null)
            {
                c._next._prev = c._prev;
            }

            if (c == _world._contactList)
            {
                _world._contactList = c._next;
            }

            // Remove from body 1
            if (c._node1.Prev != null)
            {
                c._node1.Prev.Next = c._node1.Next;
            }

            if (c._node1.Next != null)
            {
                c._node1.Next.Prev = c._node1.Prev;
            }

            if (c._node1 == body1._contactList)
            {
                body1._contactList = c._node1.Next;
            }

            // Remove from body 2
            if (c._node2.Prev != null)
            {
                c._node2.Prev.Next = c._node2.Next;
            }

            if (c._node2.Next != null)
            {
                c._node2.Next.Prev = c._node2.Prev;
            }

            if (c._node2 == body2._contactList)
            {
                body2._contactList = c._node2.Next;
            }

            // Call the factory.
            Contact.Destroy(c);
            --_world._contactCount;
        }
Ejemplo n.º 20
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.º 21
0
 public virtual void Add(ContactPoint point)
 {
 }
 public override void Add(ref ContactPoint point)
 {
     BufferContactPoint(ref point);
 }
 /// <summary>
 /// Called when a contact point is added. This includes the geometry
 /// and the forces.
 /// </summary>
 public virtual void Add(ContactPoint point)
 {
     return;
 }
 public override void Persist(ref ContactPoint point)
 {
     BufferContactPoint(ref point);
 }
 /// <summary>
 /// Called when a contact point is removed. This includes the last
 /// computed geometry and forces.
 /// </summary>
 public virtual void Remove(ContactPoint point)
 {
     return;
 }
Ejemplo n.º 26
0
 public void Destroy(Contact c)
 {
     Shape shape = c.GetShape1();
     Shape shape2 = c.GetShape2();
     Body body = shape.GetBody();
     Body body2 = shape2.GetBody();
     ContactPoint contactPoint = new ContactPoint();
     contactPoint.Shape1 = shape;
     contactPoint.Shape2 = shape2;
     contactPoint.Friction = Settings.MixFriction(shape.Friction, shape2.Friction);
     contactPoint.Restitution = Settings.MixRestitution(shape.Restitution, shape2.Restitution);
     int manifoldCount = c.GetManifoldCount();
     if (manifoldCount > 0 && this._world._contactListener != null)
     {
         Manifold[] manifolds = c.GetManifolds();
         for (int i = 0; i < manifoldCount; i++)
         {
             Manifold manifold = manifolds[i];
             contactPoint.Normal = manifold.Normal;
             for (int j = 0; j < manifold.PointCount; j++)
             {
                 ManifoldPoint manifoldPoint = manifold.Points[j];
                 contactPoint.Position = body.GetWorldPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint = body.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint1);
                 Vec2 linearVelocityFromLocalPoint2 = body2.GetLinearVelocityFromLocalPoint(manifoldPoint.LocalPoint2);
                 contactPoint.Velocity = linearVelocityFromLocalPoint2 - linearVelocityFromLocalPoint;
                 contactPoint.Separation = manifoldPoint.Separation;
                 contactPoint.ID = manifoldPoint.ID;
                 this._world._contactListener.Remove(contactPoint);
             }
         }
     }
     if (c._prev != null)
     {
         c._prev._next = c._next;
     }
     if (c._next != null)
     {
         c._next._prev = c._prev;
     }
     if (c == this._world._contactList)
     {
         this._world._contactList = c._next;
     }
     if (c._node1.Prev != null)
     {
         c._node1.Prev.Next = c._node1.Next;
     }
     if (c._node1.Next != null)
     {
         c._node1.Next.Prev = c._node1.Prev;
     }
     if (c._node1 == body._contactList)
     {
         body._contactList = c._node1.Next;
     }
     if (c._node2.Prev != null)
     {
         c._node2.Prev.Next = c._node2.Next;
     }
     if (c._node2.Next != null)
     {
         c._node2.Next.Prev = c._node2.Prev;
     }
     if (c._node2 == body2._contactList)
     {
         body2._contactList = c._node2.Next;
     }
     Contact.Destroy(c);
     this._world._contactCount--;
 }