Skip to content

Commit 150b1ab

Browse files
committed
Adjustment to air hose display
1 parent 34d0991 commit 150b1ab

File tree

2 files changed

+119
-21
lines changed

2 files changed

+119
-21
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ public static Interpolator SteamHeatBoilerFuelUsageGalukpH()
248248
public float RearAirHoseDisconnectedAnimWidthM;
249249
public float RearAirHoseDisconnectedAnimHeightM;
250250

251+
public float FrontAirHoseHeightAdjustmentM;
252+
public float RearAirHoseHeightAdjustmentM;
253+
public float FrontAirHoseAngleAdjustmentRad;
254+
public float RearAirHoseAngleAdjustmentRad;
255+
251256
// Used to calculate Carriage Steam Heat Loss
252257
public const float BogieHeightM = 1.06f; // Height reduced by 1.06m to allow for bogies, etc
253258
public const float CarCouplingPipeM = 1.2f; // Allow for connection between cars (assume 2' each end) - no heat is contributed to carriages.
@@ -1270,6 +1275,68 @@ public void UpdateTrainDerailmentRisk()
12701275
CarAhead.WagonRearCouplerAngleRad = 0;
12711276
}
12721277
}
1278+
1279+
// Calculate airhose angles and height
1280+
var airhoselengthM = 1.0f; // 2' = 600mm - Note if air hose length is less then coupler distance then NaN occurs
1281+
var rearairhoseheightadjustmentreferenceM = (float)Math.Sqrt((float)Math.Pow(airhoselengthM, 2) - (float)Math.Pow(CouplerDistanceThisCarM, 2));
1282+
var frontairhoseheightadjustmentreferenceM = (float)Math.Sqrt((float)Math.Pow(airhoselengthM, 2) - (float)Math.Pow(CouplerDistanceBehindCarM, 2));
1283+
1284+
RearAirHoseHeightAdjustmentM = (float)Math.Sqrt( (float)Math.Pow(airhoselengthM, 2) - (float)Math.Pow((CouplerDistanceThisCarM + CouplerSlackM / 2.0f), 2));
1285+
CarBehind.FrontAirHoseHeightAdjustmentM = (float)Math.Sqrt((float)Math.Pow(airhoselengthM, 2) - (float)Math.Pow((CouplerDistanceBehindCarM + CouplerSlackM / 2.0f), 2));
1286+
// Trace.TraceInformation("Rear AirHose Heights - CarID {0} R {1} length {2} CouplerDistance {3} Slack {4}", CarID, RearAirHoseHeightAdjustmentM, airhoselengthM, CouplerDistanceThisCarM, CouplerSlackM / 2.0f);
1287+
1288+
// Trace.TraceInformation("Front AirHose Heights - CarID {0} F {1} length {2} CouplerDistance {3} Slack {4}", CarID, CarBehind.FrontAirHoseHeightAdjustmentM, airhoselengthM, CouplerDistanceBehindCarM, CouplerSlackM / 2.0f);
1289+
1290+
// refererence adjustment heights to rest position
1291+
if (RearAirHoseHeightAdjustmentM >= rearairhoseheightadjustmentreferenceM)
1292+
{
1293+
RearAirHoseHeightAdjustmentM -= rearairhoseheightadjustmentreferenceM;
1294+
}
1295+
else
1296+
{
1297+
RearAirHoseHeightAdjustmentM = rearairhoseheightadjustmentreferenceM - RearAirHoseHeightAdjustmentM;
1298+
}
1299+
1300+
if (CarBehind.FrontAirHoseHeightAdjustmentM >= frontairhoseheightadjustmentreferenceM)
1301+
{
1302+
CarBehind.FrontAirHoseHeightAdjustmentM -= frontairhoseheightadjustmentreferenceM;
1303+
}
1304+
else
1305+
{
1306+
CarBehind.FrontAirHoseHeightAdjustmentM = frontairhoseheightadjustmentreferenceM - CarBehind.FrontAirHoseHeightAdjustmentM;
1307+
}
1308+
1309+
var rearairhoseangleadjustmentreferenceRad = (float)Math.Cos(CouplerDistanceThisCarM / airhoselengthM);
1310+
var frontairhoseangleadjustmentreferenceRad = (float)Math.Cos(CouplerDistanceBehindCarM / airhoselengthM);
1311+
1312+
RearAirHoseAngleAdjustmentRad = (float)Math.Cos((CouplerDistanceThisCarM + CouplerSlackM / 2.0f)/ airhoselengthM);
1313+
CarBehind.FrontAirHoseAngleAdjustmentRad = (float)Math.Cos((CouplerDistanceBehindCarM + CouplerSlackM / 2.0f) / airhoselengthM);
1314+
1315+
// Trace.TraceInformation("Angle Adjustment Rear - CarID {0} Adj {1} CouplerDist {2} Slack {3} Length {4} Ref {5}", CarID, RearAirHoseAngleAdjustmentRad, CouplerDistanceThisCarM, CouplerSlackM / 2.0f, airhoselengthM, rearairhoseangleadjustmentreferenceRad);
1316+
1317+
// Trace.TraceInformation("Angle Adjustment Front - CarID {0} Adj {1} CouplerDist {2} Slack {3} Length {4} Ref {5}", CarID, CarBehind.FrontAirHoseAngleAdjustmentRad, CouplerDistanceBehindCarM, CouplerSlackM / 2.0f, airhoselengthM, frontairhoseangleadjustmentreferenceRad);
1318+
1319+
// refererence adjustment angles to rest position
1320+
if (RearAirHoseAngleAdjustmentRad >= rearairhoseangleadjustmentreferenceRad)
1321+
{
1322+
RearAirHoseAngleAdjustmentRad -= rearairhoseangleadjustmentreferenceRad;
1323+
}
1324+
else
1325+
{
1326+
RearAirHoseAngleAdjustmentRad = rearairhoseangleadjustmentreferenceRad - RearAirHoseAngleAdjustmentRad;
1327+
}
1328+
1329+
if (CarBehind.FrontAirHoseAngleAdjustmentRad >= frontairhoseangleadjustmentreferenceRad)
1330+
{
1331+
CarBehind.FrontAirHoseAngleAdjustmentRad -= frontairhoseangleadjustmentreferenceRad;
1332+
}
1333+
else
1334+
{
1335+
CarBehind.FrontAirHoseAngleAdjustmentRad = frontairhoseangleadjustmentreferenceRad - CarBehind.FrontAirHoseAngleAdjustmentRad;
1336+
}
1337+
1338+
// Trace.TraceInformation("CarID {0} FrontAdj {1} RearAdj {2}", CarID, CarBehind.FrontAirHoseAngleAdjustmentRad, RearAirHoseAngleAdjustmentRad);
1339+
12731340
}
12741341

12751342
// Train will derail if lateral forces on the train exceed the vertical forces holding the train on the railway track.

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,22 +1030,22 @@ private void UpdateCouplers(RenderFrame frame, ElapsedTime elapsedTime)
10301030
// Display front airhose in sim if open coupler shape is configured, otherwise skip to next section, and just display closed (default) coupler if configured
10311031
if (FrontAirHoseShape != null && !(Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab))
10321032
{
1033-
// Get the movement that would be needed to locate the coupler on the car if they were pointing in the default direction.
1034-
var displacement = new Vector3
1035-
{
1036-
X = Car.FrontAirHoseAnimWidthM,
1037-
Y = Car.FrontAirHoseAnimHeightM,
1038-
Z = (Car.FrontAirHoseAnimLengthM + (Car.CarLengthM / 2.0f)) // Reversed as this is the rear coupler of the wagon
1039-
};
10401033

10411034
if (Car.CarAhead != null) // Display animated coupler if there is a car behind this car
10421035
{
1036+
// Get the movement that would be needed to locate the air hose on the car if they were pointing in the default direction.
1037+
var displacement = new Vector3
1038+
{
1039+
X = Car.FrontAirHoseAnimWidthM,
1040+
Y = Car.FrontAirHoseAnimHeightM + Car.FrontAirHoseHeightAdjustmentM,
1041+
Z = (Car.FrontCouplerAnimLengthM + (Car.CarLengthM / 2.0f) + Car.FrontCouplerSlackM)
1042+
};
1043+
10431044
var quaternion = PositionCoupler(Car, FrontAirHoseShape, displacement);
10441045

10451046
var quaternionCar = new Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
10461047

1047-
var maximumCouplerExtension = Me.FromIn(3.0f);
1048-
var AirHoseAngleRadians = (Car.CouplerSlackM / maximumCouplerExtension) * 0.174533f;
1048+
var AirHoseAngleRadians = Car.FrontAirHoseAngleAdjustmentRad;
10491049

10501050
AlignCouplerWithCar(Car, FrontAirHoseShape);
10511051

@@ -1057,6 +1057,14 @@ private void UpdateCouplers(RenderFrame frame, ElapsedTime elapsedTime)
10571057
}
10581058
else if (FrontAirHoseDisconnectedShape != null && Car.RearCouplerOpenFitted && Car.RearCouplerOpen) // Display open coupler if no car is behind car, and an open coupler shape is present
10591059
{
1060+
// Get the movement that would be needed to locate the air hose on the car if they were pointing in the default direction.
1061+
var displacement = new Vector3
1062+
{
1063+
X = Car.FrontAirHoseAnimWidthM,
1064+
Y = Car.FrontAirHoseAnimHeightM,
1065+
Z = (Car.FrontCouplerAnimLengthM + (Car.CarLengthM / 2.0f) + Car.FrontCouplerSlackM)
1066+
};
1067+
10601068
var quaternion = PositionCoupler(Car, FrontAirHoseDisconnectedShape, displacement);
10611069

10621070
AlignCouplerWithCar(Car, FrontAirHoseDisconnectedShape);
@@ -1066,6 +1074,13 @@ private void UpdateCouplers(RenderFrame frame, ElapsedTime elapsedTime)
10661074
}
10671075
else //Display closed static coupler by default if other conditions not met
10681076
{
1077+
// Get the movement that would be needed to locate the air hose on the car if they were pointing in the default direction.
1078+
var displacement = new Vector3
1079+
{
1080+
X = Car.FrontAirHoseAnimWidthM,
1081+
Y = Car.FrontAirHoseAnimHeightM,
1082+
Z = (Car.FrontCouplerAnimLengthM + (Car.CarLengthM / 2.0f) + Car.FrontCouplerSlackM)
1083+
};
10691084
var quaternion = PositionCoupler(Car, FrontAirHoseShape, displacement);
10701085

10711086
AlignCouplerWithCar(Car, FrontAirHoseShape);
@@ -1079,22 +1094,22 @@ private void UpdateCouplers(RenderFrame frame, ElapsedTime elapsedTime)
10791094
// Display rear airhose in sim if open coupler shape is configured, otherwise skip to next section, and just display closed (default) coupler if configured
10801095
if (RearAirHoseShape != null && !(Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab))
10811096
{
1082-
// Get the movement that would be needed to locate the coupler on the car if they were pointing in the default direction.
1083-
var displacement = new Vector3
1084-
{
1085-
X = Car.RearAirHoseAnimWidthM,
1086-
Y = Car.RearAirHoseAnimHeightM,
1087-
Z = -(Car.RearAirHoseAnimLengthM + (Car.CarLengthM / 2.0f)) // Reversed as this is the rear coupler of the wagon
1088-
};
10891097

1090-
if (Car.CarBehind != null) // Display animated coupler if there is a car behind this car
1098+
if (Car.CarBehind != null) // Display animated air hose if there is a car behind this car
10911099
{
1100+
// Get the movement that would be needed to locate the air hose on the car if they were pointing in the default direction.
1101+
var displacement = new Vector3
1102+
{
1103+
X = Car.RearAirHoseAnimWidthM,
1104+
Y = Car.RearAirHoseAnimHeightM + Car.RearAirHoseHeightAdjustmentM,
1105+
Z = -(Car.RearCouplerAnimLengthM + (Car.CarLengthM / 2.0f) + Car.RearCouplerSlackM) // Reversed as this is the rear coupler of the wagon
1106+
};
1107+
10921108
var quaternion = PositionCoupler(Car, RearAirHoseShape, displacement);
10931109

10941110
var quaternionCar = new Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
10951111

1096-
var maximumCouplerExtension = Me.FromIn(3.0f);
1097-
var AirHoseAngleRadians = -(Car.CouplerSlackM / maximumCouplerExtension) * 0.174533f;
1112+
var AirHoseAngleRadians = -Car.RearAirHoseAngleAdjustmentRad;
10981113

10991114
AlignCouplerWithCar(Car, RearAirHoseShape);
11001115

@@ -1104,17 +1119,33 @@ private void UpdateCouplers(RenderFrame frame, ElapsedTime elapsedTime)
11041119
RearAirHoseShape.PrepareFrame(frame, elapsedTime);
11051120

11061121
}
1107-
else if (RearAirHoseDisconnectedShape != null && Car.RearCouplerOpenFitted && Car.RearCouplerOpen) // Display open coupler if no car is behind car, and an open coupler shape is present
1122+
else if (RearAirHoseDisconnectedShape != null && Car.RearCouplerOpenFitted && Car.RearCouplerOpen) // Display single air hose if no car is behind car, and an open air hose shape is present
11081123
{
1124+
// Get the movement that would be needed to locate the air hose on the car if they were pointing in the default direction.
1125+
var displacement = new Vector3
1126+
{
1127+
X = Car.RearAirHoseAnimWidthM,
1128+
Y = Car.RearAirHoseAnimHeightM,
1129+
Z = -(Car.RearCouplerAnimLengthM + (Car.CarLengthM / 2.0f) + Car.RearCouplerSlackM) // Reversed as this is the rear coupler of the wagon
1130+
};
1131+
11091132
var quaternion = PositionCoupler(Car, RearAirHoseDisconnectedShape, displacement);
11101133

11111134
AlignCouplerWithCar(Car, RearAirHoseDisconnectedShape);
11121135

11131136
// Display Animation Shape
11141137
RearAirHoseDisconnectedShape.PrepareFrame(frame, elapsedTime);
11151138
}
1116-
else //Display closed static coupler by default if other conditions not met
1139+
else //Display closed static air hose by default if other conditions not met
11171140
{
1141+
// Get the movement that would be needed to locate the air hose on the car if they were pointing in the default direction.
1142+
var displacement = new Vector3
1143+
{
1144+
X = Car.RearAirHoseAnimWidthM,
1145+
Y = Car.RearAirHoseAnimHeightM,
1146+
Z = -(Car.RearCouplerAnimLengthM + (Car.CarLengthM / 2.0f) + Car.RearCouplerSlackM) // Reversed as this is the rear coupler of the wagon
1147+
};
1148+
11181149
var quaternion = PositionCoupler(Car, RearAirHoseShape, displacement);
11191150

11201151
AlignCouplerWithCar(Car, RearAirHoseShape);

0 commit comments

Comments
 (0)