private void ComputeDensityPressure() { for (int i = 0; i < particles.Length; i++) { hash.Insert(particles[i].position, particles[i]); particles[i].density = 0.0f; //currentParticleBin = hash.GetBin(particles[i].position); // listNeighbours = hash.GetNeighbourBinsFromPosition(particles[i].position); neighbourParticles = hash.GetParticlesFromBins(hash.GetNeighbourBinsFromPosition(particles[i].position)); //Debug.Log(neighbourParticles.Count); //look at neighbours for (int j = 0; j < neighbourParticles.Count; j++) { Vector3 dist = neighbourParticles[j].position - particles[i].position; float r2 = dist.sqrMagnitude; if (r2 < parameters[0].smoothingRadiusSq) { particles[i].density += parameters[0].particleMass * (315.0f / (64.0f * Mathf.PI * Mathf.Pow(parameters[0].smoothingRadius, 9.0f))) * Mathf.Pow(parameters[0].smoothingRadiusSq - r2, 3.0f); } } particles[i].pressure = GAS_CONST * (particles[i].density - parameters[0].restDensity); } }