private float CalculateDensity(SPH_Particle currentParticle, float distance) { if (distance < smoothiningRadius) { currentParticle.density += mass * (315 / (64 * Mathf.PI * Mathf.Pow(smoothiningRadius, 9))) * Mathf.Pow(smoothiningRadius - distance, 3); } return(currentParticle.density); }
private Vector3 CalculateViscosity(SPH_Particle currentParticle, SPH_Particle otherParticle, float distance) { if (distance < smoothiningRadius) { Vector3 viscosity = this.viscosity * mass * (otherParticle.velocity - currentParticle.velocity) / otherParticle.density * (45 / (Mathf.PI * Mathf.Pow(smoothiningRadius, 6))) * (smoothiningRadius - distance); return(viscosity); } return(Vector3.zero); }
private Vector3 CalculatePressure(SPH_Particle currentParticle, SPH_Particle otherParticle, Vector3 direction, float distance) { if (distance < smoothiningRadius) { Vector3 pressure = -1 * (direction.normalized) * mass * (currentParticle.pressure + otherParticle.pressure) / (2 * otherParticle.density) * (-45 / (Mathf.PI * Mathf.Pow(smoothiningRadius, 6))) * Mathf.Pow(smoothiningRadius - distance, 2); return(pressure); } return(Vector3.zero); }
private void InitilizeSimulation() { particles = new SPH_Particle[amount]; for (int i = 0; i < particles.Length; i++) { float x = (i % perRow) + Random.Range(-0.1f, 0.1f); float y = (2 * radius) + ((i / perRow) / perRow) * 1.1f; float z = ((i / perRow) % perRow) + Random.Range(-0.1f, 0.1f); GameObject currentGameObject = Instantiate(dropPrefab); SPH_Particle currentParticle = currentGameObject.AddComponent <SPH_Particle>(); particles[i] = currentParticle; currentGameObject.transform.localScale = Vector3.one * radius; currentGameObject.transform.position = new Vector3(x, y, z); currentParticle.particleObj = currentGameObject; currentParticle.position = currentGameObject.transform.position; } }