public void AddParticle(FluidParticle p) { // Calculate which cell this particle goes in int x = (int)((p.Position.X - fluid.Container.Bounds.Max.X) / this.h); int y = (int)((p.Position.Y - fluid.Container.Bounds.Max.Y) / this.h); int z = (int)((p.Position.Z - fluid.Container.Bounds.Max.Z) / this.h); x = Math.Abs(x) % this.width; y = Math.Abs(y) % this.height; z = Math.Abs(z) % this.depth; int index = this.width * this.height * z + this.width * y + x; this.Entry[index].Add(p); }
private void SelfGatherCellNeighbors(FluidParticle part, int index, int index0, List<NeighbourPair> neighbors) { for (int i = index + 1; i < this.Entry[index0].Count; i++) { FluidParticle b = this.Entry[index0][i]; Vector3 rv = part.Position - b.Position; if (rv.LengthSquared() < this.h2) { neighbors.Add(new NeighbourPair(part, b)); } } }
public NeighbourPair(FluidParticle a, FluidParticle b) { A = a; B = b; }
private void GatherCellNeighbors2(FluidParticle part, int x1, int y1, int z1, List<NeighbourPair> neighbors) { x1 = Math.Abs(x1) % this.width; y1 = Math.Abs(y1) % this.height; z1 = Math.Abs(z1) % this.depth; int index = (((z1 * this.height) + y1) * this.width) + x1; foreach (FluidParticle particle in this.Entry[index]) { Vector3 rv = part.Position - particle.Position; if (rv.LengthSquared() < this.h2) { neighbors.Add(new NeighbourPair(part, particle)); } } }
public void InitializeParticles() { Particles.Clear(); for (int i = 0; i < MaxParticles; i++) { FluidParticle particle = new FluidParticle(); particle.Position = Random(this.Container.Bounds.Min, this.Container.Bounds.Max); particle.Velocity = Vector3.Zero; particle.Force = Vector3.Zero; //particle.Color = new Vector3((float)FluidSimulation1.Random.NextDouble(), (float)FluidSimulation1.Random.NextDouble(), (float)FluidSimulation1.Random.NextDouble()); particle.Color = new Vector3(0.18f, 0.81f, 1); particle.Density = 0f; particle.Pressure = 0f; Particles.Add(particle); } }