diff --git a/assignments/src/MV3500Cohort2023MarchJune/homework3/Islas/ExampleSimulationProgram.java b/assignments/src/MV3500Cohort2023MarchJune/homework3/Islas/ExampleSimulationProgram.java index 27391682d6c8167269da63f27c7fb804661e40d6..969c44d902d5ab9e2f32ea3471be2d3db2a81fb1 100644 --- a/assignments/src/MV3500Cohort2023MarchJune/homework3/Islas/ExampleSimulationProgram.java +++ b/assignments/src/MV3500Cohort2023MarchJune/homework3/Islas/ExampleSimulationProgram.java @@ -176,6 +176,14 @@ public class ExampleSimulationProgram // more is needed here by scenario authors... munitionDescriptor1.setQuantity(1); firePdu_1a.setDescriptor(munitionDescriptor1).setRange(1000.0f); + + entityStatePdu_2.getEntityLocation().setX(0.0); // Initial location of Entity 2 + entityStatePdu_2.getEntityLocation().setZ(0.0); // Initial location of Entity 2 + entityStatePdu_2.getEntityLocation().setY(0.0); // Initial location of Entity 2 + + entityStatePdu_1.getEntityLocation().setX(1050.0); // Initial location of Entity 2 + entityStatePdu_1.getEntityLocation().setZ(0.0); // Initial location of Entity 2 + entityStatePdu_1.getEntityLocation().setY(500.0); // Initial location of Entity 2 } /** @@ -223,13 +231,34 @@ public class ExampleSimulationProgram // compute a track, update an ESPDU, whatever it is that your model is doing... // Where is my entity? Insert changes in position; this sample only changes X position. - // Adjusted to change all X, Y, and Z positions - swislas - entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + 1.0); // 1m per timestep - entityStatePdu_1.getEntityLocation().setY(entityStatePdu_1.getEntityLocation().getY() + 1.0); // 1m per timestep - entityStatePdu_1.getEntityLocation().setZ(entityStatePdu_1.getEntityLocation().getZ() + 1.0); // 1m per timestep - + + // Velocity calculations for Entity 1 moving towards Entity 2 + Double dMinusP_X = entityStatePdu_2.getEntityLocation().getX() - entityStatePdu_1.getEntityLocation().getX(); + Double dMinusP_Z = entityStatePdu_2.getEntityLocation().getZ() - entityStatePdu_1.getEntityLocation().getZ(); + Double magnitudeDMinusP = Math.sqrt(dMinusP_X * dMinusP_X + dMinusP_Z * dMinusP_Z); + + Double speed = 77.2; // Average speed of CH53 - meters per second + + Double velocityX = dMinusP_X * speed / magnitudeDMinusP; + Double velocityZ = dMinusP_Z * speed / magnitudeDMinusP; + + entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + velocityX); + entityStatePdu_1.getEntityLocation().setZ(entityStatePdu_1.getEntityLocation().getZ() + velocityZ); // decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoot at! - + double magnitudeX = entityStatePdu_2.getEntityLocation().getX() - entityStatePdu_1.getEntityLocation().getX(); + double magnitudeY = entityStatePdu_2.getEntityLocation().getY() - entityStatePdu_1.getEntityLocation().getY(); + double magnitudeZ = entityStatePdu_2.getEntityLocation().getZ() - entityStatePdu_1.getEntityLocation().getZ(); + double magnitude = Math.sqrt(magnitudeX * magnitudeX + magnitudeY * magnitudeY + magnitudeZ * magnitudeZ); + + System.out.println(""); + System.out.println(entityStatePdu_1.getEntityLocation()); + if (magnitude < firePdu_1a.getRange()) { + firePdu_1a.setFiringEntityID(entityID_1); + firePdu_1a.setTargetEntityID(entityID_2); + firePdu_1a.setDescriptor(munitionDescriptor1); + System.out.println("Fire at target"); + } + System.out.println(""); // etc. etc. your code goes here for your simulation of interest // something happens between my simulation entities, la de da de da...