create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / simulation / listeners / example / AirStart.java
1 package net.sf.openrocket.simulation.listeners.example;
2
3 import net.sf.openrocket.simulation.SimulationStatus;
4 import net.sf.openrocket.simulation.exception.SimulationException;
5 import net.sf.openrocket.simulation.listeners.AbstractSimulationListener;
6 import net.sf.openrocket.util.Coordinate;
7
8 /**
9  * Simulation listener that launches a rocket from a specific altitude.
10  * <p>
11  * The altitude is read from the system property "openrocket.airstart.altitude"
12  * if defined, otherwise a default altitude of 1000 meters is used.
13  */
14 public class AirStart extends AbstractSimulationListener {
15         
16         /** Default launch altitude */
17         private static final double DEFAULT_ALTITUDE = 1000.0;
18         
19         @Override
20         public void startSimulation(SimulationStatus status) throws SimulationException {
21                 
22                 // Get the launch altitude
23                 double altitude;
24                 String arg = System.getProperty("openrocket.airstart.altitude");
25                 try {
26                         altitude = Double.parseDouble(arg);
27                 } catch (RuntimeException e) {
28                         altitude = DEFAULT_ALTITUDE;
29                 }
30                 
31                 // Modify launch position
32                 Coordinate position = status.getRocketPosition();
33                 position = position.add(0, 0, altitude);
34                 status.setRocketPosition(position);
35                 
36         }
37         
38 }