diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 4dd306657..5951d39c5 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1456,7 +1456,7 @@ FreeformFinSet.FreeformFinSet = Freeform fin set ! TubeFinSEt TubeFinSet.TubeFinSet = Tube fin set !MassComponent -MassComponent.MassComponent = Unspecified +MassComponent.MassComponent = Mass Component MassComponent.Altimeter = Altimeter MassComponent.FlightComputer = Flight computer MassComponent.DeploymentCharge = Deployment charge diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java index 3f8edb5a0..c770509f2 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/MassComponentShapes.java @@ -19,19 +19,23 @@ import net.sf.openrocket.util.Transformation; public class MassComponentShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) { - - MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; + final MassComponent massObj = (MassComponent)component; - MassComponent.MassComponentType type = ((MassComponent)component).getMassComponentType(); - - double length = tube.getLength(); - double radius = tube.getRadius(); - double arc = Math.min(length, 2*radius) * 0.7; + final double length = massObj.getLength(); + final double radius = massObj.getRadius(); // radius of the object, itself + // magic number, but it's only cosmetic -- it just has to look pretty + final double arc = Math.min(length, 2*radius) * 0.7; + 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 RoundRectangle2D.Double(start.x, (start.y-radius), length, 2*radius, arc, arc)}; - + Shape[] s = {new RoundRectangle2D.Double(renderPosition.x - radius, renderPosition.y - radius, length, 2*radius, arc, arc)}; + + final MassComponent.MassComponentType type = ((MassComponent)component).getMassComponentType(); switch (type) { case ALTIMETER: s = addAltimeterSymbol(s); @@ -62,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/MassObjectShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/MassObjectShapes.java deleted file mode 100644 index 4687220ec..000000000 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/MassObjectShapes.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.sf.openrocket.gui.rocketfigure; - -import java.awt.Shape; -import java.awt.geom.Ellipse2D; -import java.awt.geom.RoundRectangle2D; - -import net.sf.openrocket.rocketcomponent.MassObject; -import net.sf.openrocket.rocketcomponent.RocketComponent; -import net.sf.openrocket.util.Coordinate; -import net.sf.openrocket.util.Transformation; - - -public class MassObjectShapes extends RocketComponentShape { - - public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) { - - MassObject tube = (MassObject)component; - - double length = tube.getLength(); - double radius = tube.getRadius(); - double arc = Math.min(length, 2*radius) * 0.7; - - Coordinate start = transformation.transform(Coordinate.ZERO); - - Shape[] s = {new RoundRectangle2D.Double(start.x, (start.y-radius), length, 2*radius, arc, arc)}; - - return RocketComponentShape.toArray(s, component); - } - - - public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) { - - MassObject tube = (MassObject)component; - - double or = tube.getRadius(); - - final Coordinate start = transformation.transform(Coordinate.ZERO); - - Shape[] s = {new Ellipse2D.Double((start.z-or), (start.y-or), 2*or, 2*or)}; - - 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 e8c33d240..6edf1aa7c 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/ParachuteShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/ParachuteShapes.java @@ -1,5 +1,6 @@ package net.sf.openrocket.gui.rocketfigure; +import net.sf.openrocket.rocketcomponent.MassObject; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Transformation; @@ -14,35 +15,41 @@ import java.awt.geom.RoundRectangle2D; public class ParachuteShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) { - - net.sf.openrocket.rocketcomponent.MassObject tube = (net.sf.openrocket.rocketcomponent.MassObject)component; + final MassObject massObj = (MassObject)component; - double length = tube.getLength(); - double radius = tube.getRadius(); - double arc = Math.min(length, 2*radius) * 0.7; + final double length = massObj.getLength(); + final double radius = massObj.getRadius(); // radius of the object, itself + // magic number, but it's only cosmetic -- it just has to look pretty + final double arc = Math.min(length, 2*radius) * 0.7; + final double radialDistance = massObj.getRadialPosition(); + final double radialAngleRadians = massObj.getRadialDirection(); - Coordinate start = transformation.transform( Coordinate.ZERO); - - Shape[] s = new Shape[1]; + final Coordinate localPosition = new Coordinate(0, + radialDistance * Math.cos(radialAngleRadians), + radialDistance * Math.sin(radialAngleRadians)); + final Coordinate renderPosition = transformation.transform(localPosition); - s[0] = new RoundRectangle2D.Double(start.x, (start.y-radius), length, 2*radius, arc, arc); + Shape[] s = {new RoundRectangle2D.Double(renderPosition.x - radius, renderPosition.y - radius, length, 2*radius, arc, arc)}; return RocketComponentShape.toArray( addSymbol(s), component); } 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 bcd26b7ad..4f50494e4 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/StreamerShapes.java @@ -1,5 +1,6 @@ package net.sf.openrocket.gui.rocketfigure; +import net.sf.openrocket.rocketcomponent.MassObject; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Transformation; @@ -13,44 +14,41 @@ import java.awt.geom.RoundRectangle2D; public class StreamerShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) { - - net.sf.openrocket.rocketcomponent.MassObject massObj = (net.sf.openrocket.rocketcomponent.MassObject)component; + final MassObject massObj = (MassObject)component; - double length = massObj.getLength(); - double radius = massObj.getRadius(); - double arc = Math.min(length, 2*radius) * 0.7; + final double length = massObj.getLength(); + final double radius = massObj.getRadius(); // radius of the object, itself + // magic number, but it's only cosmetic -- it just has to look pretty + final double arc = Math.min(length, 2*radius) * 0.7; + 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); + + Shape[] s = {new RoundRectangle2D.Double(renderPosition.x - radius, renderPosition.y - radius, length, 2*radius, arc, arc)}; - Shape[] s = new Shape[1]; - Coordinate frontCenter = transformation.transform(Coordinate.ZERO); - s[0] = new RoundRectangle2D.Double((frontCenter.x),(frontCenter.y-radius), - length,2*radius,arc,arc); - -// Coordinate[] start = transformation.transform(tube.toAbsolute(instanceOffset)); -// Shape[] s = new Shape[start.length]; -// for (int i=0; i < start.length; i++) { -// s[i] = new RoundRectangle2D.Double(start[i].x,(start[i].y-radius), -// length,2*radius,arc,arc); -// } return RocketComponentShape.toArray(addSymbol(s), component); } 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); }