DGP - Fix to non-bulk densities

This commit is contained in:
Doug Pedrick 2010-03-17 03:22:45 +00:00
parent c2b5dd705f
commit 84533440d3
4 changed files with 49 additions and 22 deletions

View File

@ -57,7 +57,7 @@ public abstract class BaseHandler<C extends RocketComponent> extends ElementHand
mass = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
}
if ("Density".equals(element)) {
density = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_DENSITY);
density = Math.max(0d, Double.parseDouble(content) / getDensityConversion());
}
if ("KnownCG".equals(element)) {
cg = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
@ -163,6 +163,23 @@ public abstract class BaseHandler<C extends RocketComponent> extends ElementHand
return Material.newMaterial(type, "RS: " + name, density, true);
}
/**
* Get the appropriate density conversion for different types of materials.
*
* @return a conversion value that is assumed to be in Rocksim Units / OpenRocket Units
*/
private double getDensityConversion() {
switch (getMaterialType()) {
case LINE:
return RocksimHandler.ROCKSIM_TO_OPENROCKET_LINE_DENSITY;
case SURFACE:
return RocksimHandler.ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY;
case BULK:
default:
return RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY;
}
}
/**
* Set the material onto an instance of RocketComponent. This is done because only some subtypes of RocketComponent
* have the setMaterial method. Unfortunately the supertype cannot be used.

View File

@ -220,7 +220,7 @@ class FinSetHandler extends ElementHandler {
mass = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
}
if ("Density".equals(element)) {
density = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_DENSITY);
density = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
}
if ("KnownCG".equals(element)) {
cg = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);

View File

@ -82,7 +82,7 @@ class ParachuteHandler extends PositionDependentHandler<Parachute> {
warnings.add("Parachute spill holes are not supported. Ignoring.");
}
if ("ShroudLineMassPerMM".equals(element)) {
shroudLineDensity = Double.parseDouble(content) * 10d/ RocksimHandler.ROCKSIM_TO_OPENROCKET_DENSITY;
shroudLineDensity = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LINE_DENSITY;
}
if ("ShroudLineMaterial".equals(element)) {
chute.setLineMaterial(BaseHandler.createCustomMaterial(Material.Type.LINE, content, shroudLineDensity));

View File

@ -36,9 +36,19 @@ public class RocksimHandler extends ElementHandler {
public static final int ROCKSIM_TO_OPENROCKET_MASS = 1000;
/**
* Density conversion. Rocksim is in milligrams/cubic centimeter, OpenRocket in grams/cubic centimeter.
* Bulk Density conversion. Rocksim is in kilograms/cubic meter, OpenRocket in kilograms/cubic meter.
*/
public static final int ROCKSIM_TO_OPENROCKET_DENSITY = 1;
public static final int ROCKSIM_TO_OPENROCKET_BULK_DENSITY = 1;
/**
* Surface Density conversion. Rocksim is in grams/sq centimeter, OpenRocket in kilograms/sq meter. 1000/(100*100) = 1/10
*/
public static final double ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY = 1/10d;
/**
* Line Density conversion. Rocksim is in kilograms/meter, OpenRocket in kilograms/meter.
*/
public static final int ROCKSIM_TO_OPENROCKET_LINE_DENSITY = 1;
/**
* Radius conversion. Rocksim is always in diameters, OpenRocket mostly in radius.