예제 #1
0
 public override void CheckForCollisions(List <LPhysicsObject2D> objs, float deltaTime)
 {
     base.CheckForCollisions(objs, deltaTime);
     for (int i = objs.Count - 1; i >= 1; i--)
     {
         for (int j = i - 1; j >= 0; j--)
         {
             LPhysicsObject2D objA = objs[i];
             LPhysicsObject2D objB = objs[j];
             if (objA.collider != null &&
                 objB.collider != null &&
                 objA.collider.bounds.Intersects(objB.collider.bounds))
             {
                 simplex.Clear();
                 direction = Vector2.one;
                 epa.Clear();
                 closestFace = null;
                 safety.Clear();
                 LContactConstraint2D constraint = CollisionDetect(objA, objB);
                 if (constraint != null)
                 {
                     contactConstraints.Add(constraint);
                 }
             }
         }
     }
 }
예제 #2
0
    private LContactConstraint2D ContactConstraintGenerate(LPhysicsObject2D objA, LPhysicsObject2D objB)
    {
        LContactConstraint2D constraint = null;
        Vector2 contactPointsA          = LGeometryUtil2D.CalcBarycentric(closestFace.sp1.a, closestFace.sp2.a);
        Vector2 contactPointsB          = LGeometryUtil2D.CalcBarycentric(closestFace.sp1.b, closestFace.sp2.b);

        if (closestFace.sqrMagnitude > LPhysicsStatic2D.DistanceSqrtThreshold)
        {
            float   penetration = Mathf.Sqrt(closestFace.sqrMagnitude);
            Vector2 normal      = closestFace.direction / penetration;
            if (objA.rigidBody != null ||
                objB.rigidBody != null)
            {
                constraint             = new LContactConstraint2D(objA, objB);
                constraint.anchorA     = contactPointsA;
                constraint.anchorB     = contactPointsB;
                constraint.normal      = normal;
                constraint.penetration = penetration;
            }
        }
        return(constraint);
    }