Skip to content

Commit 0219baf

Browse files
committed
Automatic merge of T1.6-139-g6b62c2a7d and 14 pull requests
- Pull request #1082 at 8538170: Allow variable water level in glass gauge - Pull request #1156 at f46d5f2: Fix incorrectly disabled options in train operations window - Pull request #1091 at 492795a: Automatic speed control - Pull request #1122 at 73c47b4: Wagon Size and Centering Controls - Pull request #1124 at e241a0d: Built-in PBL2 brake controller - Pull request #1128 at d116396: Particle Emitter Overhaul - Pull request #1157 at 39cd994: Dynamic brake authorization by TCS - Pull request #1159 at 48c9a63: Skip OR warnings about TSRE-specific token Ruler - Pull request #1163 at 2f9e292: Fix: Crash when using Camera 8 and F9. - Pull request #1164 at 1ad9889: Fix: F9 crashes with a front coupled single steam locomotive by Csantucci. - Pull request #1166 at 51e7f7a: Simplify loading of internal and game textures - Pull request #1167 at 115325f: Fix: RunActivity slow to terminate because of long sleep in Host Process - Pull request #1168 at 6e2942f: Fix exception when exiting with MapForm or SoundDebugForm open. - Pull request #1169 at 8c1d787: Better Handling of Wagons with Invalid Bogie Configuration
16 parents 3aa5d5f + 6b62c2a + 8538170 + f46d5f2 + 492795a + 73c47b4 + e241a0d + d116396 + 39cd994 + 48c9a63 + 2f9e292 + 1ad9889 + 51e7f7a + 115325f + 6e2942f + 8c1d787 commit 0219baf

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,8 @@ public virtual void Copy(MSTSWagon copy)
18561856
CarWidthM = copy.CarWidthM;
18571857
CarHeightM = copy.CarHeightM;
18581858
CarLengthM = copy.CarLengthM;
1859+
FrontArticulation = copy.FrontArticulation;
1860+
RearArticulation = copy.RearArticulation;
18591861
TrackGaugeM = copy.TrackGaugeM;
18601862
CentreOfGravityM = copy.CentreOfGravityM;
18611863
MaxUnbalancedSuperElevationM = copy.MaxUnbalancedSuperElevationM;

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,7 +2931,7 @@ public void SetUpWheels()
29312931
// and the rest left out.
29322932

29332933
// Force articulation if stock is configured as such
2934-
// Otherwise, use default behavior which gives articulation if there are no axles forward/reareward on the model,
2934+
// Otherwise, use default behavior which gives articulation if there are no axles forward/rearward on the model,
29352935
// disables articulation on engines, and only allows articulation with 3 or fewer axles, but not 1 axle
29362936
bool articulatedFront = (FrontArticulation == 1 ||
29372937
(FrontArticulation == -1 && !WheelAxles.Any(a => a.OffsetM.Z < 0) && WagonType != WagonTypes.Engine && WheelAxles.Count != 1 && WheelAxles.Count <= 3));
@@ -3039,8 +3039,17 @@ public void ComputePosition(Traveller traveler, bool backToFront, float elapsedT
30393039
if (p.SumWgt > 1.5f)
30403040
p0.AddPartLocation(1, p);
30413041
}
3042+
if (Parts.Count == 2)
3043+
{
3044+
// Train car lacks sufficient parts to locate using linear regression
3045+
p0.Dir = Parts[1].Dir;
3046+
p0.Pos = Parts[1].Pos;
3047+
}
3048+
else
3049+
{
30423050
// Determine facing direction and position of train car
30433051
p0.FindCenterLine();
3052+
}
30443053
Vector3 fwd = new Vector3(p0.Dir[0], p0.Dir[1], -p0.Dir[2]);
30453054
// Check if null (0-length) vector
30463055
if (!(fwd.X == 0 && fwd.Y == 0 && fwd.Z == 0))
@@ -3758,7 +3767,7 @@ public class TrainCarPart
37583767
public double[] SumPos = new double[3]; // Sum of component locations [x, y, z]
37593768
public double[] SumPosZOffset = new double[3]; // Sum of component locations [x, y, z] times Z-offsets
37603769
public float[] Pos = new float[3]; // Position [x, y, z] of this part, calculated with y-intercept of linear regression
3761-
public float[] Dir = new float[3]; // Oritentation [x, y, z] of this part, calculated with slope of linear regression
3770+
public float[] Dir = new float[3]; // Orientation [x, y, z] of this part, calculated with slope of linear regression
37623771
public float SumRoll; // Sum of all roll angles of components
37633772
public float Roll; // Roll angle of this part
37643773
public bool Bogie; // True if this is a bogie
@@ -3823,7 +3832,7 @@ public void FindCenterLine()
38233832
// 2D Least regression between the offsets (along longitudinal axis of rail vehicle)
38243833
// and actual positions in 3D space, repeated 3 times for each dimension in 3D.
38253834

3826-
// Follows format of y = M * x + B where x is the foward/backward position along the train car axis
3835+
// Follows format of y = M * x + B where x is the forward/backward position along the train car axis
38273836
// and y is the actual (x, y, or z) position in 3D space. We need to determine vectors B (the 3D
38283837
// position of this part) and M (the 3D orientation of this part) using the offsets and positions added previously.
38293838

@@ -3838,18 +3847,15 @@ public void FindCenterLine()
38383847
Dir[i] = (float)((SumWgt * SumPosZOffset[i] - SumZOffset * SumPos[i]) / denominator);
38393848
// The position (B) is defined as 'B = [sum(y) - M * sum(x)] / N', where N is the total
38403849
// weight, x is the offset, y is the 3D position, and M is the direction value from earlier.
3841-
// This uses an equivalent form that doesn't use the result of the above calulcation to avoid
3850+
// This uses an equivalent form that doesn't use the result of the above calculation to avoid
38423851
// precision errors from the value being converted to a float.
38433852
Pos[i] = (float)((SumZOffsetSq * SumPos[i] - SumZOffset * SumPosZOffset[i]) / denominator);
38443853
}
38453854
}
3846-
else
3855+
else // Improperly defined wagon, fallback to basic calculation
38473856
{
38483857
for (int i = 0; i < 3; i++)
3849-
{
38503858
Pos[i] = (float)(SumPos[i] / SumWgt);
3851-
Dir[i] = 0;
3852-
}
38533859
}
38543860

38553861
Roll = SumRoll / (float)SumWgt;

0 commit comments

Comments
 (0)