@@ -1976,8 +1976,8 @@ public void ChangeCab(TrainCar newCar)
19761976 public class CabCamera : NonTrackingCamera
19771977 {
19781978 private readonly SavingProperty < bool > LetterboxProperty ;
1979- protected int sideLocation ;
1980- public int SideLocation { get { return sideLocation ; } }
1979+ protected int [ ] sideLocation = new int [ 2 ] ;
1980+ public int SideLocation { get { return attachedCar == null ? sideLocation [ 0 ] : ( attachedCar as MSTSLocomotive ) . UsingRearCab ? sideLocation [ 1 ] : sideLocation [ 0 ] ; } }
19811981
19821982 public override Styles Style { get { return Styles . Cab ; } }
19831983 // Cab camera is only possible on the player train.
@@ -2010,13 +2010,15 @@ public CabCamera(Viewer viewer)
20102010 protected internal override void Save ( BinaryWriter outf )
20112011 {
20122012 base . Save ( outf ) ;
2013- outf . Write ( sideLocation ) ;
2013+ outf . Write ( sideLocation [ 0 ] ) ;
2014+ outf . Write ( sideLocation [ 1 ] ) ;
20142015 }
20152016
20162017 protected internal override void Restore ( BinaryReader inf )
20172018 {
20182019 base . Restore ( inf ) ;
2019- sideLocation = inf . ReadInt32 ( ) ;
2020+ sideLocation [ 0 ] = inf . ReadInt32 ( ) ;
2021+ sideLocation [ 1 ] = inf . ReadInt32 ( ) ;
20202022 }
20212023
20222024 public override void Reset ( )
@@ -2078,10 +2080,11 @@ protected override void SetCameraCar(TrainCar car)
20782080 if ( car != null )
20792081 {
20802082 var loco = car as MSTSLocomotive ;
2081- var viewpoints = ( loco . UsingRearCab )
2082- ? loco . CabViewList [ ( int ) CabViewType . Rear ] . ViewPointList
2083- : loco . CabViewList [ ( int ) CabViewType . Front ] . ViewPointList ;
2084- attachedLocation = viewpoints [ sideLocation ] . Location ;
2083+ var sLIndex = ( loco . UsingRearCab ) ? ( int ) CabViewType . Rear : ( int ) CabViewType . Front ;
2084+ if ( sideLocation [ sLIndex ] >= loco . CabViewList [ sLIndex ] . ViewPointList . Count )
2085+ sideLocation [ sLIndex ] = 0 ;
2086+ var viewpoint = loco . CabViewList [ sLIndex ] . ViewPointList [ sideLocation [ sLIndex ] ] ;
2087+ attachedLocation = viewpoint . Location ;
20852088 }
20862089 InitialiseRotation ( attachedCar ) ;
20872090 }
@@ -2093,21 +2096,18 @@ protected override void SetCameraCar(TrainCar car)
20932096 void ShiftView ( int index )
20942097 {
20952098 var loco = attachedCar as MSTSLocomotive ;
2099+ var sLIndex = ( loco . UsingRearCab ) ? 1 : 0 ;
20962100
2097- var viewpointList = ( loco . UsingRearCab )
2098- ? loco . CabViewList [ ( int ) CabViewType . Rear ] . ViewPointList
2099- : loco . CabViewList [ ( int ) CabViewType . Front ] . ViewPointList ;
2100-
2101- sideLocation += index ;
2101+ sideLocation [ sLIndex ] += index ;
21022102
21032103 var count = ( loco . UsingRearCab )
21042104 ? loco . CabViewList [ ( int ) CabViewType . Rear ] . ViewPointList . Count
21052105 : loco . CabViewList [ ( int ) CabViewType . Front ] . ViewPointList . Count ;
21062106 // Wrap around
2107- if ( sideLocation < 0 )
2108- sideLocation = count - 1 ;
2109- else if ( sideLocation >= count )
2110- sideLocation = 0 ;
2107+ if ( sideLocation [ sLIndex ] < 0 )
2108+ sideLocation [ sLIndex ] = count - 1 ;
2109+ else if ( sideLocation [ sLIndex ] >= count )
2110+ sideLocation [ sLIndex ] = 0 ;
21112111
21122112 SetCameraCar ( attachedCar ) ;
21132113 }
@@ -2189,12 +2189,12 @@ public void InitialiseRotation(TrainCar attachedCar)
21892189 if ( attachedCar == null ) return ;
21902190
21912191 var loco = attachedCar as MSTSLocomotive ;
2192- var viewpoints = ( loco . UsingRearCab )
2193- ? loco . CabViewList [ ( int ) CabViewType . Rear ] . ViewPointList
2194- : loco . CabViewList [ ( int ) CabViewType . Front ] . ViewPointList ;
2192+ var viewpoint = ( loco . UsingRearCab )
2193+ ? loco . CabViewList [ ( int ) CabViewType . Rear ] . ViewPointList [ sideLocation [ 1 ] ]
2194+ : loco . CabViewList [ ( int ) CabViewType . Front ] . ViewPointList [ sideLocation [ 0 ] ] ;
21952195
2196- RotationXRadians = MathHelper . ToRadians ( viewpoints [ sideLocation ] . StartDirection . X ) - RotationRatio * ( Viewer . CabYOffsetPixels + Viewer . CabExceedsDisplay / 2 ) ;
2197- RotationYRadians = MathHelper . ToRadians ( viewpoints [ sideLocation ] . StartDirection . Y ) - RotationRatioHorizontal * ( - Viewer . CabXOffsetPixels + Viewer . CabExceedsDisplayHorizontally / 2 ) ; ;
2196+ RotationXRadians = MathHelper . ToRadians ( viewpoint . StartDirection . X ) - RotationRatio * ( Viewer . CabYOffsetPixels + Viewer . CabExceedsDisplay / 2 ) ;
2197+ RotationYRadians = MathHelper . ToRadians ( viewpoint . StartDirection . Y ) - RotationRatioHorizontal * ( - Viewer . CabXOffsetPixels + Viewer . CabExceedsDisplayHorizontally / 2 ) ; ;
21982198 }
21992199
22002200 public override void HandleUserInput ( ElapsedTime elapsedTime )
0 commit comments