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

Fix movement equations

parent ceb91891
Branches master
No related merge requests found
......@@ -4,9 +4,10 @@ import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
public class BulletAnimated implements DrawableSimulable, Collisionable{
private static final double STRENGTH_CANNON_COEFICIENT = 4.;
private static final double STRENGTH_CANNON_COEFICIENT = 1.;
private Point2D position;
private Point2D start;
......@@ -57,7 +58,7 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
}
if (accelerate && start.distance(position) < cannonLength) {
double cannonAngle = cannon.getAngle();
double strenghtOfCannon = cannon.getStrength() * STRENGTH_CANNON_COEFICIENT/100.;
double strenghtOfCannon = cannon.getStrength() * STRENGTH_CANNON_COEFICIENT;
speed = speed
.add(new Point2D(Math.cos(cannonAngle) * strenghtOfCannon, Math.sin(cannonAngle) * strenghtOfCannon)
.multiply(deltaT / mass));
......@@ -67,11 +68,11 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
-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));
Point2D acceleration = new Point2D(-airResistanceforce.getX() * mass,
(-Constants.GRAVITATIONAL_ACCELERATION/20 + airResistanceforce.getY()) * mass);
(-Constants.GRAVITATIONAL_ACCELERATION + airResistanceforce.getY()) * mass);
speed = speed.add(acceleration.multiply(deltaT));
}
if (!hitToGround) {
position = position.add(speed.multiply(deltaT*1000));
position = position.add(speed.multiply(deltaT*100));
if (!accelerate && position.getY() <= size / 2) {
hitToGround = true;
position = new Point2D(position.getX(), size / 2);
......@@ -83,7 +84,7 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
}
public Rectangle2D getBoundingBox() {
return new Rectangle2D(position.getX(), position.getY(), size, size);
return new Rectangle2D(position.getX() - size, position.getY(), size, size);
}
public boolean overlaps(Dragon dragon) {
......
......@@ -37,7 +37,7 @@ public class Dragon implements DrawableSimulable, Collisionable{
public Rectangle2D getBoundingBox() {
return new Rectangle2D(position.getX(), position.getY(), size, size);
return new Rectangle2D(position.getX() - size, position.getY(), size, size);
}
......
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