void the_derive(double time, double y[], double dy[]) { int i; BallVector balls = decode_balls(y); // new BallVector();//Ball[num_balls]; BallVector dballs = new BallVector(); // new Ball[num_balls]; for (i = 0; i < num_balls; i++) { Ball p = balls.get2(i); Ball d = new Ball(); d.pos = p.speed; d.speed = wall_power(p); d.speed.y -= 1; // gravity dballs.add(d); } for (i = 0; i < num_balls; i++) for (int j = i + 1; j < num_balls; j++) { Ball p1 = balls.get2(i); Ball p2 = balls.get2(j); if (far_away_fast_calc(p1.pos, p2.pos, radius * 2)) continue; double dist = p1.pos.calc_dist(p2.pos); // if (dist>radius*2) // continue; Vec collide_power = calc_collide_power(p1, p2, dist); dballs.get2(i).speed.add_to(collide_power); dballs.get2(j).speed.sub_to(collide_power); } for (i = 0; i < springs.size(); i++) { Spring s = springs.get2(i); Vec collide_power = calc_spring_power(balls.get2(s.start), balls.get2(s.end)); dballs.get2(s.start).speed.add_to(collide_power); dballs.get2(s.end).speed.sub_to(collide_power); } encode_balls(dballs, dy); };
public void controlEvent(ControlEvent theEvent) { // DropdownList is of type ControlGroup. // A controlEvent will be triggered from inside the ControlGroup class. // therefore you need to check the originator of the Event with // if (theEvent.isGroup()) // to avoid an error message thrown by controlP5. /* if (theEvent.getController().getName().equals("restart")) { paddles[0].points=0; paddles[1].points=0; }*/ if (theEvent.isGroup()) { // check if the Event was triggered from a ControlGroup // println("event from group : "+theEvent.getGroup().getValue()+" from // "+theEvent.getGroup()); if (theEvent.getGroup().toString().equals("paddle1 [DropdownList]")) { println("paddle1 " + theEvent.getGroup().getValue()); paddleSelector1 = translations[(int) theEvent.getGroup().getValue()]; println(jointNames[paddleSelector1]); } else if (theEvent.getGroup().toString().equals("paddle2 [DropdownList]")) { println("paddle2 " + theEvent.getGroup().getValue()); paddleSelector2 = translations[(int) theEvent.getGroup().getValue()]; println(jointNames[paddleSelector2]); } else if (theEvent.getGroup().toString().equals("1_or_2_player [DropdownList]")) { if ((int) theEvent.getGroup().getValue() == 0) { onePlayer = true; } else { onePlayer = false; } } else if (theEvent.getGroup().toString().equals("speed [DropdownList]")) { if ((int) theEvent.getGroup().getValue() == 0) { ball.speed = new PVector(5, 5); } else if ((int) theEvent.getGroup().getValue() == 1) { ball.speed = new PVector(10, 10); } else if ((int) theEvent.getGroup().getValue() == 2) { ball.speed = new PVector(15, 15); } } } else if (theEvent.isController()) { println( "event from controller : " + theEvent.getController().getValue() + " from " + theEvent.getController()); } }