From b1586ae5e79deb144d531c9f969f134b8beb0b5a Mon Sep 17 00:00:00 2001 From: carlossantucci Date: Tue, 8 Jan 2019 21:54:12 +0000 Subject: [PATCH] Bug fix for https://bugs.launchpad.net/or/+bug/1810685 Animation of root matrix does not work. git-svn-id: http://svn.uktrainsim.com/svn/openrails/trunk@4334 a9f3cfff-6c41-7446-b0ca-052bd761e6eb --- Source/RunActivity/Viewer3D/Shapes.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/RunActivity/Viewer3D/Shapes.cs b/Source/RunActivity/Viewer3D/Shapes.cs index 4bc370bb55..fcc1f93955 100644 --- a/Source/RunActivity/Viewer3D/Shapes.cs +++ b/Source/RunActivity/Viewer3D/Shapes.cs @@ -1484,6 +1484,13 @@ void LoadContent() throw new InvalidDataException("Shape file missing lod_control section"); else if (LodControls[0].DistanceLevels.Length > 0 && LodControls[0].DistanceLevels[0].SubObjects.Length > 0) { + // Zero the position offset of the root matrix for compatibility with MSTS + if (LodControls[0].DistanceLevels[0].SubObjects[0].ShapePrimitives.Length > 0 && LodControls[0].DistanceLevels[0].SubObjects[0].ShapePrimitives[0].Hierarchy[0] == -1) + { + Matrices[0].M41 = 0; + Matrices[0].M42 = 0; + Matrices[0].M43 = 0; + } // Look for root subobject, it is not necessarily the first (see ProTrain signal) for (int soIndex = 0; soIndex <= LodControls[0].DistanceLevels[0].SubObjects.Length - 1; soIndex++) { @@ -1974,7 +1981,7 @@ public void PrepareFrame(RenderFrame frame, WorldPosition location, Matrix[] ani { var xnaMatrix = Matrix.Identity; var hi = shapePrimitive.HierarchyIndex; - while (hi >= 0 && hi < shapePrimitive.Hierarchy.Length && shapePrimitive.Hierarchy[hi] != -1) + while (hi >= 0 && hi < shapePrimitive.Hierarchy.Length) { Matrix.Multiply(ref xnaMatrix, ref animatedXNAMatrices[hi], out xnaMatrix); hi = shapePrimitive.Hierarchy[hi];