@@ -1861,18 +1861,8 @@ public virtual void InitializeMoving()
1861
1861
MSTSLocomotive lead = (MSTSLocomotive)Cars[LeadLocomotiveIndex];
1862
1862
if (lead is MSTSSteamLocomotive) MUReverserPercent = 25;
1863
1863
1864
- // Percent slope = rise / run -> the Y position of the forward vector gives us the 'rise'
1865
- // Derive the 'run' by assuming a hypotenuse length of 1, so run = sqrt(1 - rise^2)
1866
- float rise = lead.WorldPosition.XNAMatrix.M32;
1867
- lead.CurrentElevationPercent = 100f * (rise / (float)Math.Sqrt(1 - rise * rise));
1868
-
1869
- //TODO: next if block has been inserted to flip trainset physics in order to get viewing direction coincident with loco direction when using rear cab.
1870
- // To achieve the same result with other means, without flipping trainset physics, the block should be deleted
1871
- //
1872
- if (lead.IsDriveable && (lead as MSTSLocomotive).UsingRearCab)
1873
- {
1874
- lead.CurrentElevationPercent = -lead.CurrentElevationPercent;
1875
- }
1864
+ // Force calculate gradient at the lead locomotive
1865
+ lead.UpdateGravity();
1876
1866
// give it a bit more gas if it is uphill
1877
1867
if (lead.CurrentElevationPercent < -2.0) initialThrottlepercent = 40f;
1878
1868
// better block gas if it is downhill
@@ -4532,9 +4522,7 @@ public void RepositionRearTraveller()
4532
4522
car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller.X, traveller.Y, traveller.Z, x, y, z);
4533
4523
4534
4524
// Update gravity force when position is updated, but before any secondary motion is added
4535
- Vector3 fwd = car.WorldPosition.XNAMatrix.Backward;
4536
- car.GravityForceN = car.MassKG * TrainCar.GravitationalAccelerationMpS2 * fwd.Y;
4537
- car.CurrentElevationPercent = 100f * (fwd.Y / (float)Math.Sqrt(1 - fwd.Y * fwd.Y));
4525
+ car.UpdateGravity();
4538
4526
4539
4527
// Apply superelevation to car
4540
4528
car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
@@ -4653,9 +4641,7 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
4653
4641
car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller.X, traveller.Y, traveller.Z, x, y, z);
4654
4642
4655
4643
// Update gravity force when position is updated, but before any secondary motion is added
4656
- Vector3 fwd = car.WorldPosition.XNAMatrix.Backward;
4657
- car.GravityForceN = car.MassKG * TrainCar.GravitationalAccelerationMpS2 * fwd.Y;
4658
- car.CurrentElevationPercent = 100f * (fwd.Y / (float)Math.Sqrt(1 - fwd.Y * fwd.Y));
4644
+ car.UpdateGravity();
4659
4645
4660
4646
// Apply superelevation to car
4661
4647
car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
@@ -4734,9 +4720,7 @@ public void CalculatePositionOfEOT()
4734
4720
car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller.X, traveller.Y, traveller.Z, x, y, z);
4735
4721
4736
4722
// Update gravity force when position is updated, but before any secondary motion is added
4737
- Vector3 fwd = car.WorldPosition.XNAMatrix.Backward;
4738
- car.GravityForceN = car.MassKG * TrainCar.GravitationalAccelerationMpS2 * fwd.Y;
4739
- car.CurrentElevationPercent = 100f * (fwd.Y / (float)Math.Sqrt(1 - fwd.Y * fwd.Y));
4723
+ car.UpdateGravity();
4740
4724
4741
4725
// Apply superelevation to car
4742
4726
car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
0 commit comments