Skip to content

Commit e9a7e75

Browse files
committed
Correct an issue with coupler not displaying after a non animated coupler car.
1 parent b35dcfa commit e9a7e75

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -938,17 +938,21 @@ private void UpdateCouplers(RenderFrame frame, ElapsedTime elapsedTime)
938938

939939
AdjustCouplerAngle(Car, FrontCouplerShape, quaternionCar, CouplerAngleRadians);
940940

941-
// Next section tests front coupler against rear coupler on previous car. If they are not located at the same position, then location is set the same as previous car.
942-
// For some reason flipped cars have a small location error, and hence couplers do not align.
943-
var absXc = Math.Abs(FrontCouplerShape.Location.Location.X - Car.CarAhead.RearCouplerLocation.X);
944-
var absYc = Math.Abs(FrontCouplerShape.Location.Location.Y - Car.CarAhead.RearCouplerLocation.Y);
945-
var absZc = Math.Abs(FrontCouplerShape.Location.Location.Z - Car.CarAhead.RearCouplerLocation.Z);
946-
947-
if ((absXc > 0.005 || absYc > 0.005 || absZc > 0.005))
941+
// If the car ahead does not have an animated coupler then location values will be zero for car ahaead, and no coupler will display. Hence do not correct coupler location
942+
if (Car.CarAhead.RearCouplerLocation.X != 0 && Car.CarAhead.RearCouplerLocation.Y != 0 && Car.CarAhead.RearCouplerLocation.Z != 0)
948943
{
949-
FrontCouplerShape.Location.Location = Car.CarAhead.RearCouplerLocation; // Set coupler to same location as previous car coupler
950-
FrontCouplerShape.Location.TileX = Car.CarAhead.RearCouplerLocationTileX;
951-
FrontCouplerShape.Location.TileZ = Car.CarAhead.RearCouplerLocationTileZ;
944+
// Next section tests front coupler against rear coupler on previous car. If they are not located at the same position, then location is set the same as previous car.
945+
// For some reason flipped cars have a small location error, and hence couplers do not align.
946+
var absXc = Math.Abs(FrontCouplerShape.Location.Location.X - Car.CarAhead.RearCouplerLocation.X);
947+
var absYc = Math.Abs(FrontCouplerShape.Location.Location.Y - Car.CarAhead.RearCouplerLocation.Y);
948+
var absZc = Math.Abs(FrontCouplerShape.Location.Location.Z - Car.CarAhead.RearCouplerLocation.Z);
949+
950+
if ((absXc > 0.005 || absYc > 0.005 || absZc > 0.005))
951+
{
952+
FrontCouplerShape.Location.Location = Car.CarAhead.RearCouplerLocation; // Set coupler to same location as previous car coupler
953+
FrontCouplerShape.Location.TileX = Car.CarAhead.RearCouplerLocationTileX;
954+
FrontCouplerShape.Location.TileZ = Car.CarAhead.RearCouplerLocationTileZ;
955+
}
952956
}
953957

954958
// Display Animation Shape

0 commit comments

Comments
 (0)