Пример #1
0
		public override void PreSolve(Contact contact, Manifold oldManifold)
		{
			base.PreSolve(contact, oldManifold);

			Fixture fixtureA = contact.FixtureA;
			Fixture fixtureB = contact.FixtureB;

			if (fixtureA != m_platform && fixtureA != m_character)
			{
				return;
			}

			if (fixtureB != m_platform && fixtureB != m_character)
			{
				return;
			}

	#if true
			Vec2 position = m_character.GetBody().GetPosition();

			if (position.Y < m_top + m_radius - 3.0f *Settings._linearSlop)
			{
				contact.SetEnabled(false);
			}
	#else
			Vec2 v = m_character.GetBody().GetLinearVelocity();
			if (v.Y > 0.0f)
			{
				contact.SetEnabled(false);
			}
	#endif
		}
Пример #2
0
		public override void PreSolve(Contact contact, Manifold oldManifold)
		{
			base.PreSolve(contact, oldManifold);

			Fixture fixtureA = contact.FixtureA;
			Fixture fixtureB = contact.FixtureB;

			if (fixtureA == m_platform)
			{
				contact.SetTangentSpeed(5.0f);
			}

			if (fixtureB == m_platform)
			{
				contact.SetTangentSpeed(-5.0f);
			}
		}
Пример #3
0
		void PostSolve(Contact contact, ContactImpulse impulse)
		{
			if (m_broke)
			{
				// The body already broke.
				return;
			}

			// Should the body break?
			int count = contact.GetManifold().points.Count();

			float maxImpulse = 0.0f;
			for (int i = 0; i < count; ++i)
			{
				maxImpulse = Math.Max(maxImpulse, impulse.normalImpulses[i]);
			}

			if (maxImpulse > 40.0f)
			{
				// Flag the body for breaking.
				m_break = true;
			}
		}
Пример #4
0
		// Implement contact listener.
		public void BeginContact(Contact contact)
		{
			Fixture fixtureA = contact.FixtureA;
			Fixture fixtureB = contact.FixtureB;

			if (fixtureA == m_sensor)
			{
				object userData = fixtureB.GetBody().UserData;
				if (userData != null)
				{
					userData = true;
				}
			}

			if (fixtureB == m_sensor)
			{
				object userData = fixtureA.GetBody().UserData;
				if (userData != null)
				{
					userData = true;
				}
			}
		}
Пример #5
0
		/// This lets you inspect a contact after the solver is finished. This is useful
		/// for inspecting impulses.
		/// Note: the contact manifold does not include time of impact impulses, which can be
		/// arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly
		/// in a separate data structure.
		/// Note: this is only called for contacts that are touching, solid, and awake.
		public virtual void PostSolve(Contact contact, ContactImpulse impulse)
		{
		}
Пример #6
0
		/// This is called after a contact is updated. This allows you to inspect a
		/// contact before it goes to the solver. If you are careful, you can modify the
		/// contact manifold (e.g. disable contact).
		/// A copy of the old manifold is provided so that you can detect changes.
		/// Note: this is called only for awake bodies.
		/// Note: this is called even when the number of contact points is zero.
		/// Note: this is not called for sensors.
		/// Note: if you set the number of contact points to zero, you will not
		/// get an EndContact callback. However, you may get a BeginContact callback
		/// the next step.
		public virtual void PreSolve(Contact contact, Manifold oldManifold)
		{
		}
Пример #7
0
		/// Called when two fixtures cease to touch.
		public virtual void EndContact(Contact contact) { 
		}
Пример #8
0
		/// Called when two fixtures begin to touch.
		public virtual void BeginContact(Contact contact) { 
		}
Пример #9
0
		public static void Destroy(Contact contact){}
Пример #10
0
		//protected static void Destroy(Contact contact, Shape::Type typeA, Shape::Type typeB, BlockAllocator* allocator);
		protected static void Destroy(Contact contact){
			throw new NotImplementedException();
			//Utilities.Assert(s_initialized == true);

			//Fixture fixtureA = contact.m_fixtureA;
			//Fixture fixtureB = contact.m_fixtureB;

			//if (contact.m_manifold.pointCount > 0 &&
			//    fixtureA.IsSensor() == false &&
			//    fixtureB.IsSensor() == false)
			//{
			//    fixtureA.GetBody().SetAwake(true);
			//    fixtureB.GetBody().SetAwake(true);
			//}

			//Shape::Type typeA = fixtureA.GetType();
			//Shape::Type typeB = fixtureB.GetType();

			//Utilities.Assert(0 <= typeA && typeB < ShapeType.typeCount);
			//Utilities.Assert(0 <= typeA && typeB < ShapeType.typeCount);

			//ContactDestroyFcn* destroyFcn = s_registers[typeA][typeB].destroyFcn;
			//destroyFcn(contact, allocator);
		}
Пример #11
0
		public virtual void PreSolve(Contact contact, Manifold oldManifold) {
			Manifold manifold = contact.GetManifold();

			if (manifold.points.Count() == 0)
			{
				return;
			}

			Fixture fixtureA = contact.FixtureA;
			Fixture fixtureB = contact.FixtureB;

			PointState[] state1 = new PointState[Settings._maxManifoldPoints];
			PointState[] state2 = new PointState[Settings._maxManifoldPoints];
			Collision.GetPointStates(state1, state2, oldManifold, manifold);

			WorldManifold worldManifold;
			contact.GetWorldManifold(out worldManifold);

			for (int i = 0; i < manifold.points.Count() && m_pointCount < Program.k_maxContactPoints; ++i)
			{
				ContactPoint cp = m_points[m_pointCount];
				cp.fixtureA = fixtureA;
				cp.fixtureB = fixtureB;
				cp.position = worldManifold.points[i];
				cp.normal = worldManifold.normal;
				cp.state = state2[i];
				cp.normalImpulse = manifold.points[i].normalImpulse;
				cp.tangentImpulse = manifold.points[i].tangentImpulse;
				++m_pointCount;
			}
		}
Пример #12
0
		// Implement contact listener.
		public void EndContact(Contact contact)
		{
			Fixture fixtureA = contact.FixtureA;
			Fixture fixtureB = contact.FixtureB;

			if (fixtureA == m_sensor)
			{
				if (fixtureB.GetBody().UserData != null)
				{
					fixtureB.GetBody().UserData = false;
				}
			}

			if (fixtureB == m_sensor)
			{
				if (fixtureA.GetBody().UserData != null)
				{
					fixtureA.GetBody().UserData = false;
				}
			}
		}
Пример #13
0
		public void Destroy(Contact c) {
			Fixture fixtureA = c.FixtureA;
			Fixture fixtureB = c.FixtureB;
			Body bodyA = fixtureA.GetBody();
			Body bodyB = fixtureB.GetBody();

			if (m_contactListener != null && c.IsTouching())
			{
			    m_contactListener.EndContact(c);
			}

			// Remove from the world.
			m_contactList.Remove(c);

			// Remove from body 1
			c.m_nodeA.other.m_contactList.Remove(c.m_nodeA);

			// Remove from body 2
			c.m_nodeB.other.m_contactList.Remove(c.m_nodeA);

			// Call the factory.
		}
Пример #14
0
		public void Add(Contact contact)
		{
			m_contacts.Add(contact);
		}