public void Fire() { Random rnd = new Random(); if (!Start) { Start = true; // 设置全局的阻力 PhysicsWorld.CreateGlobalZone(new ParticleDrag(0.5, 0.5)); // 初始化水 for (int i = 0; i < 20; i++) { var item = PhysicsWorld.CreateParticle ( new Vector2D ( rnd.Next((int)Bitmap.Width).ToSimUnits(), rnd.Next((int)Bitmap.Height).ToSimUnits() ), Vector2D.Zero, 1 ); item.BindShape(new Circle(2.ToSimUnits())); _water.ObjList.Add(item); } } // 抖动 _water.ObjList.ForEach(obj => obj.Velocity.Set(rnd.Next(5) - 2.5, rnd.Next(5) - 2.5)); }
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; }
public void Fire() { if (!Start) { // 全局增加一个小阻尼 PhysicsWorld.CreateGlobalZone(new ParticleDrag(0.01, 0.02)); Start = true; } var item = PhysicsWorld.CreateParticle ( new Vector2D(200.ToSimUnits(), 200.ToSimUnits()), new Vector2D(0, 5), 1 ); _objList.Add(item); }
public ElasticDemo(Image image) : base(image) { // 设置全局的阻力用以增加稳定性 PhysicsWorld.CreateGlobalZone(new ParticleDrag(0.8f, 0.6f)); }