Skip to content
Snippets Groups Projects
Verified Commit 9dc3f636 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Add width,height to world.

Remove air resistance force.
parent c3efdd21
Branches
No related merge requests found
...@@ -12,13 +12,10 @@ public class BulletAnimated { ...@@ -12,13 +12,10 @@ public class BulletAnimated {
private Point2D initialSpeed; private Point2D initialSpeed;
private double size; private double size;
private double mass = 2; private double mass = 2;
private double strenghtOfCannon = 2; private double strenghtOfCannon = 80;
private double cannonLength = 100; private double cannonLength = 100;
private boolean accelerate = true; private boolean accelerate = true;
private boolean hitToGround = false; private boolean hitToGround = false;
private double crossSectionalArea;
private double dragCoefficient = 0.47;
private Image image; private Image image;
private World world; private World world;
...@@ -55,15 +52,11 @@ public class BulletAnimated { ...@@ -55,15 +52,11 @@ public class BulletAnimated {
.multiply(1 / mass)); .multiply(1 / mass));
} else if (!hitToGround) { } else if (!hitToGround) {
accelerate = false; accelerate = false;
Point2D airResistanceforce = new Point2D( Point2D acceleration = new Point2D(0, -Constants.GRAVITATIONAL_ACCELERATION*50 * mass);
-1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * dragCoefficient * Math.pow(speed.getX(), 2), speed = speed.add(acceleration.multiply(timeStep));
-1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * 0.47 * Math.pow(speed.getY(), 2));
Point2D acceleration = new Point2D(-airResistanceforce.getX() * mass,
(-Constants.GRAVITATIONAL_ACCELERATION + airResistanceforce.getY()) * mass);
speed = speed.add(acceleration.multiply(timeStep / 1000));
} }
if (!hitToGround) { if (!hitToGround) {
position = position.add(speed); position = position.add(speed.multiply(timeStep));
if (!accelerate && position.getY() <= size / 2) { if (!accelerate && position.getY() <= size / 2) {
hitToGround = true; hitToGround = true;
position = new Point2D(position.getX(), size / 2); position = new Point2D(position.getX(), size / 2);
......
...@@ -28,8 +28,8 @@ public class DrawingThread extends AnimationTimer { ...@@ -28,8 +28,8 @@ public class DrawingThread extends AnimationTimer {
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
world.draw(); world.draw();
if (lasttime > 0) { if (lasttime > 0) {
//time are in nanoseconds and method simulate expects miliseconds //time are in nanoseconds and method simulate expects seconds
world.simulate((now - lasttime) / 1e6); world.simulate((now - lasttime) / 1e9);
} }
lasttime = now; lasttime = now;
} }
......
...@@ -32,6 +32,12 @@ public class World { ...@@ -32,6 +32,12 @@ public class World {
cannon.simulate(timeDelta); cannon.simulate(timeDelta);
} }
public double getWidth() {
return canvas.getWidth();
}
public double getHeight() {
return canvas.getHeight();
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment