Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (int i = 0; i < cells.size(); i++) {
- float a[] = cells.get(i).updateAcceleration();
- cells.get(i).xVel += (a[0] * 1.0f/60.0f);
- cells.get(i).yVel += (a[1] * 1.0f/60.0f);
- cells.get(i).xPos += (cells.get(i).xVel * 1.0f/60.0f);
- cells.get(i).yPos += (cells.get(i).yVel * 1.0f/60.0f);
- cells.get(i).update();
- }
- for (int i = 0; i < cells.size(); i++) {
- //cells.get(i).update();
- for (int j = i+1; j < cells.size(); j++) {
- if (collision.BalltoBall(cells.get(i), cells.get(j))) {
- float normalx, normaly;
- normalx = cells.get(j).xPos - cells.get(i).xPos;
- normaly = cells.get(j).yPos - cells.get(i).yPos;
- float mag = (float) Math.hypot(normalx,normaly);
- normalx = normalx/mag;
- normaly = normaly/mag;
- float radiumSum = cells.get(i).radius+cells.get(j).radius;
- float penetrationdepth = radiumSum - mag;
- float percentCorrection = 0.5f;
- float slop = 0.02f;
- float inverseMassI = 1.0f/cells.get(i).mass;
- float inverseMassJ = 1.0f/cells.get(j).mass;
- float totalinverseMass = inverseMassI + inverseMassJ;
- float correctionX = normalx * ((Math.max(penetrationdepth-slop,0.0f)/totalinverseMass)*percentCorrection);
- float correctionY = normaly * ((Math.max(penetrationdepth-slop,0.0f)/totalinverseMass)*percentCorrection);
- cells.get(i).xPos -= (correctionX*inverseMassI);
- cells.get(i).yPos -= (correctionY*inverseMassI);
- cells.get(j).xPos += (correctionX*inverseMassJ);
- cells.get(j).yPos += (correctionY*inverseMassJ);
- float velx = cells.get(i).xVel - cells.get(j).xVel;
- float vely = cells.get(i).yVel - cells.get(j).yVel;
- float dot = (normalx * velx) + (normaly * vely);
- Log.d("dot", ""+dot);
- float elasticity = 0.9f;
- float scalarJ = -(1+elasticity)*dot;
- scalarJ /= totalinverseMass;
- float impulsex = normalx * scalarJ;
- float impulsey = normaly * scalarJ;
- cells.get(i).xVel += (impulsex*inverseMassI);
- cells.get(i).yVel += (impulsey*inverseMassI);
- cells.get(j).xVel -= (impulsex*inverseMassJ);
- cells.get(j).yVel -= (impulsey*inverseMassJ);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement