trackeditor: show steps for straights

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9281 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
iobyte 2024-01-25 01:10:35 +00:00
parent 9cc818b430
commit 13621473cb
10 changed files with 200 additions and 149 deletions

View File

@ -108,6 +108,7 @@ IF(Java_Development_FOUND AND Java_FOUND)
utils/circuit/ObjectData.java
utils/circuit/ObjectMap.java
utils/circuit/Pits.java
utils/circuit/Point3D.java
utils/circuit/Reliefs.java
utils/circuit/Sector.java
utils/circuit/Segment.java

View File

@ -34,7 +34,7 @@ public class Properties
private static Properties instance = new Properties();
private Vector<ActionListener> propertiesListeners = new Vector<ActionListener>();
public final String title = "sd2-trackeditor";
public final String version = "1.4.18";
public final String version = "1.4.19";
private String path;
private double imageScale = 1;

View File

@ -171,14 +171,14 @@ public class Curve extends Segment
if (points == null || points.length != 4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps)
{
points = new Point2D.Double[4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps];
points = new Point3D[4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps];
for (int i = 0; i < points.length; i++)
points[i] = new Point2D.Double();
points[i] = new Point3D();
trPoints = new Point2D.Double[4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps];
trPoints = new Point3D[4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps];
for (int i = 0; i < trPoints.length; i++)
trPoints[i] = new Point2D.Double();
trPoints[i] = new Point3D();
}
boolean dir = type.equals("rgt");

View File

@ -37,13 +37,13 @@ public class ObjShapeHandle extends Segment
{
if (points == null)
{
points = new Point2D.Double[1]; // 1 points in 2D
points = new Point3D[1]; // 1 points in 2D
for (int i = 0; i < points.length; i++)
points[i] = new Point2D.Double();
points[i] = new Point3D();
trPoints = new Point2D.Double[1];
trPoints = new Point3D[1];
for (int i = 0; i < trPoints.length; i++)
trPoints[i] = new Point2D.Double();
trPoints[i] = new Point3D();
}
points[0].x = location.getX();

View File

@ -145,13 +145,13 @@ public class ObjShapeObject extends Segment
if (points == null)
{
points = new Point2D.Double[4]; // 4 points in 2D
points = new Point3D[4]; // 4 points in 2D
for (int i = 0; i < points.length; i++)
points[i] = new Point2D.Double();
points[i] = new Point3D();
trPoints = new Point2D.Double[4];
trPoints = new Point3D[4];
for (int i = 0; i < trPoints.length; i++)
trPoints[i] = new Point2D.Double();
trPoints[i] = new Point3D();
}
points[0].x = this.location.getX() - width / 2;

View File

@ -124,13 +124,13 @@ public class ObjShapeRelief extends Segment
xToDraw = new int[vertices.size()];
yToDraw = new int[vertices.size()];
points = new Point2D.Double[vertices.size()];
points = new Point3D[vertices.size()];
for (int i = 0; i < points.length; i++)
points[i] = new Point2D.Double();
points[i] = new Point3D();
trPoints = new Point2D.Double[vertices.size()];
trPoints = new Point3D[vertices.size()];
for (int i = 0; i < trPoints.length; i++)
trPoints[i] = new Point2D.Double();
trPoints[i] = new Point3D();
}
for (int i = 0; i < points.length; i++)

View File

@ -37,13 +37,13 @@ public class ObjShapeTerrain extends Segment
// TODO get border and holes from relief file someday
if (points == null)
{
points = new Point2D.Double[4]; // 4 points in 2D
points = new Point3D[4]; // 4 points in 2D
for (int i = 0; i < points.length; i++)
points[i] = new Point2D.Double();
points[i] = new Point3D();
trPoints = new Point2D.Double[4];
trPoints = new Point3D[4];
for (int i = 0; i < trPoints.length; i++)
trPoints[i] = new Point2D.Double();
trPoints[i] = new Point3D();
}
double border = editorFrame.getTrackData().getGraphic().getTerrainGeneration().getBorderMargin();

View File

@ -0,0 +1,24 @@
package utils.circuit;
import java.awt.geom.Point2D;
public class Point3D extends Point2D.Double
{
public double z;
public Point3D()
{
super();
}
public Point3D(double x, double y, double z)
{
super(x, y);
this.z = z;
}
public String toString()
{
return "Point3D["+x+", "+y+", "+z+"]";
}
}

View File

@ -104,8 +104,8 @@ public class Segment implements Cloneable
protected double calculatedEndTangentRight = Double.NaN;
// shape to be drawn
public Point2D.Double points[];
public Point2D.Double trPoints[];
public Point3D points[];
public Point3D trPoints[];
// datas for fast 'draw' process
int xToDraw[] = new int[4];
@ -879,14 +879,14 @@ public class Segment implements Cloneable
/**
* @return Returns the points.
*/
public Point2D.Double[] getPoints()
public Point3D[] getPoints()
{
return points;
}
/**
* @param points The points to set.
*/
public void setPoints(Point2D.Double[] points)
public void setPoints(Point3D[] points)
{
this.points = points;
}

View File

@ -89,6 +89,7 @@ public class Straight extends Segment
double currentY = Editor.getProperties().getCurrentY();
double currentA = Editor.getProperties().getCurrentA();
double showArrows = Editor.getProperties().getShowArrows();
double profilStepsLength = getValidProfilStepsLength(editorFrame);
double trackWidth = editorFrame.getTrackData().getMainTrack().getWidth();
double leftBorderWidth = getValidLeftBorderWidth(editorFrame);
double rightBorderWidth = getValidRightBorderWidth(editorFrame);
@ -99,145 +100,170 @@ public class Straight extends Segment
double leftBarrierWidth = getValidLeftBarrierWidth(editorFrame);
double rightBarrierWidth = getValidRightBarrierWidth(editorFrame);
if (points == null || points.length != 4 * (7 + (showArrows > 0.0 ? 1 : 0)))
int nbSteps = 1;
if (hasProfilSteps())
{
points = new Point2D.Double[4 * (7 + (showArrows > 0.0 ? 1 : 0))];
for (int i = 0; i < points.length; i++)
points[i] = new Point2D.Double();
trPoints = new Point2D.Double[4 * (7 + (showArrows > 0.0 ? 1 : 0))];
for (int i = 0; i < trPoints.length; i++)
trPoints[i] = new Point2D.Double();
nbSteps = getProfilSteps();
}
double cos = Math.cos(currentA) * length;
double sin = Math.sin(currentA) * length;
else
{
nbSteps = (int) (length / profilStepsLength + 0.5) + 1;
}
double stepLength = length / nbSteps;
if (points == null || points.length != 4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps)
{
points = new Point3D[4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps];
for (int i = 0; i < points.length; i++)
points[i] = new Point3D();
trPoints = new Point3D[4 * (7 + (showArrows > 0.0 ? 1 : 0)) * nbSteps];
for (int i = 0; i < trPoints.length; i++)
trPoints[i] = new Point3D();
}
int currentSubSeg = 0;
double leftSideDeltaStep = (leftSideEndWidth - leftSideStartWidth) / nbSteps;
double rightSideDeltaStep = (rightSideEndWidth - rightSideStartWidth) / nbSteps;
double cos = Math.cos(currentA) * stepLength;
double sin = Math.sin(currentA) * stepLength;
double cosTransLeft = Math.cos(currentA + Math.PI / 2);
double sinTransLeft = Math.sin(currentA + Math.PI / 2);
// track
points[0].x = currentX + cosTransLeft * trackWidth / 2;
points[0].y = currentY + sinTransLeft * trackWidth / 2;
points[1].x = points[0].x + cos;
points[1].y = points[0].y + sin;
points[3].x = currentX - cosTransLeft * trackWidth / 2;
points[3].y = currentY - sinTransLeft * trackWidth / 2;
points[2].x = points[3].x + cos;
points[2].y = points[3].y + sin;
// left border
points[4].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth);
points[4].y = currentY + sinTransLeft * (trackWidth / 2 + leftBorderWidth);
points[5].x = points[4].x + cos;
points[5].y = points[4].y + sin;
points[7].x = points[0].x;
points[7].y = points[0].y;
points[6].x = points[1].x;
points[6].y = points[1].y;
// left side
points[8].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth);
points[8].y = currentY + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth);
points[9].x = currentX + cos + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideEndWidth);
points[9].y = currentY + sin + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideEndWidth);
points[10].x = points[5].x;
points[10].y = points[5].y;
points[11].x = points[4].x;
points[11].y = points[4].y;
// left barrier
points[12].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + leftBarrierWidth);
points[12].y = currentY + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + leftBarrierWidth);
points[13].x = currentX + cos + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideEndWidth + leftBarrierWidth);
points[13].y = currentY + sin + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideEndWidth + leftBarrierWidth);
points[15].x = points[8].x;
points[15].y = points[8].y;
points[14].x = points[9].x;
points[14].y = points[9].y;
// right border
points[16].x = currentX - cosTransLeft * (trackWidth / 2 + rightBorderWidth);
points[16].y = currentY - sinTransLeft * (trackWidth / 2 + rightBorderWidth);
points[17].x = points[16].x + cos;
points[17].y = points[16].y + sin;
points[19].x = points[3].x;
points[19].y = points[3].y;
points[18].x = points[2].x;
points[18].y = points[2].y;
// right side
points[20].x = currentX - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth);
points[20].y = currentY - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth);
points[21].x = currentX + cos - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideEndWidth);
points[21].y = currentY + sin - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideEndWidth);
points[22].x = points[17].x;
points[22].y = points[17].y;
points[23].x = points[16].x;
points[23].y = points[16].y;
// right barrier
points[24].x = currentX - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + rightBarrierWidth);
points[24].y = currentY - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + rightBarrierWidth);
points[25].x = currentX + cos - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideEndWidth + rightBarrierWidth);
points[25].y = currentY + sin - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideEndWidth + rightBarrierWidth);
points[27].x = points[20].x;
points[27].y = points[20].y;
points[26].x = points[21].x;
points[26].y = points[21].y;
if (showArrows > 0.0)
for (int nStep = 0; nStep < nbSteps; nStep++)
{
// arrow
points[28].x = currentX + cosTransLeft * trackWidth / 2;
points[28].y = currentY + sinTransLeft * trackWidth / 2;
// track
points[currentSubSeg + 0].x = currentX + cosTransLeft * trackWidth / 2;
points[currentSubSeg + 0].y = currentY + sinTransLeft * trackWidth / 2;
points[29].x = points[0].x + cos - (cosTransLeft * trackWidth / 2) * 0.99999;
points[29].y = points[0].y + sin - (sinTransLeft * trackWidth / 2) * 0.99999;
points[currentSubSeg + 1].x = points[currentSubSeg + 0].x + cos;
points[currentSubSeg + 1].y = points[currentSubSeg + 0].y + sin;
points[31].x = currentX - cosTransLeft * trackWidth / 2;
points[31].y = currentY - sinTransLeft * trackWidth / 2;
points[currentSubSeg + 3].x = currentX - cosTransLeft * trackWidth / 2;
points[currentSubSeg + 3].y = currentY - sinTransLeft * trackWidth / 2;
points[30].x = points[23].x + cos + (cosTransLeft * trackWidth / 2) * 0.99999;
points[30].y = points[23].y + sin + (sinTransLeft * trackWidth / 2) * 0.99999;
points[currentSubSeg + 2].x = points[currentSubSeg + 3].x + cos;
points[currentSubSeg + 2].y = points[currentSubSeg + 3].y + sin;
// left border
points[currentSubSeg + 4].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth);
points[currentSubSeg + 4].y = currentY + sinTransLeft * (trackWidth / 2 + leftBorderWidth);
points[currentSubSeg + 5].x = points[currentSubSeg + 4].x + cos;
points[currentSubSeg + 5].y = points[currentSubSeg + 4].y + sin;
points[currentSubSeg + 7].x = points[currentSubSeg + 0].x;
points[currentSubSeg + 7].y = points[currentSubSeg + 0].y;
points[currentSubSeg + 6].x = points[currentSubSeg + 1].x;
points[currentSubSeg + 6].y = points[currentSubSeg + 1].y;
// left side
points[currentSubSeg + 8].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * nStep));
points[currentSubSeg + 8].y = currentY + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * nStep));
points[currentSubSeg + 9].x = currentX + cos + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * (nStep + 1)));
points[currentSubSeg + 9].y = currentY + sin + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * (nStep + 1)));
points[currentSubSeg + 10].x = points[currentSubSeg + 5].x;
points[currentSubSeg + 10].y = points[currentSubSeg + 5].y;
points[currentSubSeg + 11].x = points[currentSubSeg + 4].x;
points[currentSubSeg + 11].y = points[currentSubSeg + 4].y;
// left barrier
points[currentSubSeg + 12].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * nStep) + leftBarrierWidth);
points[currentSubSeg + 12].y = currentY + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * nStep) + leftBarrierWidth);
points[currentSubSeg + 13].x = currentX + cos + cosTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * (nStep + 1)) + leftBarrierWidth);
points[currentSubSeg + 13].y = currentY + sin + sinTransLeft * (trackWidth / 2 + leftBorderWidth + leftSideStartWidth + (leftSideDeltaStep * (nStep + 1)) + leftBarrierWidth);
points[currentSubSeg + 15].x = points[currentSubSeg + 8].x;
points[currentSubSeg + 15].y = points[currentSubSeg + 8].y;
points[currentSubSeg + 14].x = points[currentSubSeg + 9].x;
points[currentSubSeg + 14].y = points[currentSubSeg + 9].y;
// right border
points[currentSubSeg + 16].x = currentX - cosTransLeft * (trackWidth / 2 + rightBorderWidth);
points[currentSubSeg + 16].y = currentY - sinTransLeft * (trackWidth / 2 + rightBorderWidth);
points[currentSubSeg + 17].x = points[currentSubSeg + 16].x + cos;
points[currentSubSeg + 17].y = points[currentSubSeg + 16].y + sin;
points[currentSubSeg + 19].x = points[currentSubSeg + 3].x;
points[currentSubSeg + 19].y = points[currentSubSeg + 3].y;
points[currentSubSeg + 18].x = points[currentSubSeg + 2].x;
points[currentSubSeg + 18].y = points[currentSubSeg + 2].y;
// right side
points[currentSubSeg + 20].x = currentX - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * nStep));
points[currentSubSeg + 20].y = currentY - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * nStep));
points[currentSubSeg + 21].x = currentX + cos - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * (nStep + 1)));
points[currentSubSeg + 21].y = currentY + sin - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * (nStep + 1)));
points[currentSubSeg + 22].x = points[currentSubSeg + 17].x;
points[currentSubSeg + 22].y = points[currentSubSeg + 17].y;
points[currentSubSeg + 23].x = points[currentSubSeg + 16].x;
points[currentSubSeg + 23].y = points[currentSubSeg + 16].y;
// right barrier
points[currentSubSeg + 24].x = currentX - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * nStep) + rightBarrierWidth);
points[currentSubSeg + 24].y = currentY - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * nStep) + rightBarrierWidth);
points[currentSubSeg + 25].x = currentX + cos - cosTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * (nStep + 1)) + rightBarrierWidth);
points[currentSubSeg + 25].y = currentY + sin - sinTransLeft * (trackWidth / 2 + rightBorderWidth + rightSideStartWidth + (rightSideDeltaStep * (nStep + 1)) + rightBarrierWidth);
points[currentSubSeg + 27].x = points[currentSubSeg + 20].x;
points[currentSubSeg + 27].y = points[currentSubSeg + 20].y;
points[currentSubSeg + 26].x = points[currentSubSeg + 21].x;
points[currentSubSeg + 26].y = points[currentSubSeg + 21].y;
if (showArrows > 0.0)
{
// arrow
points[currentSubSeg + 28].x = currentX + cosTransLeft * trackWidth / 2;
points[currentSubSeg + 28].y = currentY + sinTransLeft * trackWidth / 2;
points[currentSubSeg + 29].x = points[currentSubSeg + 0].x + cos - (cosTransLeft * trackWidth / 2) * 0.99999;
points[currentSubSeg + 29].y = points[currentSubSeg + 0].y + sin - (sinTransLeft * trackWidth / 2) * 0.99999;
points[currentSubSeg + 31].x = currentX - cosTransLeft * trackWidth / 2;
points[currentSubSeg + 31].y = currentY - sinTransLeft * trackWidth / 2;
points[currentSubSeg + 30].x = points[currentSubSeg + 23].x + cos + (cosTransLeft * trackWidth / 2) * 0.99999;
points[currentSubSeg + 30].y = points[currentSubSeg + 23].y + sin + (sinTransLeft * trackWidth / 2) * 0.99999;
currentSubSeg += 32;
}
else
{
currentSubSeg += 28;
}
// move track center
this.dx = cos;
this.dy = sin;
currentX += cos;
currentY += sin;
}
// move track center
this.dx = cos;
this.dy = sin;
currentX += cos;
currentY += sin;
endTrackCenter.setLocation(currentX, currentY);
endTrackAlpha = startTrackAlpha;
//System.out.println("X = "+tmpX+" , Y = "+tmpY+" , Length = "+this.length);
Editor.getProperties().setCurrentA(currentA);
Editor.getProperties().setCurrentX(currentX);
Editor.getProperties().setCurrentY(currentY);