From 2150223cb1a3034416d651805a6e1261b9aca8b7 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Tue, 1 Sep 2020 22:45:58 -0400 Subject: [PATCH] [fix][ui][graphics] Mass components now display their Radial / Angle position in Back Views --- .../gui/rocketfigure/MassComponentShapes.java | 15 +++++++---- .../gui/rocketfigure/ParachuteShapes.java | 21 +++++++++------- .../gui/rocketfigure/StreamerShapes.java | 25 +++++++++---------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java index 949da3de2..c770509f2 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java @@ -66,14 +66,19 @@ public class MassComponentShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) { - - net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; + final MassObject massObj = (MassObject)component; - double or = tube.getRadius(); + final double radius = massObj.getRadius(); // radius of the object, itself + final double diameter = 2*radius; + final double radialDistance = massObj.getRadialPosition(); + final double radialAngleRadians = massObj.getRadialDirection(); - final Coordinate start = transformation.transform(Coordinate.ZERO); + final Coordinate localPosition = new Coordinate(0, + radialDistance * Math.cos(radialAngleRadians), + radialDistance * Math.sin(radialAngleRadians)); + final Coordinate renderPosition = transformation.transform(localPosition); - Shape[] s = {new Ellipse2D.Double((start.z-or),(start.y-or),2*or,2*or)}; + final Shape[] s = {new Ellipse2D.Double(renderPosition.z - radius, renderPosition.y - radius, diameter, diameter)}; return RocketComponentShape.toArray(s, component); } diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/ParachuteShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/ParachuteShapes.java index 38003c016..6edf1aa7c 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/ParachuteShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ParachuteShapes.java @@ -36,17 +36,20 @@ public class ParachuteShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) { - - net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; + final MassObject massObj = (MassObject)component; - double or = tube.getRadius(); + final double radius = massObj.getRadius(); // radius of the object, itself + final double diameter = 2*radius; + final double radialDistance = massObj.getRadialPosition(); + final double radialAngleRadians = massObj.getRadialDirection(); + + final Coordinate localPosition = new Coordinate(0, + radialDistance * Math.cos(radialAngleRadians), + radialDistance * Math.sin(radialAngleRadians)); + final Coordinate renderPosition = transformation.transform(localPosition); + + final Shape[] s = {new Ellipse2D.Double(renderPosition.z - radius, renderPosition.y - radius, diameter, diameter)}; - Coordinate[] start = transformation.transform(tube.toAbsolute(Coordinate.ZERO)); - - Shape[] s = new Shape[start.length]; - for (int i=0; i < start.length; i++) { - s[i] = new Ellipse2D.Double((start[i].z-or),(start[i].y-or),2*or,2*or); - } return RocketComponentShape.toArray( s, component); } diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java index 78d683759..4f50494e4 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java @@ -35,21 +35,20 @@ public class StreamerShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) { - - net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; + final MassObject massObj = (MassObject)component; - double or = tube.getRadius(); - Shape[] s = new Shape[1]; - Coordinate center = transformation.transform(Coordinate.ZERO); + final double radius = massObj.getRadius(); // radius of the object, itself + final double diameter = 2*radius; + final double radialDistance = massObj.getRadialPosition(); + final double radialAngleRadians = massObj.getRadialDirection(); + + final Coordinate localPosition = new Coordinate(0, + radialDistance * Math.cos(radialAngleRadians), + radialDistance * Math.sin(radialAngleRadians)); + final Coordinate renderPosition = transformation.transform(localPosition); + + final Shape[] s = {new Ellipse2D.Double(renderPosition.z - radius, renderPosition.y - radius, diameter, diameter)}; - s[0] = new Ellipse2D.Double((center.z-or),(center.y-or),2*or,2*or); - -// Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset)); -// -// Shape[] s = new Shape[start.length]; -// for (int i=0; i < start.length; i++) { -// s[i] = new Ellipse2D.Double((start[i].z-or),(start[i].y-or),2*or,2*or); -// } return RocketComponentShape.toArray(s, component); }