Skip to content

Commit 52d5886

Browse files
committed
Fix 3D cab render order
1 parent a67d510 commit 52d5886

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,19 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
35843584
/// </summary>
35853585
public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
35863586
{
3587+
// First, update the position of the 3D cab shape
3588+
if (TrainCarShape != null)
3589+
{
3590+
int viewPoint = (Viewer.Camera as InsideThreeDimCamera).ActViewPoint;
3591+
// Update transform of entire interior
3592+
TrainCarShape.Location.XNAMatrix = Car.WorldPosition.XNAMatrix;
3593+
TrainCarShape.Location.TileX = Car.WorldPosition.TileX;
3594+
TrainCarShape.Location.TileZ = Car.WorldPosition.TileZ;
3595+
3596+
TrainCarShape.XNAMatrices[0].Translation = Car.CabViewpoints[viewPoint].ShapeOffset;
3597+
if (Car.CabViewpoints[viewPoint].ShapeIndex >= 0 && Car.CabViewpoints[viewPoint].ShapeIndex < LocoViewer.TrainCarShape.ResultMatrices.Length)
3598+
TrainCarShape.Location.XNAMatrix = LocoViewer.TrainCarShape.ResultMatrices[Car.CabViewpoints[viewPoint].ShapeIndex] * TrainCarShape.Location.XNAMatrix;
3599+
}
35873600

35883601
Locomotive.SoundHeardInternallyCorrection[0] = Locomotive.SoundHeardInternallyCorrection[1] = 0;
35893602
foreach (var p in AnimateParts)
@@ -3733,27 +3746,16 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
37333746
p.Value.PrepareFrame(frame, elapsedTime);
37343747
}
37353748

3736-
if (ExternalWipers != null) ExternalWipers.UpdateLoop(Locomotive.Wiper, elapsedTime);
3749+
ExternalWipers?.UpdateLoop(Locomotive.Wiper, elapsedTime);
37373750
/*
37383751
foreach (var p in DigitParts)
37393752
{
37403753
p.Value.PrepareFrame(frame, elapsedTime);
37413754
}*/ //removed with 3D digits
37423755

3743-
if (TrainCarShape != null)
3744-
{
3745-
int viewPoint = (Viewer.Camera as InsideThreeDimCamera).ActViewPoint;
3746-
// Update transform of entire interior
3747-
TrainCarShape.Location.XNAMatrix = Car.WorldPosition.XNAMatrix;
3748-
TrainCarShape.Location.TileX = Car.WorldPosition.TileX;
3749-
TrainCarShape.Location.TileZ = Car.WorldPosition.TileZ;
3750-
3751-
TrainCarShape.XNAMatrices[0].Translation = Car.CabViewpoints[viewPoint].ShapeOffset;
3752-
if (Car.CabViewpoints[viewPoint].ShapeIndex >= 0 && Car.CabViewpoints[viewPoint].ShapeIndex < LocoViewer.TrainCarShape.ResultMatrices.Length)
3753-
TrainCarShape.Location.XNAMatrix = LocoViewer.TrainCarShape.ResultMatrices[Car.CabViewpoints[viewPoint].ShapeIndex] * TrainCarShape.Location.XNAMatrix;
37543756

3755-
TrainCarShape.ConditionallyPrepareFrame(frame, elapsedTime, MatrixVisible);
3756-
}
3757+
// Finally, handle the 3D cab shape
3758+
TrainCarShape?.ConditionallyPrepareFrame(frame, elapsedTime, MatrixVisible);
37573759
}
37583760

37593761
public override void UpdateAnimations(ElapsedTime elapsedTime)

0 commit comments

Comments
 (0)