Skip to content

Commit 23cb0c3

Browse files
committed
Prevent visual elevation entirely if superelevation is turned off
1 parent ce89147 commit 23cb0c3

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Source/Orts.Simulation/Simulation/SuperElevation.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ void MarkSections(Simulator simulator, List<TrVectorSection> SectionList, float
215215
}
216216
}
217217

218-
if (standard == null || maxElev < standard.MinCantM)
218+
if ((standard == null || maxElev < standard.MinCantM) && !SectionList.Any(s => s.NomElevM > 0.0f))
219219
{
220220
foreach (TrVectorSection s in SectionList)
221+
{
221222
s.NomElevM = 0; // No superelevation needed, or curve is so short that no meaningful superelevation can be applied
223+
return;
224+
}
222225
}
223226
else
224227
{
@@ -383,12 +386,17 @@ void MarkSections(Simulator simulator, List<TrVectorSection> SectionList, float
383386

384387
SectionList[count].PhysElevTable = new Interpolator(positions, elevations);
385388

386-
// Visual superelevation is stored in terms of angle in radians rather than meters
387-
float[] angles = elevations.Select(e => (float)Math.Asin(e / simulator.SuperElevationGauge)).ToArray();
388-
SectionList[count].VisElevTable = new Interpolator(SectionList[count].PhysElevTable.X, angles);
389-
// Invert visual elevation values based on curve direction
390-
// direction is negated for consistency of direction sense in other places
391-
SectionList[count].VisElevTable.ScaleY(-direction);
389+
// Only generate visual superelevation if option is enabled
390+
if (simulator.UseSuperElevation)
391+
{
392+
// Visual superelevation is stored in terms of angle in radians rather than meters
393+
float[] angles = elevations.Select(e => (float)Math.Asin(e / simulator.SuperElevationGauge)).ToArray();
394+
395+
SectionList[count].VisElevTable = new Interpolator(SectionList[count].PhysElevTable.X, angles);
396+
// Invert visual elevation values based on curve direction
397+
// direction is negated for consistency of direction sense in other places
398+
SectionList[count].VisElevTable.ScaleY(-direction);
399+
}
392400

393401
accumulatedLength += lengths[count];
394402
count++;

0 commit comments

Comments
 (0)