|
|
|
@ -2,10 +2,13 @@ package com.throwgame.main;
|
|
|
|
|
|
|
|
|
|
|
|
import com.badlogic.gdx.math.Vector2;
|
|
|
|
import com.badlogic.gdx.math.Vector2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import model.Projectile;
|
|
|
|
|
|
|
|
|
|
|
|
public class ThrowMath {
|
|
|
|
public class ThrowMath {
|
|
|
|
private double tanA;
|
|
|
|
private double tanA;
|
|
|
|
private double coefficient;
|
|
|
|
private double coefficient;
|
|
|
|
private double y0;
|
|
|
|
private double y0;
|
|
|
|
|
|
|
|
private int xPos0;
|
|
|
|
private boolean initialised;
|
|
|
|
private boolean initialised;
|
|
|
|
|
|
|
|
|
|
|
|
public ThrowMath(){
|
|
|
|
public ThrowMath(){
|
|
|
|
@ -15,16 +18,17 @@ public class ThrowMath {
|
|
|
|
this.initialised = false;
|
|
|
|
this.initialised = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void initThrow(double alpha, double g, double v0, double y0){
|
|
|
|
public void initThrow(double alpha, double g, double v0, double y0, int xPos0){
|
|
|
|
this.tanA = Math.tan(alpha);
|
|
|
|
this.tanA = Math.tan(alpha);
|
|
|
|
this.coefficient = g / (2 * Math.pow(v0, 2) * Math.pow(Math.cos(alpha), 2));
|
|
|
|
this.coefficient = g / (2 * Math.pow(v0, 2) * Math.pow(Math.cos(alpha), 2));
|
|
|
|
this.y0 = y0;
|
|
|
|
this.y0 = y0;
|
|
|
|
this.initialised = true;
|
|
|
|
this.initialised = true;
|
|
|
|
|
|
|
|
this.xPos0 = xPos0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int calculateY(int xPos){
|
|
|
|
public int calculateY(int xPos){
|
|
|
|
if(this.initialised){
|
|
|
|
if(this.initialised){
|
|
|
|
double res = this.y0 + this.tanA * xPos - this.coefficient * Math.pow(xPos, 2);
|
|
|
|
double res = 1* (this.y0 + this.tanA * (xPos - this.xPos0) - this.coefficient * Math.pow((xPos - this.xPos0), 2));
|
|
|
|
return (int) res;
|
|
|
|
return (int) res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
@ -33,6 +37,16 @@ public class ThrowMath {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Vector2 test(Projectile projectile, double g){
|
|
|
|
|
|
|
|
Vector2 lol = new Vector2();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lol.x = (int) (projectile.getxPos() + projectile.getvX());
|
|
|
|
|
|
|
|
projectile.setvY(projectile.getvY() - g);
|
|
|
|
|
|
|
|
lol.y = (int) (projectile.getyPos() + projectile.getvY());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return lol;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector2 pivotGetNewPos(double alpha, int xPosPivot, int yPosPivot, int radius){
|
|
|
|
public Vector2 pivotGetNewPos(double alpha, int xPosPivot, int yPosPivot, int radius){
|
|
|
|
Vector2 vector = new Vector2();
|
|
|
|
Vector2 vector = new Vector2();
|
|
|
|
vector.x = (float) (radius * Math.sin(alpha));
|
|
|
|
vector.x = (float) (radius * Math.sin(alpha));
|
|
|
|
|