|
@@ -39,8 +39,9 @@ public class HolonCanvasController {
|
|
|
|
|
|
ArrayList<Vector2d> pos = insertionDistSort(sortedDist);
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
+ int ID = sortedSize.get(subCount - 1 - i).getId();
|
|
|
for (j = 0; j < subCount; j++) {
|
|
|
- if (sortedSize.get(subCount - 1 - i).getId() == bodies.get(j).getId()) {
|
|
|
+ if (ID == bodies.get(j).getId()) {
|
|
|
bodies.get(j).position = pos.get(i);
|
|
|
break;
|
|
|
}
|
|
@@ -55,10 +56,12 @@ public class HolonCanvasController {
|
|
|
// find correct color for existing HolonBodys
|
|
|
ArrayList<HolonBody> newBodies = new ArrayList<>();
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
+ Color subNetColor = model.getSubNetColors().get(i);
|
|
|
for (int j = 0; j < bodies.size(); j++) {
|
|
|
- if (model.getSubNetColors().get(i) == bodies.get(j).getColor()) {
|
|
|
- bodies.get(j).setRadius((subnets.get(i).getObjects().size() * 5 + 10) * HolonBodyScale / 100);
|
|
|
- bodies.get(j).setMass((float) Math.pow((subnets.get(i).getObjects().size() + 1) * 5, 3));
|
|
|
+ if (subNetColor == bodies.get(j).getColor()) {
|
|
|
+ int objectsSize = subnets.get(i).getObjects().size();
|
|
|
+ bodies.get(j).setRadius((objectsSize * 5 + 10) * HolonBodyScale / 100);
|
|
|
+ bodies.get(j).setMass((float) Math.pow((objectsSize + 1) * 5, 3));
|
|
|
newBodies.add(bodies.get(j));
|
|
|
newBodies.get(i).setId(i);
|
|
|
break;
|
|
@@ -228,15 +231,17 @@ public class HolonCanvasController {
|
|
|
|
|
|
for (int i = 0; i < subCount; i++) {
|
|
|
// Ball to Ball collision
|
|
|
+ float radiusI = bodies.get(i).getRadius();
|
|
|
+ float xPlusradius = (bodies.get(i).position.getX() + radiusI);
|
|
|
+ float yPlusradius = (bodies.get(i).position.getY() + radiusI);
|
|
|
+ float yMinusRadius = (bodies.get(i).position.getY()- radiusI);
|
|
|
for (int j = i + 1; j < subCount; j++) {
|
|
|
- if ((bodies.get(i).position.getX() + bodies.get(i).getRadius()) < (bodies.get(j).position.getX()
|
|
|
- - bodies.get(j).getRadius()))
|
|
|
+ float radiusJ = bodies.get(j).getRadius();
|
|
|
+ if (xPlusradius < (bodies.get(j).position.getX()- radiusJ))
|
|
|
break;
|
|
|
|
|
|
- if ((bodies.get(i).position.getY() + bodies.get(i).getRadius()) < (bodies.get(j).position.getY()
|
|
|
- - bodies.get(j).getRadius())
|
|
|
- || (bodies.get(j).position.getY() + bodies.get(j).getRadius()) < (bodies.get(i).position.getY()
|
|
|
- - bodies.get(i).getRadius()))
|
|
|
+ if (yPlusradius < (bodies.get(j).position.getY()- radiusJ)
|
|
|
+ || (bodies.get(j).position.getY() + radiusJ) < yMinusRadius)
|
|
|
continue;
|
|
|
|
|
|
bodies.get(i).resolveCollision(bodies.get(j));
|