コード例 #1
0
        public void TestTryApplyTo()
        {
            var p = new Particle
            {
                Mass = 1
            };
            var zone = new GlobalZone();

            zone.Add(new ParticleConstantForce(new Vector2D(5, 0)));

            zone.TryApplyTo(p, 1 / 60.0);
            p.Update(1 / 60.0);

            Assert.AreEqual(new Vector2D(5, 0), p.Acceleration);
        }
コード例 #2
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);
        }