Esempio n. 1
0
        private void PositionalCorrection(PhysicsObject A, PhysicsObject B, float pDepth, Vector2 normal)
        {
            Vector2 correction = Vector2.Multiply(normal, (Math.Max(pDepth - posCorrSlop, 0.0f) / (A.InvMass + B.InvMass)) * posCorrPercent);

            A.Position -= A.InvMass * correction;
            B.Position += B.InvMass * correction;
        }
Esempio n. 2
0
        private void ResolveCollision(PhysicsObject a, PhysicsObject b, Vector2 normal, float pDepth)
        {
            Vector2 rv = b.Velocity - a.Velocity;

            float velocityAlongNormal = Vector2.Dot(rv, normal);
            if (velocityAlongNormal > 0)
                return;

            float e = Math.Min(a.Restitution, b.Restitution);

            float j = -(1 + e) * velocityAlongNormal;
            j /= (1 / a.Mass + 1 / b.Mass);

            Vector2 impulse = j * normal;
            a.Velocity -= a.InvMass * impulse;
            b.Velocity += b.InvMass * impulse;
        }
Esempio n. 3
0
		public Manifold(PhysicsObject a, PhysicsObject b, float penetration, Vector2 normal)
		{
			A = a;
			B = b;
			Penetration = penetration;
			Normal = normal;
		}