public void render(GL10 gl) { if (numTest < numTests) { if (negativeSign != getSign(ball.getLinearVelocity().z)) { sumEK += ball.getKineticEnergy(); negativeSign = !negativeSign; numBounces++; Logger.write(ball.getKineticEnergy() + ""); ticks = 0; } float z = ball.getTranslation().z; if (numBounces > maxBounces || ticks > maxTicks || ball.getLinearVelocity().length() == 0 || z > 100 || z < -100) { if (ball.getLinearVelocity().length() == 0) { for (int i = numBounces; i < maxBounces + 1; i++) Logger.write("0.0"); numTest++; } else if (numBounces > maxBounces) { numTest++; } ticks = 0; avgEK[numTest] = (float) (sumEK / (float) maxBounces); sumEK = 0; numBounces = 0; resetSimulation(restitution + (float) numTest * deltaRest, true); Logger.close(); Logger.setLogFile(String.format(format, restitution + (float) numTest * deltaRest)); } ticks++; } for (int i = 0; i < table.length; i++) table[i].render(gl); ball.render(gl); }
public void create() { dw.simulationSubSteps = 120; dw.fixedStep = (float) (1.0 / 60.0); camera = new Camera(new Vector3(0, 20, 0), 0, 270); // camera.lookat = true; Camera.active = camera; tableBottom = new Box(3f, 1, 3f); tableBottom.setColor(.3f, 1, .3f, 1); tableVerticalPart = new Box(1, 1, 3f); tableVerticalPart.setColor(.6f, .3f, 0, 1); tableHorizontalPart = new Box(3f, 1, 1); tableHorizontalPart.setColor(.6f, .3f, 0, 1); table = new CollisionShape[] { dw.createShape(tableBottom, new Vector3(0, 1, 0), 0), dw.createShape(tableVerticalPart, new Vector3(2f, 2, 0), 0), dw.createShape(tableVerticalPart, new Vector3(-2f, 2, 0), 0), dw.createShape(tableHorizontalPart, new Vector3(0, 2, 2f), 0), dw.createShape(tableHorizontalPart, new Vector3(0, 2, -2f), 0) }; for (int i = 0; i < table.length; i++) { table[i].setRestitution(restitution); table[i].setFriction(0); } table[0].setRestitution(1f); ballShape = new Sphere(.25f); box = new Box(.25f, .25f, .25f); ball = dw.createShape(ballShape, new Vector3(0, 1.75f, 0), 1); ball.setRestitution(restitution); ball.setFriction(0); ball.setLinearVelocity(new Vector3(0, 0, -5)); resetSimulation(restitution, false); negativeSign = getSign(ball.getLinearVelocity().z); Logger.setLogFile(String.format(format, restitution)); }