trackeditor: start adding elevation and banking checking

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8557 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 6d7f013303375c057afa6e10746f47e212ec8b53
Former-commit-id: d4e5e4e4886d5a8bccd83ca1394fb2ccd6d12f0f
This commit is contained in:
iobyte 2022-09-26 21:12:46 +00:00
parent fd4ecb40f7
commit 19fd05b825

View file

@ -15,6 +15,7 @@ import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import utils.Editor;
import utils.SegmentVector;
import utils.TrackData;
import utils.circuit.EnvironmentMapping;
import utils.circuit.Segment;
@ -74,6 +75,7 @@ public class CheckDialog extends JDialog
{
public void componentShown(ComponentEvent e)
{
checkTrackHeight();
checkSurfaces();
checkObjects();
checkTerrainGeneration();
@ -87,6 +89,80 @@ public class CheckDialog extends JDialog
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
private void checkTrackHeight()
{
SegmentVector segments = editorFrame.getTrackData().getSegments();
double width = editorFrame.getTrackData().getMainTrack().getWidth();
for (int i = 0; i < segments.size(); i++)
{
Segment segment = segments.get(i);
String segmentInfo = "Segment " + segment.getName() + " : ";
double heightStartLeft = segment.getHeightStartLeft();
boolean hasHeightStartLeft = !Double.isNaN(heightStartLeft);
double heightStartRight = segment.getHeightStartRight();
boolean hasHeightStartRight = !Double.isNaN(heightStartRight);
boolean hasBankingStartFromHeights = hasHeightStartLeft && hasHeightStartRight && heightStartLeft != heightStartRight;
double bankingStart = segment.getBankingStart();
boolean hasBankingStart = !Double.isNaN(bankingStart);
// Track must start at an elevation of 0.0.
if (i == 0)
{
if (hasHeightStartLeft && hasHeightStartRight)
{
double centerHeight = (heightStartLeft + heightStartRight) / 2.0;
if (centerHeight != 0.0)
{
textArea.append(segmentInfo + "Track height at start must be 0. Actual height: " + centerHeight +"\n");
}
}
}
if (hasBankingStart && hasBankingStartFromHeights)
{
textArea.append(segmentInfo + "Banking start angle and banking from heights\n");
double bankingFromHeights = Math.atan2(heightStartLeft - heightStartRight, width) * 180.0 / Math.PI;
if (bankingStart != bankingFromHeights)
{
textArea.append(segmentInfo + "Banking start: " + bankingStart + " doesn't match banking from heights: " + bankingFromHeights + "\n");
}
}
double heightEndLeft = segment.getHeightEndLeft();
boolean hasHeightEndLeft = !Double.isNaN(heightEndLeft);
double heightEndRight = segment.getHeightEndRight();
boolean hasHeightEndRight = !Double.isNaN(heightEndRight);
boolean hasBankingEndFromHeights = hasHeightEndLeft && hasHeightEndRight && heightEndLeft != heightEndRight;
double bankingEnd = segment.getBankingEnd();
boolean hasBankingEnd = !Double.isNaN(bankingEnd);
if (hasBankingEnd && hasBankingEndFromHeights)
{
textArea.append(segmentInfo + "Banking end angle and banking from heights\n");
double bankingFromHeights = Math.atan2(heightEndLeft - heightEndRight, width) * 180.0 / Math.PI;
if (bankingEnd != bankingFromHeights)
{
textArea.append(segmentInfo + "Banking end: " + bankingEnd + " doesn't match banking from heights: " + bankingFromHeights + "\n");
}
}
}
}
private void checkGraphic()
{
String image = editorFrame.getTrackData().getGraphic().getBackgroundImage();