@@ -1861,18 +1861,8 @@ public virtual void InitializeMoving()
18611861 MSTSLocomotive lead = (MSTSLocomotive)Cars[LeadLocomotiveIndex];
18621862 if (lead is MSTSSteamLocomotive) MUReverserPercent = 25;
18631863
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();
18761866 // give it a bit more gas if it is uphill
18771867 if (lead.CurrentElevationPercent < -2.0) initialThrottlepercent = 40f;
18781868 // better block gas if it is downhill
@@ -4512,9 +4502,9 @@ public void RepositionRearTraveller()
45124502
45134503 // Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
45144504 // Also determine roll angle for superelevation by averaging both bogies
4515- float roll = traveller.GetVisualElevation();
4505+ float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation );
45164506 car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4517- roll = (roll + traveller.GetVisualElevation()) / 2.0f;
4507+ roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation )) / 2.0f;
45184508
45194509 // Normalize across tile boundaries
45204510 x += 2048 * (tileX - traveller.TileX);
@@ -4532,9 +4522,7 @@ public void RepositionRearTraveller()
45324522 car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller.X, traveller.Y, traveller.Z, x, y, z);
45334523
45344524 // 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();
45384526
45394527 // Apply superelevation to car
45404528 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)
46334621
46344622 // Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
46354623 // Outputs rotation angle for superelevation, used below
4636- float roll = traveller.GetVisualElevation();
4624+ float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation );
46374625 car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4638- roll = (roll + traveller.GetVisualElevation()) / 2.0f;
4626+ roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation )) / 2.0f;
46394627
46404628 // Normalize across tile boundaries
46414629 x += 2048 * (tileX - traveller.TileX);
@@ -4653,9 +4641,7 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
46534641 car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller.X, traveller.Y, traveller.Z, x, y, z);
46544642
46554643 // 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();
46594645
46604646 // Apply superelevation to car
46614647 car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
@@ -4714,9 +4700,9 @@ public void CalculatePositionOfEOT()
47144700
47154701 // Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
47164702 // Outputs rotation angle for superelevation, used below
4717- float roll = traveller.GetVisualElevation();
4703+ float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation );
47184704 car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4719- roll = (roll + traveller.GetVisualElevation()) / 2.0f;
4705+ roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation )) / 2.0f;
47204706
47214707 // Normalize across tile boundaries
47224708 x += 2048 * (tileX - traveller.TileX);
@@ -4734,9 +4720,7 @@ public void CalculatePositionOfEOT()
47344720 car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller.X, traveller.Y, traveller.Z, x, y, z);
47354721
47364722 // 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();
47404724
47414725 // Apply superelevation to car
47424726 car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
0 commit comments