// Use this for initialization void Start() { Objects = new List <GameObject>(); dampener = new List <HookesLaw.SpringDamper>(); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { var y = -i * restPosition; var z = -j * restPosition; part = Instantiate(Object); part.transform.position = new Vector3(0, y, z); Objects.Add(part); part2 = new HookesLaw.Particle(part.transform.position); particles.Add(part2); } } Spheres.Sort(); for (int i = 0; i < rows * cols; i++) { bool greaterZero = i > 0; bool lessThanRightSideColumn = i % cols < cols - 1; bool leftSideColumn = i % cols == 0; bool lessthanbottomRow = i < (cols * rows) - cols; //Horizontal Connections if (lessThanRightSideColumn) { dampener.Add(new HookesLaw.SpringDamper(particles[i], particles[i + 1], constant, dampening, restPosition)); } ////Vertical Connections if (lessthanbottomRow) { dampener.Add(new HookesLaw.SpringDamper(particles[i], particles[i + rows], constant, dampening, restPosition)); } //Left - right Diag connections if (lessthanbottomRow && lessThanRightSideColumn) { int bottom = i + cols; int right = i + 1; dampener.Add(new HookesLaw.SpringDamper(particles[bottom], particles[right], constant, dampening, restPosition * 1.41f)); } //Right-left Diag connections if (lessthanbottomRow && lessThanRightSideColumn) { int bottom = i + cols; int bottomRight = bottom + 1; dampener.Add(new HookesLaw.SpringDamper(particles[i], particles[bottomRight], constant, dampening, restPosition * 1.41f)); } } }
public void CalculateWind(HookesLaw.Particle p1, HookesLaw.Particle p2, HookesLaw.Particle p3, Vector3 windDir, float p, float cd) { Vector3 vsurface = p1.velocity + p2.velocity + p3.velocity / 3; Vector3 v = vsurface - windDir; Vector3 n = Vector3.Cross((p2.position - p1.position), (p3.position - p1.position)).normalized; float a = Vector3.Dot(v, n) / v.magnitude; Vector3 f = -.5f * p * (v.magnitude * v.magnitude) * cd * a * n; p1.AddForce(f / 3); p2.AddForce(f / 3); p3.AddForce(f / 3); }
// Use this for initialization void Start() { part1 = new HookesLaw.Particle(firstSphere.transform.position); part2 = new HookesLaw.Particle(secondSphere.transform.position); dampener = new HookesLaw.SpringDamper(part1, part2, 1, 1, 1); }