Skip to content

Commit

Permalink
Fixed equation in test to match max heigh with actual height
Browse files Browse the repository at this point in the history
Graugger solved this, no clue how
  • Loading branch information
DarkGuardsman committed Feb 27, 2018
1 parent e5d3e5f commit de8e8cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
24 changes: 17 additions & 7 deletions src/app/java/icbm/classic/app/test/FramePathTest.java
Expand Up @@ -160,7 +160,7 @@ public void actionPerformed(ActionEvent event)
{
try
{
calculateData(0, Integer.parseInt(distanceField.getText().trim()), 3, 160, Color.RED, false);
calculateData(0, Integer.parseInt(distanceField.getText().trim()), 1, 0, Color.RED, false);
plotPanel.repaint();
}
catch (Exception e)
Expand Down Expand Up @@ -193,9 +193,17 @@ public void calculateData(int start, int end, Color color, boolean add)
*/
public void calculateData(int start, int end, int height_scale, int height_init, Color color, boolean add) //TODO break method down into sub methods and store all data values for display
{
//Constants derived from original equations
final int ticksPerMeterFlat = 4;
final int minFlightTime = 100;


//Debug
outputDebug("\n======================================"); //TODO replace debug called with debugger object
outputDebug("==========Running Calculation=========");
outputDebug("======================================");

//Collects points to draw in display
List<PlotPoint> data = new ArrayList();

//Debug
Expand All @@ -207,24 +215,24 @@ public void calculateData(int start, int end, int height_scale, int height_init,
double flat_distance = Math.abs(start - end);

double max_height = height_init + (flat_distance * height_scale);
float flight_time = (float) Math.max(100, 2 * flat_distance);
float acceleration = (float) (max_height * 2) / (flight_time * flight_time);
float flight_time = (float) Math.max(minFlightTime, ticksPerMeterFlat * flat_distance);
float drag = (float) (max_height / (flight_time / ticksPerMeterFlat) / (0.5 * flat_distance));//(float) (height_scale * ticksPerMeterFlat * (max_height / (flight_time * flight_time)));

//Set data in display
maxHeightLabel.setText(max_height + " m");
flightTimeLabel.setText(flight_time + " ticks");
accelerationLabel.setText(acceleration + " m/tick");
accelerationLabel.setText(drag + " m/tick");

//Debug
outputDebug("----------------------------------");
outputDebug("\tDistance: " + flat_distance);
outputDebug("\tHeight: " + max_height);
outputDebug("\tTime: " + flight_time);
outputDebug("\tAcceleration: " + acceleration);
outputDebug("\tAcceleration: " + drag);
outputDebug("----------------------------------");

//Calculate vector for motion
float my = acceleration * (flight_time / 2); //I think this is asking "how much speed to get to center of ark"
float my = drag * (flight_time / 2); //I think this is asking "how much speed to get to center of ark"
float mx = (float) (deltaX / flight_time);

//Output to display
Expand All @@ -244,6 +252,8 @@ public void calculateData(int start, int end, int height_scale, int height_init,
double x = start;
double y = 0;

data.add(new PlotPoint(start, -1, color.darker().darker(), 10));
data.add(new PlotPoint(end, -1, color, 10));

//Loop until position is at ground
int tick = 0;
Expand All @@ -263,7 +273,7 @@ public void calculateData(int start, int end, int height_scale, int height_init,
y += my;

//Decrease upward motion
my -= acceleration;
my -= drag;
}

outputDebug("----------------------------------");
Expand Down
4 changes: 2 additions & 2 deletions src/app/java/icbm/classic/app/test/PlotPanel.java
Expand Up @@ -42,14 +42,14 @@ protected void paintComponent(Graphics g)
for (PlotPoint pos : data)
{
//Get pixel position
double x = w - PAD - scaleX * pos.x();
double x = PAD + scaleX * pos.x();
double y = h - PAD - scaleY * pos.y();

//Set color
g2.setPaint(pos.color != null ? pos.color : Color.red);

//Draw
g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
g2.fill(new Ellipse2D.Double(x - (pos.size / 2), y - (pos.size / 2), pos.size, pos.size));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/java/icbm/classic/app/test/PlotPoint.java
Expand Up @@ -15,6 +15,7 @@ public class PlotPoint implements IPos2D
double x;
double y;
Color color;
int size = 4;


public PlotPoint(double x, double y, Color color)
Expand All @@ -24,6 +25,13 @@ public PlotPoint(double x, double y, Color color)
this.color = color;
}

public PlotPoint(double x, double y, Color color, int size)
{
this(x, y, color);
this.size = size;
}


@Override
public double x()
{
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/icbm/classic/content/entity/EntityMissile.java
Expand Up @@ -188,6 +188,9 @@ public EntityMissile ignore(Entity entity)
*/
public void recalculatePath()
{
final int ticksPerMeterFlat = 2;
final int minFlightTime = 100;

if (this.targetVector != null)
{
// Calculate the distance difference of the missile
Expand All @@ -202,7 +205,7 @@ public void recalculatePath()
// Parabolic Height
this.maxHeight = 160 + (int) (this.flatDistance * 3);
// Flight time
this.missileFlightTime = (float) Math.max(100, 2 * this.flatDistance) - this.ticksInAir;
this.missileFlightTime = (float) Math.max(minFlightTime, ticksPerMeterFlat * this.flatDistance) - this.ticksInAir;
// Acceleration
this.acceleration = (float) (this.maxHeight * 2) / (this.missileFlightTime * this.missileFlightTime);
}
Expand Down Expand Up @@ -246,12 +249,12 @@ protected void updateMotion()
//If we hit zero start curving towards target
if (this.lockHeight <= 0)
{
//Set upwards motion
this.motionY = this.acceleration * (this.missileFlightTime / 2); //TODO what is 2? meters per tick or ticks per meter
//Set upwards motion (acceleration * half of flight time)
this.motionY = this.acceleration * (this.missileFlightTime / 2); //Velocity needed to get to top of arc

//Aim missile vector towards target
this.motionX = this.deltaPathX / missileFlightTime;
this.motionZ = this.deltaPathZ / missileFlightTime;
this.motionX = this.deltaPathX / missileFlightTime; //Velocity needed to move towards target
this.motionZ = this.deltaPathZ / missileFlightTime; //Velocity needed to move towards target
}
}
else
Expand Down

0 comments on commit de8e8cd

Please sign in to comment.