diff --git a/Source/Orts.Formats.Msts/CabViewFile.cs b/Source/Orts.Formats.Msts/CabViewFile.cs index a66c15dae..36553958e 100644 --- a/Source/Orts.Formats.Msts/CabViewFile.cs +++ b/Source/Orts.Formats.Msts/CabViewFile.cs @@ -445,6 +445,13 @@ protected virtual float ParseSwitchVal(STFReader stf) stf.SkipRestOfBlock(); return switchVal; } + protected virtual float ParseRotation(STFReader stf) + { + stf.MustMatch("("); + var rotation = -MathHelper.ToRadians((float)stf.ReadDouble(0)); + stf.SkipRestOfBlock(); + return rotation; + } } #endregion @@ -515,6 +522,7 @@ public class CVCGauge : CabViewControl public int NumPositiveColors { get; set; } public int NumNegativeColors { get; set; } public color DecreaseColor { get; set; } + public float Rotation { get; set; } public CVCGauge() { } @@ -575,7 +583,8 @@ public CVCGauge(STFReader stf, string basepath) stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("controlcolour", ()=>{ DecreaseColor = ParseControlColor(stf); }) }); } - }) + }), + new STFReader.TokenProcessor("ortsangle", () =>{ Rotation = ParseRotation(stf); }) }); } } @@ -696,7 +705,7 @@ public CVCDigital(STFReader stf, string basepath) } }), new STFReader.TokenProcessor("ortsfont", ()=>{ParseFont(stf); }), - new STFReader.TokenProcessor("ortsangle", () => { ParseRotation(stf); }), + new STFReader.TokenProcessor("ortsangle", () => {Rotation = ParseRotation(stf); }), }); } @@ -737,14 +746,6 @@ protected void ParseFont(STFReader stf) if (fontFamily != null) FontFamily = fontFamily; stf.SkipRestOfBlock(); } - - protected virtual void ParseRotation(STFReader stf) - { - stf.MustMatch("("); - Rotation = - MathHelper.ToRadians((float)stf.ReadDouble(0)); - stf.SkipRestOfBlock(); - } - } public class CVCDigitalClock : CVCDigital diff --git a/Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs b/Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs index 5a3d15fbf..00ed0e2de 100644 --- a/Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs +++ b/Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs @@ -1536,6 +1536,7 @@ public class CabViewGaugeRenderer : CabViewControlRenderer Rectangle DestinationRectangle = new Rectangle(); // bool LoadMeterPositive = true; Color DrawColor; + float DrawRotation; Double Num; bool IsFire; @@ -1620,13 +1621,14 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) if (Gauge.Orientation == 0) { destX = (int)(xratio * (Control.PositionX + (zeropos < xpos ? zeropos : xpos))); - destY = (int)(yratio * Control.PositionY); +// destY = (int)(yratio * Control.PositionY); + destY = (int)(yratio * (Control.PositionY + (Gauge.Direction == 0 && zeropos > xpos ? (zeropos - xpos) * Math.Sin(DrawRotation) : 0))); destW = (int)(xratio * (xpos > zeropos ? xpos - zeropos : zeropos - xpos)); destH = (int)(yratio * ypos); } else { - destX = (int)(xratio * Control.PositionX); + destX = (int)(xratio * Control.PositionX + (Gauge.Direction == 0 && ypos > zeropos ? (ypos - zeropos) * Math.Sin(DrawRotation) : 0)); if (Gauge.Direction != 1 && !IsFire) destY = (int)(yratio * (Control.PositionY + (zeropos > ypos ? zeropos : 2 * zeropos - ypos))); else @@ -1640,9 +1642,16 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) var topY = Control.PositionY; // top of visible column. +ve Y is downwards if (Gauge.Direction != 0) // column grows from bottom or from right { - destX = (int)(xratio * (Control.PositionX + Gauge.Width - xpos)); if (Gauge.Orientation != 0) + { topY += Gauge.Height * (1 - percent); + destX = (int)(xratio * (Control.PositionX + Gauge.Width - xpos + ypos * Math.Sin(DrawRotation))); + } + else + { + topY -= xpos * Math.Sin(DrawRotation); + destX = (int)(xratio * (Control.PositionX + Gauge.Width - xpos)); + } } else { @@ -1655,20 +1664,33 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) } else // pointer gauge using texture { + // even if there is a rotation, we leave the X position unaltered (for small angles Cos(alpha) = 1) var topY = Control.PositionY; // top of visible column. +ve Y is downwards if (Gauge.Orientation == 0) // gauge horizontal { + if (Gauge.Direction != 0) // column grows from right + { destX = (int)(xratio * (Control.PositionX + Gauge.Width - 0.5 * Gauge.Area.Width - xpos)); + topY -= xpos * Math.Sin(DrawRotation); + } else + { destX = (int)(xratio * (Control.PositionX - 0.5 * Gauge.Area.Width + xpos)); + topY += xpos * Math.Sin(DrawRotation); + } } else // gauge vertical { + // even if there is a rotation, we leave the Y position unaltered (for small angles Cos(alpha) = 1) topY += ypos - 0.5 * Gauge.Area.Height; - destX = (int)(xratio * Control.PositionX); - if (Gauge.Direction != 0) // column grows from bottom + if (Gauge.Direction == 0) + destX = (int)(xratio * (Control.PositionX - ypos * Math.Sin(DrawRotation))); + else // column grows from bottom + { topY += Gauge.Height - 2 * ypos; + destX = (int)(xratio * (Control.PositionX + ypos * Math.Sin(DrawRotation))); + } } destY = (int)(yratio * topY); destW = (int)(xratio * Gauge.Area.Width); @@ -1707,6 +1729,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) DestinationRectangle.Y = destY; DestinationRectangle.Width = destW; DestinationRectangle.Height = destH; + DrawRotation = Gauge.Rotation; } public override void Draw(GraphicsDevice graphicsDevice) @@ -1715,7 +1738,7 @@ public override void Draw(GraphicsDevice graphicsDevice) { Shader.SetTextureData(DestinationRectangle.Left, DestinationRectangle.Top, DestinationRectangle.Width, DestinationRectangle.Height); } - CabShaderControlView.SpriteBatch.Draw(Texture, DestinationRectangle, SourceRectangle, DrawColor); + CabShaderControlView.SpriteBatch.Draw(Texture, DestinationRectangle, SourceRectangle, DrawColor, DrawRotation, Vector2.Zero, SpriteEffects.None, 0); } }