Beispiel #1
0
        public static bool Collide_vectors(ref Vec a, ref Vec b)
        {
            Vec    deltap = b.Sub(a);
            double dist   = deltap.Len();
            double penet  = a.r + b.r - dist;

            if (penet <= 0)
            {
                return(false);
            }

            a.m = a.r == rules.BALL_RADIUS ? rules.BALL_MASS : rules.ROBOT_MASS;
            b.m = b.r == rules.BALL_RADIUS ? rules.BALL_MASS : rules.ROBOT_MASS;

            double ccc  = ((1 / a.m) + (1 / b.m));
            double k_a  = (1 / a.m) / ccc;
            double k_b  = (1 / b.m) / ccc;
            Vec    norm = deltap.Normalize();

            a = a.Sub(norm.Mul(penet * k_a));
            b = b.Sub(norm.Mul(penet * k_b));
            double deltav = b.VelocityVec().Sub(a.VelocityVec()).Dot(norm) +
                            b.rcs - a.rcs;

            if (deltav < 0)
            {
                Vec impulse = norm.Mul(1 + averagehit * (-deltav));
                a.AddVelocity(impulse.Mul(k_a));
                b.RemVelocity(impulse.Mul(k_b));
            }


            return(true);
        }
Beispiel #2
0
        public static bool CollideWithArena(ref Vec a, bool verb)
        {
            double rimbalzo;

            if (a.r == 1)
            {
                rimbalzo = rules.ROBOT_ARENA_E;
            }
            else
            {
                rimbalzo = rules.BALL_ARENA_E;
            }

            Dan    dta   = a.DanToArena();
            double penet = a.r - dta.distance;

            if (penet <= 0)
            {
                return(false);
            }
            if (verb)
            {
                De("penet=" + penet);
            }

            a.DoAdd(dta.normal.Mul(penet));

            double vel = a.VelocityVec().Dot(dta.normal) - a.rcs;

            if (vel < 0)
            {
                Vec zs = dta.normal.Mul(-vel * (1 + rimbalzo));
                if (verb)
                {
                    De("vel added " + zs.x + " " + zs.y + " " + zs.z);
                }
                a.AddVelocity(zs);
                return(true);
            }
            return(false);
        }