Example #1
0
        public void TestUpdate()
        {
            var forceRegistry = new ForceRegistry();
            var force         = new ParticleConstantForce(new Vector2D(5, 0));
            var p             = new Particle {
                Mass = 1
            };

            force.Add(p);

            this.TestAddForceGenerator(forceRegistry, force);
            forceRegistry.Update(1 / 60.0);
            p.Update(1 / 60.0);
            Assert.AreEqual(new Vector2D(5, 0), p.Acceleration, "物体被赋予正确的加速度");

            p.Acceleration = Vector2D.Zero;
            this.TestRemoveForceGenerator(forceRegistry, force);
            forceRegistry.Update(1 / 60.0);
            p.Update(1 / 60.0);
            Assert.AreEqual(new Vector2D(0, 0), p.Acceleration, "删去作用力发生器,物体不再受该作用力发生器所产生的力");

            force.Add(p);
            this.TestAddForceGenerator(forceRegistry, force);
            this.TestRemoveParticle(forceRegistry, p);
            forceRegistry.Update(1 / 60.0);
            p.Update(1 / 60.0);
            Assert.AreEqual(new Vector2D(0, 0), p.Acceleration, "删去物体,物体不再受该作用力发生器所产生的力");
        }
Example #2
0
        public void TestApplyTo()
        {
            var force    = new ParticleConstantForce(new Vector2D(5, 0));
            var particle = new Particle
            {
                Mass = 1
            };

            force.Add(particle);
            force.Apply(1);

            particle.Update(1);

            Assert.AreEqual(new Vector2D(5, 0), particle.Acceleration);
        }
Example #3
0
        public void TestUpdate()
        {
            var world = new World();

            // 两种物体
            var objA = new CombinedParticle(
                new List <Vector2D> {
                new Vector2D(0, 0),
                new Vector2D(5, 0),
                new Vector2D(0, 5)
            });
            var objB = new Particle {
                Mass = 1, Position = Vector2D.Zero
            };

            // 一个全局作用力
            var zone = new GlobalZone();

            zone.Add(new ParticleGravity(new Vector2D(0, 9.8)));
            world.Zones.Add(zone);

            TestAddCustomObject(world, objA);
            var handle = TestPin(world, objA);

            TestUnPin(world, objA, handle);
            TestRemoveCustomObject(world, objA);

            // 一个作用力
            var force = new ParticleConstantForce(new Vector2D(5, 0));

            force.Add(objB);
            world.ForceGenerators.Add(force);

            TestAddObject(world, objB);
            TestRemoveObject(world, objB);
        }