trackeditor: calculate sub-segment heights for linear and spline profils

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

Former-commit-id: 17a2cb565bd2282b9941be8e98d938a645eb3f64
Former-commit-id: 7d9142507ca4bde4b62b003d22fbc5c2e82c88b1
This commit is contained in:
iobyte 2024-01-28 18:38:30 +00:00
parent e7e204c9e8
commit b76a81458c
6 changed files with 238 additions and 122 deletions

View file

@ -846,18 +846,24 @@ public class XmlReader
shape = new Curve(type, null); shape = new Curve(type, null);
} }
shape = setSegment(e, shape, prev); shape = setSegment(e, shape, prev);
try
{
shape.calcShape(editorFrame);
} catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
trackData.add(shape); trackData.add(shape);
prev = shape; prev = shape;
} }
editorFrame.getTrackData().setSegments(trackData); editorFrame.getTrackData().setSegments(trackData);
editorFrame.getTrackData().calculateSegmentValues();
for (Segment segment : editorFrame.getTrackData().getSegments())
{
try
{
segment.calcShape(editorFrame);
}
catch (Exception e)
{
e.printStackTrace();
}
}
} }
private synchronized Segment setSegment(Element seg, Segment shape, private synchronized Segment setSegment(Element seg, Segment shape,

View file

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

View file

@ -135,17 +135,6 @@ public class SegmentVector extends Vector<Segment>
} }
} }
public void dumpCalculated(String indent)
{
System.out.println(indent + "Track Segments");
for (int i = 0; i < size(); i++)
{
System.out.println(indent + " segment[" + i + "]");
get(i).dumpCalculated(indent + " ");
}
}
public void dumpLinks() public void dumpLinks()
{ {
for (int i = 0; i < size(); i++) for (int i = 0; i < size(); i++)

View file

@ -124,13 +124,10 @@ public class Curve extends Segment
double rightSideEndWidth = getValidRightSideEndWidth(editorFrame); double rightSideEndWidth = getValidRightSideEndWidth(editorFrame);
double leftBarrierWidth = getValidLeftBarrierWidth(editorFrame); double leftBarrierWidth = getValidLeftBarrierWidth(editorFrame);
double rightBarrierWidth = getValidRightBarrierWidth(editorFrame); double rightBarrierWidth = getValidRightBarrierWidth(editorFrame);
double leftStartHeight = this.getCalculatedHeightStartLeft();
/** double rightStartHeight = this.getCalculatedHeightStartRight();
* double leftEndHeight = this.getCalculatedHeightEndLeft();
* New code double rightEndHeight = this.getCalculatedHeightEndRight();
*
*
*/
// calc turn length // calc turn length
double arc = getArcRad(); double arc = getArcRad();
@ -162,9 +159,13 @@ public class Curve extends Segment
tmpRadius += deltaRadiusStep; tmpRadius += deltaRadiusStep;
} }
stepLength *= arc / tmpAngle; stepLength *= arc / tmpAngle;
} else }
else
{
deltaRadiusStep = (radiusEnd - radiusStart) / nbSteps; deltaRadiusStep = (radiusEnd - radiusStart) / nbSteps;
} else }
}
else
{ {
deltaRadiusStep = 0; deltaRadiusStep = 0;
} }
@ -188,6 +189,24 @@ public class Curve extends Segment
double leftSideDeltaStep = (leftSideEndWidth - leftSideStartWidth) / nbSteps; double leftSideDeltaStep = (leftSideEndWidth - leftSideStartWidth) / nbSteps;
double rightSideDeltaStep = (rightSideEndWidth - rightSideStartWidth) / nbSteps; double rightSideDeltaStep = (rightSideEndWidth - rightSideStartWidth) / nbSteps;
double leftHeightDeltaStep = (leftEndHeight - leftStartHeight) / nbSteps;
double rightHeightDeltaStep = (rightEndHeight - rightStartHeight) / nbSteps;
boolean linear = getValidProfil(editorFrame).equals("linear");
double T1l = getCalculatedStartTangentLeft() * getLength();
double T2l = getCalculatedEndTangentLeft() * getLength();
double tl = 0.0;
double dtl = 1.0 / nbSteps;
double T1r = getCalculatedStartTangentRight() * getLength();
double T2r = getCalculatedEndTangentRight() * getLength();
double tr = 0.0;
double dtr = 1.0 / nbSteps;
double curzsl = leftStartHeight;
double curzsr = rightStartHeight;
double curzel = leftStartHeight;
double curzer = rightStartHeight;
int currentSubSeg = 0; int currentSubSeg = 0;
for (int nStep = 0; nStep < nbSteps; nStep++) for (int nStep = 0; nStep < nbSteps; nStep++)
@ -204,7 +223,8 @@ public class Curve extends Segment
xCenter = currentX - cosTrans * curRadius; xCenter = currentX - cosTrans * curRadius;
yCenter = currentY - sinTrans * curRadius; yCenter = currentY - sinTrans * curRadius;
thisStepArc = -stepLength / curRadius; thisStepArc = -stepLength / curRadius;
} else }
else
{ {
xCenter = currentX + cosTrans * curRadius; xCenter = currentX + cosTrans * curRadius;
yCenter = currentY + sinTrans * curRadius; yCenter = currentY + sinTrans * curRadius;
@ -212,8 +232,9 @@ public class Curve extends Segment
} }
if (nStep == 0) if (nStep == 0)
// center.setLocation( xCenter, -yCenter ); {
center.setLocation(xCenter, yCenter); center.setLocation(xCenter, yCenter);
}
double cos = Math.cos(thisStepArc); double cos = Math.cos(thisStepArc);
double sin = Math.sin(thisStepArc); double sin = Math.sin(thisStepArc);
@ -241,6 +262,30 @@ public class Curve extends Segment
points[currentSubSeg + 2].x = x * cos - y * sin + xCenter; points[currentSubSeg + 2].x = x * cos - y * sin + xCenter;
points[currentSubSeg + 2].y = y * cos + x * sin + yCenter; points[currentSubSeg + 2].y = y * cos + x * sin + yCenter;
if (linear)
{
points[currentSubSeg + 0].z = leftStartHeight + leftHeightDeltaStep * nStep;
points[currentSubSeg + 1].z = leftStartHeight + leftHeightDeltaStep * (nStep + 1);
points[currentSubSeg + 2].z = rightStartHeight + rightHeightDeltaStep * (nStep + 1);
points[currentSubSeg + 3].z = rightStartHeight + rightHeightDeltaStep * nStep;
}
else
{
tl += dtl;
tr += dtr;
curzsl = curzel;
curzel = trackSpline(leftStartHeight, leftEndHeight, T1l, T2l, tl);
curzsr = curzer;
curzer = trackSpline(rightStartHeight, rightEndHeight, T1r, T2r, tr);
points[currentSubSeg + 0].z = curzsl;
points[currentSubSeg + 1].z = curzel;
points[currentSubSeg + 2].z = curzer;
points[currentSubSeg + 3].z = curzsr;
}
currentSubSeg += 4; currentSubSeg += 4;
// left border // left border
@ -420,15 +465,10 @@ public class Curve extends Segment
Editor.getProperties().setCurrentY(currentY); Editor.getProperties().setCurrentY(currentY);
} }
// public void draw(Graphics g, AffineTransform affineTransform)
// {
// calcShape();
// }
public void drag(Point2D.Double dragDelta) public void drag(Point2D.Double dragDelta)
{ {
} }
/** /**
* @return Returns the arc. * @return Returns the arc.
*/ */

View file

@ -308,6 +308,21 @@ public class Segment implements Cloneable
return false; return false;
} }
public double trackSpline(double p0, double p1, double t0, double t1, double t)
{
double t2, t3;
double h0, h1, h2, h3;
t2 = t * t;
t3 = t * t2;
h1 = 3 * t2 - 2 * t3;
h0 = 1 - h1;
h2 = t3 - 2 * t2 + t;
h3 = t3 - t2;
return h0 * p0 + h1 * p1 + h2 * t0 + h3 * t1;
}
public Rectangle2D.Double getBounds() public Rectangle2D.Double getBounds()
{ {
if (points == null || points.length == 0) if (points == null || points.length == 0)
@ -2239,10 +2254,41 @@ public class Segment implements Cloneable
right.setSideBankingType(getValidRightSideBankingType(editorFrame)); right.setSideBankingType(getValidRightSideBankingType(editorFrame));
} }
public void dumpCalculated(String indent) public void dump(String indent)
{ {
dump(indent, true, true, true, true);
}
public void dump(String indent, boolean dumpCalculated, boolean dumpPoints, boolean dumpTrPoints, boolean dumpToDraw)
{
System.out.println(indent + "Segment");
System.out.println(indent + " previousShape : " + (previousShape != null ? previousShape.name : "null"));
System.out.println(indent + " nextShape : " + (nextShape != null ? nextShape.name : "null"));
System.out.println(indent + " name : " + name); System.out.println(indent + " name : " + name);
System.out.println(indent + " type : " + type); System.out.println(indent + " type : " + type);
System.out.println(indent + " count : " + count);
System.out.println(indent + " length : " + length);
System.out.println(indent + " surface : " + surface);
System.out.println(indent + " heightStart : " + heightStart);
System.out.println(indent + " heightStartLeft : " + heightStartLeft);
System.out.println(indent + " heightStartRight : " + heightStartRight);
System.out.println(indent + " heightEnd : " + heightEnd);
System.out.println(indent + " heightEndLeft : " + heightEndLeft);
System.out.println(indent + " heightEndRight : " + heightEndRight);
System.out.println(indent + " grade : " + grade);
System.out.println(indent + " bankingStart : " + bankingStart);
System.out.println(indent + " bankingEnd : " + bankingEnd);
System.out.println(indent + " profil : " + profil);
System.out.println(indent + " profilSteps : " + profilSteps);
System.out.println(indent + " profilStepsLength : " + profilStepsLength);
System.out.println(indent + " profilStartTangent : " + profilStartTangent);
System.out.println(indent + " profilEndTangent : " + profilEndTangent);
System.out.println(indent + " profilStartTangentLeft : " + profilStartTangentLeft);
System.out.println(indent + " profilEndTangentLeft : " + profilEndTangentLeft);
System.out.println(indent + " profilStartTangentRight : " + profilStartTangentRight);
System.out.println(indent + " profilEndTangentRight : " + profilEndTangentRight);
if (dumpCalculated)
{
System.out.println(indent + " calculatedHeightStart : " + calculatedHeightStart); System.out.println(indent + " calculatedHeightStart : " + calculatedHeightStart);
System.out.println(indent + " calculatedHeightStartLeft : " + calculatedHeightStartLeft); System.out.println(indent + " calculatedHeightStartLeft : " + calculatedHeightStartLeft);
System.out.println(indent + " calculatedHeightStartRight : " + calculatedHeightStartRight); System.out.println(indent + " calculatedHeightStartRight : " + calculatedHeightStartRight);
@ -2260,35 +2306,18 @@ public class Segment implements Cloneable
System.out.println(indent + " calculatedEndTangentRight : " + calculatedEndTangentRight); System.out.println(indent + " calculatedEndTangentRight : " + calculatedEndTangentRight);
} }
public void dump(String indent)
{
System.out.println(indent + "Segment");
System.out.println(indent + " previousShape : " + (previousShape != null ? previousShape.name : "null"));
System.out.println(indent + " nextShape : " + (nextShape != null ? nextShape.name : "null"));
System.out.println(indent + " name : " + name);
System.out.println(indent + " type : " + type);
System.out.println(indent + " count : " + count);
System.out.println(indent + " calculatedHeightStart : " + calculatedHeightStart);
System.out.println(indent + " calculatedHeightStartLeft : " + calculatedHeightStartLeft);
System.out.println(indent + " calculatedHeightStartRight : " + calculatedHeightStartRight);
System.out.println(indent + " calculatedHeightEnd : " + calculatedHeightEndLeft);
System.out.println(indent + " calculatedHeightEndLeft : " + calculatedHeightEndLeft);
System.out.println(indent + " calculatedHeightEndRight : " + calculatedHeightEndRight);
System.out.println(indent + " calculatedGrade : " + calculatedGrade);
System.out.println(indent + " calculatedBankingStart : " + calculatedBankingStart);
System.out.println(indent + " calculatedBankingEnd : " + calculatedBankingEnd);
System.out.println(indent + " calculatedStartTangent : " + calculatedStartTangent);
System.out.println(indent + " calculatedStartTangentLeft : " + calculatedStartTangentLeft);
System.out.println(indent + " calculatedStartTangentRight : " + calculatedStartTangentRight);
System.out.println(indent + " calculatedEndTangent : " + calculatedEndTangent);
System.out.println(indent + " calculatedEndTangentLeft : " + calculatedEndTangentLeft);
System.out.println(indent + " calculatedEndTangentRight : " + calculatedEndTangentRight);
if (points != null) if (points != null)
{ {
System.out.println(indent + " points : " + points.length); System.out.println(indent + " points : " + points.length);
if (dumpPoints)
{
for (int i = 0; i < points.length; i++) for (int i = 0; i < points.length; i++)
{ {
System.out.println(indent + " points[" + i + "] " + points[i].x + ", " + points[i].y + ", " + points[i].z); System.out.println(indent + " points[" + i + "] " +
String.format("%12.7f", points[i].x) + ", " +
String.format("%12.7f", points[i].y) + ", " +
String.format("%12.7f", points[i].z));
}
} }
} }
else else
@ -2298,15 +2327,20 @@ public class Segment implements Cloneable
if (trPoints != null) if (trPoints != null)
{ {
System.out.println(indent + " trPoints : " + trPoints.length); System.out.println(indent + " trPoints : " + trPoints.length);
if (dumpTrPoints)
{
for (int i = 0; i < trPoints.length; i++) for (int i = 0; i < trPoints.length; i++)
{ {
System.out.println(indent + " trPoints[" + i + "] " + trPoints[i].x + ", " + trPoints[i].y); System.out.println(indent + " trPoints[" + i + "] " + trPoints[i].x + ", " + trPoints[i].y);
} }
} }
}
else else
{ {
System.out.println(indent + " trPoints : null"); System.out.println(indent + " trPoints : null");
} }
if (dumpToDraw)
{
if (xToDraw != null) if (xToDraw != null)
{ {
System.out.println(indent + " xToDraw : " + xToDraw.length); System.out.println(indent + " xToDraw : " + xToDraw.length);
@ -2331,6 +2365,7 @@ public class Segment implements Cloneable
{ {
System.out.println(indent + " yToDraw : null"); System.out.println(indent + " yToDraw : null");
} }
}
System.out.println(indent + " dx : " + dx); System.out.println(indent + " dx : " + dx);
System.out.println(indent + " dy : " + dy); System.out.println(indent + " dy : " + dy);
} }

View file

@ -99,6 +99,10 @@ public class Straight extends Segment
double rightSideEndWidth = getValidRightSideEndWidth(editorFrame); double rightSideEndWidth = getValidRightSideEndWidth(editorFrame);
double leftBarrierWidth = getValidLeftBarrierWidth(editorFrame); double leftBarrierWidth = getValidLeftBarrierWidth(editorFrame);
double rightBarrierWidth = getValidRightBarrierWidth(editorFrame); double rightBarrierWidth = getValidRightBarrierWidth(editorFrame);
double leftStartHeight = this.getCalculatedHeightStartLeft();
double rightStartHeight = this.getCalculatedHeightStartRight();
double leftEndHeight = this.getCalculatedHeightEndLeft();
double rightEndHeight = this.getCalculatedHeightEndRight();
int nbSteps = 1; int nbSteps = 1;
if (hasProfilSteps()) if (hasProfilSteps())
@ -127,12 +131,30 @@ public class Straight extends Segment
double leftSideDeltaStep = (leftSideEndWidth - leftSideStartWidth) / nbSteps; double leftSideDeltaStep = (leftSideEndWidth - leftSideStartWidth) / nbSteps;
double rightSideDeltaStep = (rightSideEndWidth - rightSideStartWidth) / nbSteps; double rightSideDeltaStep = (rightSideEndWidth - rightSideStartWidth) / nbSteps;
double leftHeightDeltaStep = (leftEndHeight - leftStartHeight) / nbSteps;
double rightHeightDeltaStep = (rightEndHeight - rightStartHeight) / nbSteps;
double cos = Math.cos(currentA) * stepLength; double cos = Math.cos(currentA) * stepLength;
double sin = Math.sin(currentA) * stepLength; double sin = Math.sin(currentA) * stepLength;
double cosTransLeft = Math.cos(currentA + Math.PI / 2); double cosTransLeft = Math.cos(currentA + Math.PI / 2);
double sinTransLeft = Math.sin(currentA + Math.PI / 2); double sinTransLeft = Math.sin(currentA + Math.PI / 2);
boolean linear = getValidProfil(editorFrame).equals("linear");
double T1l = getCalculatedStartTangentLeft() * getLength();
double T2l = getCalculatedEndTangentLeft() * getLength();
double tl = 0.0;
double dtl = 1.0 / nbSteps;
double T1r = getCalculatedStartTangentRight() * getLength();
double T2r = getCalculatedEndTangentRight() * getLength();
double tr = 0.0;
double dtr = 1.0 / nbSteps;
double curzsl = leftStartHeight;
double curzsr = rightStartHeight;
double curzel = leftStartHeight;
double curzer = rightStartHeight;
for (int nStep = 0; nStep < nbSteps; nStep++) for (int nStep = 0; nStep < nbSteps; nStep++)
{ {
// track // track
@ -148,6 +170,30 @@ public class Straight extends Segment
points[currentSubSeg + 2].x = points[currentSubSeg + 3].x + cos; points[currentSubSeg + 2].x = points[currentSubSeg + 3].x + cos;
points[currentSubSeg + 2].y = points[currentSubSeg + 3].y + sin; points[currentSubSeg + 2].y = points[currentSubSeg + 3].y + sin;
if (linear)
{
points[currentSubSeg + 0].z = leftStartHeight + leftHeightDeltaStep * nStep;
points[currentSubSeg + 1].z = leftStartHeight + leftHeightDeltaStep * (nStep + 1);
points[currentSubSeg + 2].z = rightStartHeight + rightHeightDeltaStep * (nStep + 1);
points[currentSubSeg + 3].z = rightStartHeight + rightHeightDeltaStep * nStep;
}
else
{
tl += dtl;
tr += dtr;
curzsl = curzel;
curzel = trackSpline(leftStartHeight, leftEndHeight, T1l, T2l, tl);
curzsr = curzer;
curzer = trackSpline(rightStartHeight, rightEndHeight, T1r, T2r, tr);
points[currentSubSeg + 0].z = curzsl;
points[currentSubSeg + 1].z = curzel;
points[currentSubSeg + 2].z = curzer;
points[currentSubSeg + 3].z = curzsr;
}
// left border // left border
points[currentSubSeg + 4].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth); points[currentSubSeg + 4].x = currentX + cosTransLeft * (trackWidth / 2 + leftBorderWidth);