Skip to content

Commit 336a700

Browse files
authored
Merge pull request #799 from twpol/feature/one-true-wind
Consolidated wind simulation
2 parents 14405bf + dfc715e commit 336a700

File tree

21 files changed

+804
-604
lines changed

21 files changed

+804
-604
lines changed

Source/ORTS.Common/Conversions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ public static class FormatStrings
576576
public static string kN = Catalog.GetString("kN");
577577
public static string lbf = Catalog.GetString("lbf");
578578
public static string klbf = Catalog.GetString("klbf");
579+
public static string deg = Catalog.GetString("°");
579580

580581
/// <summary>
581582
/// Formatted unlocalized speed string, used in reports and logs.
@@ -838,6 +839,11 @@ public static string FormatAirFlow(float flowM3pS, bool isMetric)
838839
return String.Format(CultureInfo.CurrentCulture, "{0:F0} {1}", flow, isMetric ? lps : cfm);
839840
}
840841

842+
public static string FormatAngleDeg(float angleDeg)
843+
{
844+
return String.Format(CultureInfo.CurrentCulture, "{0:F0} {1}", angleDeg, deg);
845+
}
846+
841847
/// <summary>
842848
/// Converts duration in floating-point seconds to whole hours, minutes and seconds (rounded down).
843849
/// </summary>

Source/ORTS.Settings/UserSettings.cs

-6
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,6 @@ public enum DirectXFeature
313313
public bool AdhesionProportionalToWeather { get; set; }
314314
[Default(false)]
315315
public bool NoForcedRedAtStationStops { get; set; }
316-
[Default(100)]
317-
public int PrecipitationBoxHeight { get; set; }
318-
[Default(500)]
319-
public int PrecipitationBoxWidth { get; set; }
320-
[Default(500)]
321-
public int PrecipitationBoxLength { get; set; }
322316
[Default(false)]
323317
public bool CorrectQuestionableBrakingParams { get; set; }
324318
[Default(false)]

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ public void AIUpdate(float elapsedClockSeconds, double clockTime, bool preUpdate
710710

711711
if (Cars[0] is MSTSLocomotive leadingLoco)
712712
{
713-
var isRainingOrSnowing = Simulator.Weather.PricipitationIntensityPPSPM2 > 0;
713+
var isRainingOrSnowing = Simulator.Weather.PrecipitationIntensityPPSPM2 > 0;
714714
if (leadingLoco.Wiper && !isRainingOrSnowing)
715715
leadingLoco.SignalEvent(Event.WiperOff);
716716
else if (!leadingLoco.Wiper && isRainingOrSnowing)

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

+30-31
Original file line numberDiff line numberDiff line change
@@ -2205,42 +2205,41 @@ public virtual void physicsUpdate(float elapsedClockSeconds)
22052205
public void UpdateWindComponents()
22062206
{
22072207
// Gets wind direction and speed, and determines HUD display values for the train as a whole.
2208-
//These will be representative of the train whilst it is on a straight track, but each wagon will vary when going around a curve.
2208+
// These will be representative of the train whilst it is on a straight track, but each wagon will vary when going around a curve.
22092209
// Note both train and wind direction will be positive between 0 (north) and 180 (south) through east, and negative between 0 (north) and 180 (south) through west
22102210
// Wind and train direction to be converted to an angle between 0 and 360 deg.
2211-
// Calculate Wind speed and direction, and train direction
2212-
// Update the value of the Wind Speed and Direction for the train
2213-
PhysicsWindDirectionDeg = MathHelper.ToDegrees(Simulator.Weather.WindDirection);
2214-
PhysicsWindSpeedMpS = Simulator.Weather.WindSpeed;
2215-
float TrainSpeedMpS = Math.Abs(SpeedMpS);
2216-
2217-
// If a westerly direction (ie -ve) convert to an angle between 0 and 360
2218-
if (PhysicsWindDirectionDeg < 0)
2219-
PhysicsWindDirectionDeg += 360;
2220-
2221-
if (PhysicsTrainLocoDirectionDeg < 0)
2222-
PhysicsTrainLocoDirectionDeg += 360;
2223-
2224-
// calculate angle between train and eind direction
2225-
if (PhysicsWindDirectionDeg > PhysicsTrainLocoDirectionDeg)
2226-
ResultantWindComponentDeg = PhysicsWindDirectionDeg - PhysicsTrainLocoDirectionDeg;
2227-
else if (PhysicsTrainLocoDirectionDeg > PhysicsWindDirectionDeg)
2228-
ResultantWindComponentDeg = PhysicsTrainLocoDirectionDeg - PhysicsWindDirectionDeg;
2229-
else
2230-
ResultantWindComponentDeg = 0.0f;
2231-
2232-
// Correct wind direction if it is greater then 360 deg, then correct to a value less then 360
2233-
if (Math.Abs(ResultantWindComponentDeg) > 360)
2234-
ResultantWindComponentDeg = ResultantWindComponentDeg - 360.0f;
2211+
// Calculate Wind speed and direction, and train direction
2212+
// Update the value of the Wind Speed and Direction for the train
2213+
PhysicsWindDirectionDeg = MathHelper.ToDegrees(Simulator.Weather.WindInstantaneousDirectionRad);
2214+
PhysicsWindSpeedMpS = Simulator.Weather.WindInstantaneousSpeedMpS;
2215+
var speedMpS = Math.Abs(SpeedMpS);
2216+
2217+
// If a westerly direction (ie -ve) convert to an angle between 0 and 360
2218+
if (PhysicsWindDirectionDeg < 0)
2219+
PhysicsWindDirectionDeg += 360;
2220+
2221+
if (PhysicsTrainLocoDirectionDeg < 0)
2222+
PhysicsTrainLocoDirectionDeg += 360;
2223+
2224+
// Calculate angle between train and wind direction
2225+
if (PhysicsWindDirectionDeg > PhysicsTrainLocoDirectionDeg)
2226+
ResultantWindComponentDeg = PhysicsWindDirectionDeg - PhysicsTrainLocoDirectionDeg;
2227+
else if (PhysicsTrainLocoDirectionDeg > PhysicsWindDirectionDeg)
2228+
ResultantWindComponentDeg = PhysicsTrainLocoDirectionDeg - PhysicsWindDirectionDeg;
2229+
else
2230+
ResultantWindComponentDeg = 0.0f;
22352231

2236-
// Wind angle should be kept between 0 and 180 the formulas do not cope with angles > 180. If angle > 180, denotes wind of "other" side of train
2237-
if (ResultantWindComponentDeg > 180)
2238-
ResultantWindComponentDeg = 360 - ResultantWindComponentDeg;
2232+
// Correct wind direction if it is greater then 360 deg, then correct to a value less then 360
2233+
if (Math.Abs(ResultantWindComponentDeg) > 360)
2234+
ResultantWindComponentDeg = ResultantWindComponentDeg - 360.0f;
22392235

2240-
float WindAngleRad = MathHelper.ToRadians(ResultantWindComponentDeg);
2236+
// Wind angle should be kept between 0 and 180 the formulas do not cope with angles > 180. If angle > 180, denotes wind of "other" side of train
2237+
if (ResultantWindComponentDeg > 180)
2238+
ResultantWindComponentDeg = 360 - ResultantWindComponentDeg;
22412239

2242-
WindResultantSpeedMpS = (float)Math.Sqrt(TrainSpeedMpS * TrainSpeedMpS + PhysicsWindSpeedMpS * PhysicsWindSpeedMpS + 2.0f * TrainSpeedMpS * PhysicsWindSpeedMpS * (float)Math.Cos(WindAngleRad));
2243-
}
2240+
var windAngleRad = MathHelper.ToRadians(ResultantWindComponentDeg);
2241+
WindResultantSpeedMpS = (float)Math.Sqrt(speedMpS * speedMpS + PhysicsWindSpeedMpS * PhysicsWindSpeedMpS + 2.0f * speedMpS * PhysicsWindSpeedMpS * (float)Math.Cos(windAngleRad));
2242+
}
22442243

22452244

22462245
//================================================================================================//

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3263,7 +3263,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
32633263
{
32643264
var fogBaseFrictionCoefficientFactor = 1.0f;
32653265
var pricBaseFrictionCoefficientFactor = 1.0f;
3266-
float pric = Simulator.Weather.PricipitationIntensityPPSPM2 * 1000;
3266+
float pric = Simulator.Weather.PrecipitationIntensityPPSPM2 * 1000;
32673267
// precipitation will calculate a base coefficient value between 60% (light rain) and 90% (heavy rain) - this will be a factor that is used to adjust the base value
32683268
// assume linear value between upper and lower precipitation values. Limits are set in the weather module, ie Rain = 0.01ppm (10) and Snow = 0.005ppm (5)
32693269
float precGrad = (0.2f - 0) / (10f - 5f);
@@ -3279,7 +3279,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
32793279
}
32803280

32813281
// Adjust adhesion for impact of fog - default = 20000m = 20km
3282-
float fog = Simulator.Weather.FogDistance;
3282+
float fog = Simulator.Weather.VisibilityM;
32833283
if (fog < 20000) // as fog thickens then decrease adhesion
32843284
{
32853285
fogBaseFrictionCoefficientFactor = Math.Min((fog * 2.75e-4f + 0.6f), 1.0f); // If fog is less then 2km then it will impact friction, decrease adhesion to 60% (same as light rain transition)

0 commit comments

Comments
 (0)