@@ -882,33 +882,38 @@ private void UpdateAnimation(RenderFrame frame, ElapsedTime elapsedTime)
882882
883883#endif
884884
885- // truck angle animation
885+ // Bogie angle animation
886886 Matrix inverseLocation = Matrix . Invert ( Car . WorldPosition . XNAMatrix ) ;
887887
888888 foreach ( var p in Car . Parts )
889889 {
890890 if ( p . iMatrix <= 0 )
891891 continue ;
892892
893- // Determine orientation of bogie in absolute space
894893 Matrix m = Matrix . Identity ;
895- Vector3 fwd = new Vector3 ( p . Dir [ 0 ] , p . Dir [ 1 ] , - p . Dir [ 2 ] ) ;
896- // Only do this calculation if the bogie position has been calculated
897- if ( ! ( fwd . X == 0 && fwd . Y == 0 && fwd . Z == 0 ) )
894+
895+ // Bogie rotation calculation doesn't work on turntables
896+ // Assume bogies aren't rotated when on a turntable
897+ if ( Car . Train ? . ControlMode != Train . TRAIN_CONTROL . TURNTABLE )
898898 {
899- fwd . Normalize ( ) ;
900- Vector3 side = Vector3 . Cross ( Vector3 . Up , fwd ) ;
901- if ( ! ( side . X == 0 && side . Y == 0 && side . Z == 0 ) )
902- side . Normalize ( ) ;
903- Vector3 up = Vector3 . Cross ( fwd , side ) ;
904- m . Right = side ;
905- m . Up = up ;
906- m . Backward = fwd ;
907-
908- // Convert absolute rotation into rotation relative to train car
909- m = Matrix . CreateRotationZ ( p . Roll ) * m * inverseLocation ;
899+ // Determine orientation of bogie in absolute space
900+ Vector3 fwd = new Vector3 ( p . Dir [ 0 ] , p . Dir [ 1 ] , - p . Dir [ 2 ] ) ;
901+ // Only do this calculation if the bogie position has been calculated
902+ if ( ! ( fwd . X == 0 && fwd . Y == 0 && fwd . Z == 0 ) )
903+ {
904+ fwd . Normalize ( ) ;
905+ Vector3 side = Vector3 . Cross ( Vector3 . Up , fwd ) ;
906+ if ( ! ( side . X == 0 && side . Y == 0 && side . Z == 0 ) )
907+ side . Normalize ( ) ;
908+ Vector3 up = Vector3 . Cross ( fwd , side ) ;
909+ m . Right = side ;
910+ m . Up = up ;
911+ m . Backward = fwd ;
912+
913+ // Convert absolute rotation into rotation relative to train car
914+ m = Matrix . CreateRotationZ ( p . Roll ) * m * inverseLocation ;
915+ }
910916 }
911-
912917 // Insert correct translation (previous step likely introduced garbage data)
913918 m . Translation = TrainCarShape . SharedShape . Matrices [ p . iMatrix ] . Translation ;
914919
0 commit comments