Exemple #1
0
        public static bool TestNarrowCircleCircle(ICircleBody targetC, ICircleBody impactC, out Contact contact)
        {
            contact.TargetBody = targetC;
            contact.ImpactBody = impactC;

            contact.Disp     = 0;
            contact.Normal   = Vector2.Zero;
            contact.ConPoint = Vector2.Zero;


            float disp = (impactC.Position - targetC.Position).Length() - targetC.Radius - impactC.Radius;

            if (disp <= 0)
            {
                var norm  = Vector2.Normalize(impactC.Position - targetC.Position);
                var conpt = targetC.Position + norm * (targetC.Radius + disp / 2); //go out to edge, then in halfway (disp is negative)

                contact.Disp     = disp;
                contact.Normal   = norm;
                contact.ConPoint = conpt;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public static bool TestNarrowCirclePoly(ICircleBody targetC, IPolyBody impactP, out Contact contact)
        {
            contact.TargetBody = targetC;
            contact.ImpactBody = impactP;

            contact.Disp     = 0;
            contact.Normal   = Vector2.Zero;
            contact.ConPoint = Vector2.Zero;

            throw new NotImplementedException();
        }
        public static bool TestNarrowCirclePoly(ICircleBody targetC, IPolyBody impactP, out Contact contact)
        {
            contact.TargetBody = targetC;
            contact.ImpactBody = impactP;

            contact.Disp = 0;
            contact.Normal = Vector2.Zero;
            contact.ConPoint = Vector2.Zero;

            throw new NotImplementedException();
        }
        public static bool TestNarrowCircleCircle(ICircleBody targetC, ICircleBody impactC, out Contact contact)
        {
            contact.TargetBody = targetC;
            contact.ImpactBody = impactC;

            contact.Disp = 0;
            contact.Normal = Vector2.Zero;
            contact.ConPoint = Vector2.Zero;

            float disp = (impactC.Position - targetC.Position).Length() - targetC.Radius - impactC.Radius;

            if (disp <= 0)
            {
                var norm = Vector2.Normalize(impactC.Position - targetC.Position);
                var conpt = targetC.Position + norm * (targetC.Radius + disp / 2); //go out to edge, then in halfway (disp is negative)

                contact.Disp = disp;
                contact.Normal = norm;
                contact.ConPoint = conpt;

                return true;
            }
            else
                return false;
        }