Skip to content

Commit f9e80b9

Browse files
authored
Merge pull request #1051 from pzgulyas/cabmouse
Mouse wheel support for cabview controls + refactor
2 parents b8c8c9a + 0ac5d30 commit f9e80b9

File tree

4 files changed

+74
-239
lines changed

4 files changed

+74
-239
lines changed

Source/RunActivity/Viewer3D/Cameras.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected void ZoomByMouseWheel(float speed)
270270
{
271271
// Will not zoom-in-out when help windows is up.
272272
// TODO: Property input processing through WindowManager.
273-
if (UserInput.IsMouseWheelChanged && !Viewer.HelpWindow.Visible)
273+
if (UserInput.IsMouseWheelChanged && !Viewer.HelpWindow.Visible && !Viewer.RenderProcess.IsMouseVisible)
274274
{
275275
var fieldOfView = MathHelper.Clamp(FieldOfView - speed * UserInput.MouseWheelChange / 10, 1, 135);
276276
new FieldOfViewCommand(Viewer.Log, fieldOfView);

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -2336,8 +2336,8 @@ public virtual int GetDrawIndex()
23362336
float NormalizedMouseMovement()
23372337
{
23382338
return (ControlDiscrete.Orientation > 0
2339-
? (float)UserInput.MouseMoveY / (float)Control.Height
2340-
: (float)UserInput.MouseMoveX / (float)Control.Width)
2339+
? (float)(UserInput.MouseMoveY + UserInput.MouseWheelChange) / (float)Control.Height
2340+
: (float)(UserInput.MouseMoveX + UserInput.MouseWheelChange) / (float)Control.Width)
23412341
* (ControlDiscrete.Direction > 0 ? -1 : 1);
23422342
}
23432343

@@ -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

+8
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)