From 7774ac2b2509536b42fedf27fa3fb58409d833b7 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sun, 12 Feb 2023 17:51:33 +0000 Subject: [PATCH] Use rail guide/launch lug instances instead of separate components --- .../rasaero/importt/LaunchLugHandler.java | 32 ++++++++++------- .../rasaero/importt/RailGuideHandler.java | 36 +++++++++++-------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/core/src/net/sf/openrocket/file/rasaero/importt/LaunchLugHandler.java b/core/src/net/sf/openrocket/file/rasaero/importt/LaunchLugHandler.java index 55e0c5cb0..85747c29a 100644 --- a/core/src/net/sf/openrocket/file/rasaero/importt/LaunchLugHandler.java +++ b/core/src/net/sf/openrocket/file/rasaero/importt/LaunchLugHandler.java @@ -17,17 +17,12 @@ public abstract class LaunchLugHandler { diameter = diameter / RASAeroCommonConstants.RASAERO_TO_OPENROCKET_LENGTH; length = length / RASAeroCommonConstants.RASAERO_TO_OPENROCKET_LENGTH; - // TODO: use instances instead of 2 separate components - LaunchLug lugFore = generateLaunchLugFromRASAeroRailGuide(diameter, length); - LaunchLug lugAft = generateLaunchLugFromRASAeroRailGuide(diameter, length); + LaunchLug lug = generateLaunchLugFromRASAeroRailGuide(diameter, length, parent.getLength()); + parent.addChild(lug); - parent.addChild(lugFore); - parent.addChild(lugAft); - - lugFore.setAxialMethod(AxialMethod.TOP); - lugAft.setAxialMethod(AxialMethod.BOTTOM); - lugFore.setAxialOffset(0.0254); // 1 inch separation - lugAft.setAxialOffset(-0.0254); // 1 inch separation + // Position the launch lug + lug.setAxialMethod(AxialMethod.TOP); + lug.setAxialOffset(0.0254); // 1 inch separation // Calculate the angle offset of the launch lugs // Don't ask me how I got this formula... I don't know what the hell RASAero is doing here. @@ -35,22 +30,33 @@ public abstract class LaunchLugHandler { double r = diameter / 2; double R = parent.getOuterRadius(); double rot = -Math.acos((0.6616*R - r) / (R+r)); - lugFore.setAngleOffset(rot); - lugAft.setAngleOffset(rot); + lug.setAngleOffset(rot); } /** * Generate an OpenRocket launch lug from the RASAero parameters. * @param diameter outer diameter of the launch lug * @param length length of the launch lug + * @param parentLength length of the parent body tube * @return an OpenRocket LaunchLug with the correct parameters */ - private static LaunchLug generateLaunchLugFromRASAeroRailGuide(double diameter, double length) { + private static LaunchLug generateLaunchLugFromRASAeroRailGuide(double diameter, double length, double parentLength) { LaunchLug lug = new LaunchLug(); lug.setOuterRadius(diameter / 2); lug.setLength(length); + // Add the second launch instance + lug.setInstanceCount(2); + /* + 1 inch separation on the front side of the first launch lug, relative to the front of the lug + 1 inch separation on the back side of the second launch lug, relative to the back of the lug + => separation = parentLength - 2 * 1 inch - length + = parentLength - 0.0508 - length // 0.0508 meters = 2 inches + */ + double separation = parentLength - 0.0508 - length; + lug.setInstanceSeparation(separation); + ColorHandler.applyRASAeroColor(lug, null); // Use default RASAero color return lug; diff --git a/core/src/net/sf/openrocket/file/rasaero/importt/RailGuideHandler.java b/core/src/net/sf/openrocket/file/rasaero/importt/RailGuideHandler.java index 707ef506a..432ea662d 100644 --- a/core/src/net/sf/openrocket/file/rasaero/importt/RailGuideHandler.java +++ b/core/src/net/sf/openrocket/file/rasaero/importt/RailGuideHandler.java @@ -25,30 +25,24 @@ public abstract class RailGuideHandler { diameter = diameter / RASAeroCommonConstants.RASAERO_TO_OPENROCKET_LENGTH; height = height / RASAeroCommonConstants.RASAERO_TO_OPENROCKET_LENGTH; - // TODO: use instances instead of 2 separate components - RailButton buttonFore = generateRailButtonFromRASAeroRailGuide(diameter, height); - RailButton buttonAft = generateRailButtonFromRASAeroRailGuide(diameter, height); + RailButton button = generateRailButtonFromRASAeroRailGuide(diameter, height, parent.getLength()); + parent.addChild(button); - parent.addChild(buttonFore); - parent.addChild(buttonAft); - - buttonFore.setAxialMethod(AxialMethod.TOP); - buttonAft.setAxialMethod(AxialMethod.BOTTOM); - buttonFore.setAxialOffset(0.0254); // 1 inch separation - buttonAft.setAxialOffset(-0.0254 + buttonAft.getOuterDiameter()/2); // 1 inch separation + // Position the first rail guide with 1 inch separation with the front of the parent body tube, relative to the front of the rail guide + button.setAxialMethod(AxialMethod.TOP); + button.setAxialOffset(0.0254 + diameter/2); // Calculate the angle offset of the rail guides // Don't ask me how I got this formula... I don't know what the hell RASAero is doing here. // Just experimentally measured the right offsets, it seems to work okay. - double H = buttonFore.getTotalHeight(); - double D = buttonFore.getOuterDiameter(); + double H = button.getTotalHeight(); + double D = button.getOuterDiameter(); double R = parent.getOuterRadius(); double rot = -Math.acos((D - 1.3232*R)/(D - 2*H - 2*R)); // This is not an exact solution for all cases, but it is for the most common case if (Double.isNaN(rot)) { // Just to be safe :) rot = 0; } - buttonFore.setAngleOffset(rot); - buttonAft.setAngleOffset(rot); + button.setAngleOffset(rot); } @@ -58,9 +52,10 @@ public abstract class RailGuideHandler { * of the rail guide, plus the screw height. * @param diameter outer diameter of the rail guide * @param height total height of the rail guide, plus the screw height + * @param parentLength length of the parent body tube * @return an OpenRocket RailButton with the correct parameters */ - private static RailButton generateRailButtonFromRASAeroRailGuide(double diameter, double height) { + private static RailButton generateRailButtonFromRASAeroRailGuide(double diameter, double height, double parentLength) { RailButton button = new RailButton(); button.setOuterDiameter(diameter); @@ -76,6 +71,17 @@ public abstract class RailGuideHandler { button.setFlangeHeight(baseHeight); button.setScrewHeight(screwHeight); + // Add the second rail guide instance + button.setInstanceCount(2); + /* + 1 inch separation on the front side of the first rail guide, relative to the front of the rail guide + 1 inch separation on the back side of the second rail guide, relative to the center of the rail guide (strange RASAero...) + => separation = parentLength - 2 * 1 inch - diameter/2 + = parentLength - 0.0508 - diameter/2 // 0.0508 meters = 2 inches + */ + double separation = parentLength - 0.0508 - diameter/2; + button.setInstanceSeparation(separation); + button.setName("Rail Guide"); ColorHandler.applyRASAeroColor(button, null); // Use default RASAero color