From 486a7f94e1a0cd081ccad3273ce89a1538ab298b Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Sun, 12 Apr 2020 20:29:14 -0700 Subject: [PATCH] Fix TubeFinSet 2D rendering The TubeFinSetShapes were applying the supplied transform too many times, resulting in the the shapes being offset off the viewing area. The offset transform is already applied to the component instance that is provided to the TubeFinSetShapes methods, so applying the transform resulted in the offset being moved to the right. This change removes the transform being applied to the component locations when retrieved and only applies a linear transformation to the component locations when applying the base rotational transform. Using the linear transform avoids applying the offset in addition to the rest of the transform. The problem existed in both the side view and the back view, however the back view was not as obvious due to the nature of the view. The common code between both functions applying the transform is refactored into a common location to reduce the amount of code. Additionally, documentation was added explaining the transform process that is being applied to the component locations for the final shapes. Fixes #605 Signed-off-by: Billy Olsen --- .../gui/rocketfigure/TubeFinSetShapes.java | 130 +++++++++++------- 1 file changed, 80 insertions(+), 50 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/TubeFinSetShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/TubeFinSetShapes.java index f3eb9e8d3..1b00fd5f4 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/TubeFinSetShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/TubeFinSetShapes.java @@ -10,72 +10,102 @@ import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Transformation; +/** + * The TubeFinSetShapes is used for retrieving shapes of the TubeFins on a + * Rocket from multiple view points. The returned shapes will be translated + * and transformed to the correct locations for rendering the rocket in the + * 2D view space. + */ public class TubeFinSetShapes extends RocketComponentShape { + /** + * Returns an array of RocketcomponentShapes that describe the shape of + * the TubeFinSet when viewed from the side of the rocket. TubeFins will + * appear as a Rectangle from the side view + * + * @param component the TubeFinSet to get the shapes for + * @param transformation the transformation to apply to the shapes + * @return an array of RocketComponentShapes that are used to draw the + * TubeFinSet from the side. + */ public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) { - TubeFinSet finset = (net.sf.openrocket.rocketcomponent.TubeFinSet)component; + TubeFinSet finSet = (TubeFinSet) component; - int fins = finset.getFinCount(); - double length = finset.getLength(); - double outerRadius = finset.getOuterRadius(); - double bodyRadius = finset.getBodyRadius(); - // old version - Oct, 19 2015 - //Coordinate[] instanceOffsets = new Coordinate[]{ transformation.transform( componentAbsoluteLocation )}; - //instanceOffsets = component.shiftCoordinates(instanceOffsets); - - // new version - Coordinate[] start = transformation.transform( component.getLocations()); + final double outerRadius = finSet.getOuterRadius(); + final double length = finSet.getLength(); + Coordinate[] locations = transformLocations(finSet, transformation); + Transformation finRotation = finSet.getFinRotationTransformation(); - Transformation baseRotation = finset.getBaseRotationTransformation(); - Transformation finRotation = finset.getFinRotationTransformation(); - - // Translate & rotate the coordinates - for (int i=0; i