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

Fix movement equation.

parent c3be9e27
No related merge requests found
...@@ -13,7 +13,7 @@ public class BulletAnimated { ...@@ -13,7 +13,7 @@ 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 = 50; private double strenghtOfCannon = 100;
private double cannonLength = 100; private double cannonLength = 100;
private boolean accelerate = true; private boolean accelerate = true;
private boolean hitToGround = false; private boolean hitToGround = false;
...@@ -53,27 +53,25 @@ public class BulletAnimated { ...@@ -53,27 +53,25 @@ public class BulletAnimated {
double cannonAngle = cannon.getAngle(); double cannonAngle = cannon.getAngle();
speed = speed speed = speed
.add(new Point2D(Math.cos(cannonAngle) * strenghtOfCannon, Math.sin(cannonAngle) * strenghtOfCannon) .add(new Point2D(Math.cos(cannonAngle) * strenghtOfCannon, Math.sin(cannonAngle) * strenghtOfCannon)
.multiply(1 / mass * deltaT)); .multiply(deltaT / mass));
} else if (!hitToGround) { } else if (!hitToGround) {
accelerate = false; accelerate = false;
Point2D airResistanceforce = new Point2D( Point2D airResistanceforce = new Point2D(
-1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * dragCoefficient * Math.pow(speed.getX(), 2), -1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * dragCoefficient * Math.pow(speed.getX(), 2),
-1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * 0.47 * Math.pow(speed.getY(), 2)); -1. / 2 * crossSectionalArea * Constants.AIR_DENSITY * 0.47 * Math.pow(speed.getY(), 2));
Point2D acceleration = new Point2D(-airResistanceforce.getX() * mass, Point2D acceleration = new Point2D(-airResistanceforce.getX() * mass,
-Constants.GRAVITATIONAL_ACCELERATION + airResistanceforce.getY() * mass); (-Constants.GRAVITATIONAL_ACCELERATION + airResistanceforce.getY()) * mass);
speed = speed.add(acceleration.multiply(deltaT)); speed = speed.add(acceleration.multiply(deltaT));
} }
if (!hitToGround) { if (!hitToGround) {
position = position.add(speed); position = position.add(speed.multiply(deltaT*100));
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);
} }
} else { } else {
reload(); reload();
} }
} }
public Rectangle2D getBoundingBox() { public Rectangle2D getBoundingBox() {
......
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