public static void UpdateAsCells(Particle[] particles, float defLen, float stiffness) { int particlesLength = (int)Math.Sqrt(particles.Length); int k = 0; for (int i = 0; i < particlesLength; ++i) { for (int j = 0; j < particlesLength - 1; ++j) { ParticlesLink.Update(particles[k], particles[k + 1], defLen, stiffness); k = k + 1; } ++k; } for (int j = 0; j < particlesLength; ++j) { k = j; for (int i = 0; i < particlesLength - 1; ++i) { ParticlesLink.Update(particles[k], particles[k + particlesLength], defLen, stiffness); k += particlesLength; } } }
public void Update(float dt) { for (int i = 0; i < particlesCount; ++i) { this.particles[i].Move(dt); } #region Temp code. float mi = 0.5f * particlesCount_i * stepBetweenParticles; float mj = 0.5f * particlesCount_j * stepBetweenParticles; int s = 20; for (int i = 0; i < particlesCount_i; i += s) { int j, k; j = 0; k = i * particlesCount_i + j; this.particles[k] = new Particle(); this.particles[k].position.x = i * stepBetweenParticles - mi; this.particles[k].position.y = j * stepBetweenParticles - mj; this.particles[k].position.z = 0; j = particlesCount_j - 1; k = i * particlesCount_i + j; this.particles[k] = new Particle(); this.particles[k].position.x = i * stepBetweenParticles - mi; this.particles[k].position.y = j * stepBetweenParticles - mj; this.particles[k].position.z = 0; } for (int j = 0; j < particlesCount_j; j += s) { int i, k; i = 0; k = i * particlesCount_i + j; this.particles[k] = new Particle(); this.particles[k].position.x = i * stepBetweenParticles - mi; this.particles[k].position.y = j * stepBetweenParticles - mj; this.particles[k].position.z = 0; i = particlesCount_i - 1; k = i * particlesCount_i + j; this.particles[k] = new Particle(); this.particles[k].position.x = i * stepBetweenParticles - mi; this.particles[k].position.y = j * stepBetweenParticles - mj; this.particles[k].position.z = 0; } #endregion Temp code. ParticlesLink.UpdateAsCells(this.particles, stepBetweenParticles, 0.5f); //ParticlesCollision.Update(this.particles); }