Skip to content

Commit c74058d

Browse files
committed
Cab controls mouse handling refactored
1 parent 3b951a0 commit c74058d

File tree

3 files changed

+68
-224
lines changed

3 files changed

+68
-224
lines changed

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,10 +3367,15 @@ public ThreeDimentionCabViewer(Viewer viewer, MSTSLocomotive car, MSTSLocomotive
33673367
break;
33683368
}
33693369

3370+
// This is the case for .s files, for glTF-s it will not be true
3371+
var targetNode = iMatrix;
3372+
33703373
if (style != null && style is CabViewDigitalRenderer)//digits?
33713374
{
33723375
//DigitParts.Add(key, new DigitalDisplay(viewer, TrainCarShape, iMatrix, parameter, locoViewer.ThreeDimentionCabRenderer.ControlMap[key]));
33733376
DigitParts3D.Add(key, new ThreeDimCabDigit(viewer, iMatrix, parameter1, parameter2, this.TrainCarShape, locoViewer.ThreeDimentionCabRenderer.ControlMap[key], Locomotive));
3377+
if (!TrainCarShape.SharedShape.StoredResultMatrixes.ContainsKey(targetNode))
3378+
TrainCarShape.SharedShape.StoredResultMatrixes.Add(targetNode, Matrix.Identity);
33743379
}
33753380
else if (style != null && style is CabViewGaugeRenderer)
33763381
{
@@ -3379,6 +3384,8 @@ public ThreeDimentionCabViewer(Viewer viewer, MSTSLocomotive car, MSTSLocomotive
33793384
if (CVFR.GetGauge().ControlStyle != CABViewControlStyles.POINTER) //pointer will be animated, others will be drawn dynamicaly
33803385
{
33813386
Gauges.Add(key, new ThreeDimCabGaugeNative(viewer, iMatrix, parameter1, parameter2, this.TrainCarShape, locoViewer.ThreeDimentionCabRenderer.ControlMap[key]));
3387+
if (!TrainCarShape.SharedShape.StoredResultMatrixes.ContainsKey(targetNode))
3388+
TrainCarShape.SharedShape.StoredResultMatrixes.Add(targetNode, Matrix.Identity);
33823389
}
33833390
else
33843391
{//for pointer animation
@@ -3390,11 +3397,15 @@ public ThreeDimentionCabViewer(Viewer viewer, MSTSLocomotive car, MSTSLocomotive
33903397
}
33913398
else tmpPart = AnimateParts[key];
33923399
tmpPart.AddMatrix(iMatrix); //tmpPart.SetPosition(false);
3400+
if (!TrainCarShape.SharedShape.StoredResultMatrixes.ContainsKey(targetNode))
3401+
TrainCarShape.SharedShape.StoredResultMatrixes.Add(targetNode, Matrix.Identity);
33933402
}
33943403
}
33953404
else if (style != null && style is DistributedPowerInterfaceRenderer)
33963405
{
33973406
DPIDisplays3D.Add(key, new ThreeDimCabDPI(viewer, iMatrix, parameter1, parameter2, this.TrainCarShape, locoViewer.ThreeDimentionCabRenderer.ControlMap[key]));
3407+
if (!TrainCarShape.SharedShape.StoredResultMatrixes.ContainsKey(targetNode))
3408+
TrainCarShape.SharedShape.StoredResultMatrixes.Add(targetNode, Matrix.Identity);
33983409
}
33993410
else
34003411
{
@@ -3406,6 +3417,8 @@ public ThreeDimentionCabViewer(Viewer viewer, MSTSLocomotive car, MSTSLocomotive
34063417
}
34073418
else tmpPart = AnimateParts[key];
34083419
tmpPart.AddMatrix(iMatrix); //tmpPart.SetPosition(false);
3420+
if (!TrainCarShape.SharedShape.StoredResultMatrixes.ContainsKey(targetNode))
3421+
TrainCarShape.SharedShape.StoredResultMatrixes.Add(targetNode, Matrix.Identity);
34093422
}
34103423
}
34113424
}

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,11 @@ public class SharedShape : IDisposable
19761976
public string SoundFileName = "";
19771977
public float CustomAnimationFPS = 8;
19781978

1979+
/// <summary>
1980+
/// Store for matrixes needed to be reused in later calculations, e.g. for 3d cabview mouse control
1981+
/// </summary>
1982+
public readonly Dictionary<int, Matrix> StoredResultMatrixes = new Dictionary<int, Matrix>();
1983+
19791984

19801985
readonly Viewer Viewer;
19811986
public readonly string FilePath;
@@ -2610,6 +2615,9 @@ public void PrepareFrame(RenderFrame frame, WorldPosition location, Matrix[] ani
26102615
}
26112616
Matrix.Multiply(ref xnaMatrix, ref xnaDTileTranslation, out xnaMatrix);
26122617

2618+
if (StoredResultMatrixes.ContainsKey(shapePrimitive.HierarchyIndex))
2619+
StoredResultMatrixes[shapePrimitive.HierarchyIndex] = xnaMatrix;
2620+
26132621
// TODO make shadows depend on shape overrides
26142622

26152623
var interior = (flags & ShapeFlags.Interior) != 0;

0 commit comments

Comments
 (0)