@@ -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
@@ -4512,9 +4502,9 @@ public void RepositionRearTraveller()
4512
4502
4513
4503
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
4514
4504
// Also determine roll angle for superelevation by averaging both bogies
4515
- float roll = traveller.GetVisualElevation();
4505
+ float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation );
4516
4506
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4517
- roll = (roll + traveller.GetVisualElevation()) / 2.0f;
4507
+ roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation )) / 2.0f;
4518
4508
4519
4509
// Normalize across tile boundaries
4520
4510
x += 2048 * (tileX - traveller.TileX);
@@ -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;
@@ -4633,9 +4621,9 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
4633
4621
4634
4622
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
4635
4623
// Outputs rotation angle for superelevation, used below
4636
- float roll = traveller.GetVisualElevation();
4624
+ float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation );
4637
4625
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4638
- roll = (roll + traveller.GetVisualElevation()) / 2.0f;
4626
+ roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation )) / 2.0f;
4639
4627
4640
4628
// Normalize across tile boundaries
4641
4629
x += 2048 * (tileX - traveller.TileX);
@@ -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;
@@ -4714,9 +4700,9 @@ public void CalculatePositionOfEOT()
4714
4700
4715
4701
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
4716
4702
// Outputs rotation angle for superelevation, used below
4717
- float roll = traveller.GetVisualElevation();
4703
+ float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation );
4718
4704
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4719
- roll = (roll + traveller.GetVisualElevation()) / 2.0f;
4705
+ roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation )) / 2.0f;
4720
4706
4721
4707
// Normalize across tile boundaries
4722
4708
x += 2048 * (tileX - traveller.TileX);
@@ -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