Skip to content

Commit d976fec

Browse files
committed
Automatic merge of T1.5.1-1695-gade019506 and 16 pull requests
- Pull request #570 at f11a428: glTF 2.0 support with PBR lighting - Pull request #900 at 4629736: DMI in 3D cab + two more dials - Pull request #1030 at d3ae4a2: Refactor settings, in prep for settings exporter - Pull request #1045 at cc4d53c: Bugfix: Empty Start Time for Explore, and other issues loading from Menu Selection and Content Routes - Pull request #1052 at 3b5cb90: Content Manager: Add axle count, and lowest derail force - Pull request #1062 at b96d6fa: Train Forces popup Window. - Pull request #1064 at 52410f9: Add Train Info tab to Help window (F1) - Pull request #1066 at 62c89c1: Log derailment, using TraceInformation. - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #896 at 335f998: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #1000 at d8d9709: Locomotive operation from control car - Pull request #1057 at 254b6d4: Switchable brake system - Pull request #1069 at 3f153f0: Mouse wheel control only with Alt – Followup for #1051 - Pull request #1070 at f818e40: Fix a NullReferenceException in TCS scripts - Pull request #1055 at 5c78967: Route Based TTrack Sounds - Pull request #1049 at 4dd8c4f: Re-organise document storage and access
18 parents 9ad4286 + ade0195 + f11a428 + 4629736 + d3ae4a2 + cc4d53c + 3b5cb90 + b96d6fa + 52410f9 + 62c89c1 + 1f5ba4c + 335f998 + d8d9709 + 254b6d4 + 3f153f0 + f818e40 + 5c78967 + 4dd8c4f commit d976fec

File tree

5 files changed

+38
-60
lines changed

5 files changed

+38
-60
lines changed

Source/Orts.Formats.Msts/TrackSectionsFile.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,6 @@ public SectionIdx(STFReader stf)
183183
}
184184
stf.SkipRestOfBlock();
185185
}
186-
public SectionIdx(TrackPath path)
187-
{
188-
X = 0;
189-
Y = 0;
190-
Z = 0;
191-
A = 0;
192-
NoSections = path.NoSections;
193-
TrackSections = path.TrackSections;
194-
}
195-
196186
public uint NoSections;
197187
public double X,Y,Z; // Offset
198188
public double A; // Angular offset

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4586,9 +4586,9 @@ public void RepositionRearTraveller()
45864586

45874587
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
45884588
// Also determine roll angle for superelevation by averaging both bogies
4589-
float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation);
4589+
float roll = traveller.GetVisualElevation();
45904590
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4591-
roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation)) / 2.0f;
4591+
roll = (roll + traveller.GetVisualElevation()) / 2.0f;
45924592

45934593
// Normalize across tile boundaries
45944594
x += 2048 * (tileX - traveller.TileX);
@@ -4739,9 +4739,9 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
47394739

47404740
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
47414741
// Outputs rotation angle for superelevation, used below
4742-
float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation);
4742+
float roll = traveller.GetVisualElevation();
47434743
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4744-
roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation)) / 2.0f;
4744+
roll = (roll + traveller.GetVisualElevation()) / 2.0f;
47454745

47464746
// Normalize across tile boundaries
47474747
x += 2048 * (tileX - traveller.TileX);
@@ -4820,9 +4820,9 @@ public void CalculatePositionOfEOT()
48204820

48214821
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
48224822
// Outputs rotation angle for superelevation, used below
4823-
float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation);
4823+
float roll = traveller.GetVisualElevation();
48244824
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4825-
roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation)) / 2.0f;
4825+
roll = (roll + traveller.GetVisualElevation()) / 2.0f;
48264826

48274827
// Normalize across tile boundaries
48284828
x += 2048 * (tileX - traveller.TileX);

Source/RunActivity/Viewer3D/DynamicTrack.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,9 +1503,6 @@ public virtual void CircArcGen()
15031503
}
15041504
break;
15051505
}
1506-
// Limit the number of sections to prevent overflowing the number of triangles
1507-
if (NumSections > 250)
1508-
NumSections = 250;
15091506
// Ensure an even number of sections
15101507
if (NumSections % 2 == 1)
15111508
NumSections++;

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -879,21 +879,16 @@ private void UpdateAnimation(RenderFrame frame, ElapsedTime elapsedTime)
879879

880880
#endif
881881

882-
// Bogie angle animation
882+
// truck angle animation
883883
Matrix inverseLocation = Matrix.Invert(Car.WorldPosition.XNAMatrix);
884884

885885
foreach (var p in Car.Parts)
886886
{
887887
if (p.iMatrix <= 0)
888888
continue;
889889

890+
// Determine orientation of bogie in absolute space
890891
Matrix m = Matrix.Identity;
891-
892-
// Bogie rotation calculation doesn't work on turntables
893-
// Assume bogies aren't rotated when on a turntable
894-
if (Car.Train?.ControlMode != Train.TRAIN_CONTROL.TURNTABLE)
895-
{
896-
// Determine orientation of bogie in absolute space
897892
Vector3 fwd = new Vector3(p.Dir[0], p.Dir[1], -p.Dir[2]);
898893
// Only do this calculation if the bogie position has been calculated
899894
if (!(fwd.X == 0 && fwd.Y == 0 && fwd.Z == 0))
@@ -910,7 +905,7 @@ private void UpdateAnimation(RenderFrame frame, ElapsedTime elapsedTime)
910905
// Convert absolute rotation into rotation relative to train car
911906
m = Matrix.CreateRotationZ(p.Roll) * m * inverseLocation;
912907
}
913-
}
908+
914909
// Insert correct translation (previous step likely introduced garbage data)
915910
m.Translation = TrainCarShape.SharedShape.Matrices[p.iMatrix].Translation;
916911

Source/RunActivity/Viewer3D/SuperElevation.cs

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,27 @@ public static bool DecomposeStaticSuperElevation(Viewer viewer, TrackObj trackOb
5959
// each subsection. The rotation component changes only in heading. The translation
6060
// component steps along the path to reflect the root of each subsection.
6161

62-
bool dontRender = false; // Should this shape be left as a static object?
63-
bool removePhys = false; // Should superelevation physics be removed from this object?
64-
SectionIdx[] SectionIdxs;
62+
TrackShape shape;
6563

66-
// Using the track object, determine the track sections
67-
// Most track sections can be recovered directly from a TrackShape object
68-
if (viewer.Simulator.TSectionDat.TrackShapes.TryGetValue(trackObj.SectionIdx, out TrackShape shape))
64+
try
6965
{
70-
if (shape.RoadShape)
71-
return false; // Roads don't use superelevation, no use in processing them.
66+
shape = viewer.Simulator.TSectionDat.TrackShapes.Get(trackObj.SectionIdx);
7267

73-
// Can't render superelevation on tunnel shapes
74-
dontRender = shape.TunnelShape;
75-
// Can't render superelevation and shouldn't have physics superelevation on junctions and crossovers
76-
dontRender |= removePhys = (shape.NumPaths > 1 && shape.ClearanceDistance != 0);
77-
SectionIdxs = shape.SectionIdxs;
78-
} // Some route-specific shapes (DynaTrax) won't be populated in the TrackShapes list, check the TrackPaths list
79-
else if (viewer.Simulator.TSectionDat.TSectionIdx.TrackPaths.TryGetValue(trackObj.SectionIdx, out TrackPath path))
68+
if (shape.RoadShape == true)
69+
return false; // Roads don't use superelevation, no use in processing them.
70+
}
71+
catch (Exception)
8072
{
81-
// Translate given data into a SectionIdx object that the rest of the method can interpret
82-
// Assumptions: Each piece of DynaTrax is a single section with origin 0, 0, 0 and 0 angle,
83-
// and the entire section of DynaTrax is defined by the track sections given in the track path
84-
SectionIdxs = new SectionIdx[1];
85-
SectionIdxs[0] = new SectionIdx(path);
73+
return false; // Won't be able to render with superelevation
8674
}
87-
else
88-
return false; // Can't find section info, won't be able to render with superelevation
8975

76+
SectionIdx[] SectionIdxs = shape.SectionIdxs;
77+
78+
// Can't render superelevation on tunnel shapes
79+
// NOTE: Even if we don't render superelevation, we still need to run through processing to remove superelevation from track sections
80+
bool dontRender = shape.TunnelShape;
81+
// Sometimes junctions get caught here, physics superelevation should be removed for those as well
82+
bool removePhys = false;
9083
// 0 = centered, positive = rotation axis moves to inside of curve, negative = moves to outside of curve
9184
float rollOffsetM = 0.0f;
9285

@@ -130,18 +123,27 @@ public static bool DecomposeStaticSuperElevation(Viewer viewer, TrackObj trackOb
130123
// Iterate through all subsections
131124
foreach (SectionIdx id in SectionIdxs)
132125
{
126+
// If section angle offset is not zero, that means we have a complicated track shape (eg: junction)
127+
// If any sections have identical starting conditions, that means we have a junction
128+
// These should not be rendered using superelevation
129+
if (!dontRender && id.A != 0.0f)
130+
dontRender = true;
131+
if (!dontRender && !removePhys
132+
&& SectionIdxs.Any(idx => idx != id && idx.X == id.X && idx.Y == id.Y && idx.Z == id.Z))
133+
{
134+
dontRender = true;
135+
removePhys = true;
136+
}
137+
133138
// The following vectors represent local positioning relative to root of original section:
134-
Vector3 offset = new Vector3((float)id.X, (float)id.Y, -(float)id.Z); // Offset from section origin for this series of sections
139+
Vector3 offset = new Vector3((float)id.X, (float)id.Y, (float)id.Z); // Offset from section origin for this series of sections
135140
Vector3 localV = Vector3.Zero; // Local position of subsection (in x-z plane)
136141
Vector3 heading = Vector3.Forward; // Local heading (unit vector)
137142

138143
WorldPosition worldMatrix = new WorldPosition(worldMatrixInput); // Copy origin location
139144

140145
worldMatrix.XNAMatrix.Translation = Vector3.Transform(offset, worldMatrix.XNAMatrix);
141146

142-
// If the section is rotated, apply that rotation now so we don't need to in the future
143-
worldMatrix.XNAMatrix = Matrix.CreateRotationY(MathHelper.ToRadians(-(float)id.A)) * worldMatrix.XNAMatrix;
144-
145147
WorldPosition nextRoot = new WorldPosition(worldMatrix); // Will become initial root
146148
Vector3 sectionOrigin = worldMatrix.XNAMatrix.Translation; // Original position for entire section
147149
worldMatrix.XNAMatrix.Translation = Vector3.Zero; // worldMatrix now rotation-only
@@ -221,17 +223,14 @@ public static void ClearJunctionSuperElevation(Viewer viewer, TrackObj trackObj,
221223
foreach (SectionIdx id in SectionIdxs)
222224
{
223225
// The following vectors represent local positioning relative to root of original section:
224-
Vector3 offset = new Vector3((float)id.X, (float)id.Y, -(float)id.Z); // Offset from section origin for this series of sections
226+
Vector3 offset = new Vector3((float)id.X, (float)id.Y, (float)id.Z); // Offset from section origin for this series of sections
225227
Vector3 localV = Vector3.Zero; // Local position of subsection (in x-z plane)
226228
Vector3 heading = Vector3.Forward; // Local heading (unit vector)
227229

228230
WorldPosition worldMatrix = new WorldPosition(worldMatrixInput); // Copy origin location
229231

230232
worldMatrix.XNAMatrix.Translation = Vector3.Transform(offset, worldMatrix.XNAMatrix);
231233

232-
// If the section is rotated, apply that rotation now so we don't need to in the future
233-
worldMatrix.XNAMatrix = Matrix.CreateRotationY(MathHelper.ToRadians(-(float)id.A)) * worldMatrix.XNAMatrix;
234-
235234
WorldPosition nextRoot = new WorldPosition(worldMatrix); // Will become initial root
236235
Vector3 sectionOrigin = worldMatrix.XNAMatrix.Translation; // Original position for entire section
237236
worldMatrix.XNAMatrix.Translation = Vector3.Zero; // worldMatrix now rotation-only
@@ -827,9 +826,6 @@ public override void LinearGen()
827826
// Very short length track, use minimum of two sections
828827
if (NumSections == 0)
829828
NumSections = 2;
830-
// Limit the number of sections to prevent overflowing the number of triangles
831-
else if (NumSections > 250)
832-
NumSections = 250;
833829
// Ensure an even number of sections
834830
if (NumSections % 2 == 1)
835831
NumSections++;

0 commit comments

Comments
 (0)