public Vector2 attract(Mover m)
        {
            Vector2 force = Vector2.Subtract(location, m.location);
            float distance = force.Length();
            if (distance > 25f)
            {
                distance = 25.0f;
            }
            else if (distance < 5.0f)
            {
                distance = 5.0f;
            }

            force.Normalize();
            float strength = (G * mass * m.mass) / (distance * distance);
            Vector2.Multiply(force, strength);

            return force;
        }
Example #2
0
        protected override void Initialize()
        {
            // Screen Init
            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferWidth = width;
            graphics.PreferredBackBufferHeight = height;
            graphics.ApplyChanges();
            Window.Title = "Example 2.6: Attraction";
            this.IsMouseVisible = true;

            // Graphics Init
            spriteBatch = new SpriteBatch(GraphicsDevice);
            device = graphics.GraphicsDevice;
            Helpers.Drawing.init(device, spriteBatch);

            // Objects Init
            a = new Attractor(width, height);
            m = new Mover(1.0f, rnd.Next(50, width - 50), rnd.Next(50, height - 50), width, height);

            base.Initialize();
        }