// Use this for initialization void Start() { this.particles = new DEMParticles(); this.spacePartitioner = new GridSP<int>( boundBL, boundTR, 20, 20, new IntEqualityComparer()); this.gravitationalForce = new GravitationalForce(new Vector2(0, -9.8f)); this.boundaryForce = new BoundaryForce( kn, cn, boundBL.x, boundBL.y, boundTR.x, boundTR.y); this.dem = new DEM(spacePartitioner, gravitationalForce, boundaryForce); spheres = new GameObject[nParticles]; for (int i = 0; i < nParticles; i++) { GameObject s = GameObject.CreatePrimitive(PrimitiveType.Sphere); s.transform.localScale = new Vector3(diameter, diameter, diameter); s.transform.position = new Vector3( Random.Range(boundBL.x, boundTR.x), Random.Range(boundBL.y, boundTR.y), 0); Destroy(s.collider); spheres[i] = s; } int length = spheres.Length; float[] radii = new float[length]; float[] masses = new float[length]; Vector2[] positions = new Vector2[length]; Vector2[] velocities = new Vector2[length]; for (int i = 0; i < length; i++) { GameObject sphere = spheres[i]; float radius = 0.5f * sphere.transform.localScale.x; radii[i] = radius; masses[i] = mass; //(rho * Mathf.PI * radius); positions[i] = new Vector2( sphere.transform.position.x, sphere.transform.position.y); velocities[i] = Vector2.zero; } particles.addParticle(masses, radii, positions, velocities); for (int i = 0; i < length; i++) { spacePartitioner.add(particles.buildAABB(i), i); } }