Exemplo n.º 1
0
        Vect RandPosition(double radius)
        {
            Vect v;

            do
            {
                v = new Vect(random.NextDouble() * (640 - 2 * radius) - (320 - radius), random.NextDouble() * (480 - 2 * radius) - (240 - radius));
            } while (v.Length() < 85.0f);

            return(v);
        }
Exemplo n.º 2
0
        void AddBox(Space space)
        {
            const double size = 10.0;
            const double mass = 1.0;

            Vect[] verts =
            {
                new Vect(-size, -size),
                new Vect(-size, size),
                new Vect(size,  size),
                new Vect(size, -size)
            };

            double radius   = verts[0].Length();
            Vect   position = RandPosition(radius);

            var body = new Body(mass, Polygon.MomentForPolygon(mass, verts, Vect.Zero, 0.0));

            space.AddBody(body);

            body.VelocityUpdateFunction = planetGravityFunctionCallback;

            body.Position = position;

            // Set the box's velocity to put it into a circular orbit from its
            // starting position.

            double r = position.Length();
            double v = Math.Sqrt(gravityStrength / r) / r;

            body.Velocity = position.Perpendicurlar * v;

            // Set the box's angular velocity to match its orbital period and
            // align its initial angle with its position.
            body.AngularVelocity = v;
            body.Angle           = Math.Atan2(position.Y, position.X);


            var shape = new Polygon(body, verts, Transform.Identity, 0.0);

            space.AddShape(shape);

            shape.Elasticity = 0.0;
            shape.Friction   = 0.7;
        }