Example #1
0
File: World.cs Project: Doge815/SNT
        public static void Step()
        {
            var quadtree = Quadtree.Build(Particles, Min, Max);

            Parallel.ForEach(Particles, particle =>
            {
                var a = Particles.ToList();
                a.Remove(particle);
                particle.Velocity += AddThem(a.Select(x => quadtree.GetForce(particle, x) / particle.Mass).ToList());

                particle.Position += particle.Velocity;
            });
        }
Example #2
0
        public static Quadtree Build(List <Particle> particles, Vector2 min, Vector2 max)
        {
            if (particles.Count == 0)
            {
                return(new Quadtree(min, max));
            }

            Quadtree quadtree = new Quadtree(particles[0], min, max);

            for (int i = 1; i < particles.Count; i++)
            {
                quadtree.Insert(particles[i]);
            }

            quadtree.Compute();

            return(quadtree);
        }