Пример #1
0
        public ContactDemo(Image image)
            : base(image)
        {
            Settings.ContactIteration = 1;

            const int num = 5;

            for (int i = 0; i < num; i++)
            {
                var fB = PhysicsWorld.CreateFixedParticle((new Vector2D(160 + 40 * i, 0)).ToSimUnits());
                var pB = PhysicsWorld.CreateParticle((new Vector2D(160 + 40 * i, 200)).ToSimUnits(), new Vector2D(0, 0), 2);

                var ball = new Ball
                {
                    FixedParticle = fB,
                    Particle      = pB,
                    R             = 20
                };

                // 为质体绑定形状
                ball.Particle.BindShape(new Circle(ball.R.ToSimUnits()));

                PhysicsWorld.CreateRope(200.ToSimUnits(), 0, fB, pB);
                DrawQueue.Add(ball);
                _ballList.Add(ball);
            }

            // 增加重力和空气阻力
            PhysicsWorld.CreateGlobalZone(new ParticleGravity(new Vector2D(0, 40)));
            PhysicsWorld.CreateParticle(Vector2D.Zero, new Vector2D(1, 0), 1);
            Slot = 1 / 120.0;

            Start = true;
        }
Пример #2
0
 public CircleDemo(Image image)
     : base(image)
 {
     // 初始化中心点
     _centerObj = PhysicsWorld.CreateFixedParticle
                  (
         new Vector2D
         (
             250.ToSimUnits(),
             200.ToSimUnits()
         )
                  );
     // 注册绘制对象
     DrawQueue.Add(this);
 }