/** Change the velocity with the force calculations * */ private static void velChanges(Body b, ArrayList<Body> system) { double xAccel = 0; double yAccel = 0; for (Body body : system) { if (body.getSize() > 500) deletions.add(body); if (b != body) { /** * Check the entire system for collisions and make the necessary changes. This way will * prevent the ConcurrentModificationExceptions I've been fighting * */ Body test = crash(b, body); if (test != null) { if (!body.getLocked()) // Bodies get added to the list twice because a crashes // into b and b also crashes into a. // Added if statements to make sure that things aren't being // double counted. if (!deletions.contains(body)) deletions.add(body); if (!b.getLocked()) if (!deletions.contains(b)) deletions.add(b); if (!b.getLocked() || !body.getLocked()) { boolean add = true; for (int i = 0; i < additions.size(); i++) { if (test.equals(additions.get(i))) add = false; } if (add) additions.add(test); } } // If there's no collision, then just do the calculations. else { xAccel += calculateAcceleration(calculateGravity(b, body, true), b); yAccel += calculateAcceleration(calculateGravity(b, body, false), b); } } } xAccel = Multiplier * xAccel; // Static Multipliers to yAccel = Multiplier * yAccel; // make things play nicer b.setvelx(b.getvelx() + xAccel); b.setvely(b.getvely() + yAccel); }
private static double calculateAcceleration(double Force, Body m) { /** Force = Mass * Acceleration * */ if (m.getLocked()) return 0; double Acc = Force / m.getMass(); return Acc; }