Whoops, front is to the right

This commit is contained in:
SiboVG 2023-07-21 17:57:40 +02:00
parent 7830d397f4
commit 970e709465

View File

@ -301,19 +301,20 @@ public class FinMarkingGuide extends JPanel {
This is because this gives the user an easy way to know where the fin should be positioned. This is because this gives the user an easy way to know where the fin should be positioned.
Just position the fore end mark to where you want the fore end of the fin to be, then mark Just position the fore end mark to where you want the fore end of the fin to be, then mark
the two ends of the arrow, connect them and you have your fin position. the two ends of the arrow, connect them and you have your fin position.
NOTE: the front/fore end of the rocket is drawn at the right.
*/ */
final double cantAngle = fins.getCantAngle(); final double cantAngle = - fins.getCantAngle(); // Invert cant angle because the front end of the rocket is to the right
final boolean isCanted = !MathUtil.equals(cantAngle, 0); final boolean isCanted = !MathUtil.equals(cantAngle, 0);
if (isCanted) { if (isCanted) {
// We want to start the arrow at the fore end of the fin, so we need add an offset to // We want to end the arrow at the fore end of the fin, so we need add an offset to
// the start to account for the y-shift of the fore end of the fin due to the cant. // the start to account for the y-shift of the fore end of the fin due to the cant.
final double finBaseHalfWidth = PrintUnit.METERS.toPoints(fins.getLength()) / 2; final double finBaseHalfWidth = PrintUnit.METERS.toPoints(fins.getLength()) / 2;
final int yFinForeEndOffset = - (int) Math.round(finBaseHalfWidth * Math.sin(cantAngle)); final int yFinForeEndOffset = (int) Math.round(finBaseHalfWidth * Math.sin(cantAngle));
yStart = yFinCenter + yFinForeEndOffset; yEnd = yFinCenter + yFinForeEndOffset;
// Calculate y offset of end point // Calculate y offset of start point
int yOffset = (int) Math.round(width * Math.tan(cantAngle)); int yOffset = - (int) Math.round(width * Math.tan(cantAngle));
yEnd = yStart + yOffset; yStart = yEnd + yOffset;
} else { } else {
yStart = yFinCenter; yStart = yFinCenter;
yEnd = yFinCenter; yEnd = yFinCenter;
@ -338,14 +339,14 @@ public class FinMarkingGuide extends JPanel {
); );
// Set color and stroke // Set color and stroke
g2.setColor(Color.GRAY); g2.setColor(new Color(200, 200, 200));
g2.setStroke(dashedStroke); g2.setStroke(dashedStroke);
// Draw dashed line // Draw dashed line
// We draw from the aft end to the fore end to ensure that the side with no arrow // We draw from left to right to ensure that the side with no arrow
// point has the dashed line touching the marking guide edge // point has the dashed line touching the marking guide edge
// (is useful for marking the fin position) // (is useful for marking the fin position)
g2.drawLine(x + width, yStart, x, yStart); g2.drawLine(x, yEnd, x + width, yEnd);
// Reset stroke // Reset stroke
g2.setStroke(thinStroke); g2.setStroke(thinStroke);
@ -354,10 +355,10 @@ public class FinMarkingGuide extends JPanel {
final double finBaseHalfWidth = PrintUnit.METERS.toPoints(fins.getLength()) / 2; final double finBaseHalfWidth = PrintUnit.METERS.toPoints(fins.getLength()) / 2;
// The cant also has an x-shift. We want the fore end to be perfectly flush with the // The cant also has an x-shift. We want the fore end to be perfectly flush with the
// fore end of the marking guide, so apply an x-shift to fin center position // right of the marking guide, so apply an x-shift to fin center position
int xFinCenter = x + (int) Math.round(finBaseHalfWidth); int xFinCenter = x + width - (int) Math.round(finBaseHalfWidth);
int xFinCenterOffset = (int) Math.round(finBaseHalfWidth * (1 - Math.cos(cantAngle))); int xFinCenterOffset = (int) Math.round(finBaseHalfWidth * (1 - Math.cos(cantAngle)));
xFinCenter -= xFinCenterOffset; xFinCenter += xFinCenterOffset;
// Draw a cross where the center of the fin should be // Draw a cross where the center of the fin should be
int crossSize = 3; int crossSize = 3;
@ -370,9 +371,9 @@ public class FinMarkingGuide extends JPanel {
// Draw fin name // Draw fin name
final int xText = x + (width / 3); final int xText = x + (width / 3);
int yText = yStart - 2; int yText = yEnd - 2;
if (isCanted) { if (isCanted) {
int yTextOffset = (int) Math.round((xText - x) * Math.tan(cantAngle)); int yTextOffset = - (int) Math.round(((x + width) - xText) * Math.tan(cantAngle));
yText += yTextOffset; yText += yTextOffset;
AffineTransform orig = g2.getTransform(); AffineTransform orig = g2.getTransform();
@ -639,15 +640,18 @@ public class FinMarkingGuide extends JPanel {
g2.setColor(color); g2.setColor(color);
// Draw an arrow to the left and the text "Fore" // Draw an arrow to the left and the text "Fore"
int arrowXEnd = x + tabSpacing + 50; final int arrowXStart = x + width - tabSpacing - 5;
int arrowY = y + (tabHeight / 2); final int arrowWidth = 50;
int textY = arrowY + g2.getFontMetrics().getHeight() / 2 - 3; final int arrowY = y + (tabHeight / 2);
drawLeftArrowLine(g2, x + tabSpacing, arrowY, arrowXEnd, arrowY); final int textY = arrowY + g2.getFontMetrics().getHeight() / 2 - 3;
g2.drawString(trans.get("FinMarkingGuide.lbl.Front"), arrowXEnd + 3, textY); drawRightArrowLine(g2, arrowXStart - arrowWidth, arrowY, arrowXStart, arrowY);
String frontText = trans.get("FinMarkingGuide.lbl.Front");
final int textWidth = g2.getFontMetrics().stringWidth(frontText);
g2.drawString(frontText, arrowXStart - arrowWidth - textWidth - 3, textY);
} }
/** /**
* Draw a horizontal line with arrows on both endpoints. Depicts a fin alignment. * Draw a horizontal line with arrows on only the right endpoint.
* *
* @param g2 the graphics context * @param g2 the graphics context
* @param x1 the starting x coordinate * @param x1 the starting x coordinate
@ -655,8 +659,8 @@ public class FinMarkingGuide extends JPanel {
* @param x2 the ending x coordinate * @param x2 the ending x coordinate
* @param y2 the ending y coordinate * @param y2 the ending y coordinate
*/ */
void drawLeftArrowLine(Graphics2D g2, int x1, int y1, int x2, int y2) { void drawRightArrowLine(Graphics2D g2, int x1, int y1, int x2, int y2) {
drawArrowLine(g2, x1, y1, x2, y2, 0, true, false); drawArrowLine(g2, x1, y1, x2, y2, 0, false, true);
} }
/** /**