Skip to content

Commit 2be1faa

Browse files
authored
Merge pull request #863 from Csantucci/alternate-3DCab-preset-viewpoints
Alternate preset 3D cabviewpoints
2 parents 43c9bc1 + 516825f commit 2be1faa

File tree

8 files changed

+95
-10
lines changed

8 files changed

+95
-10
lines changed

Source/Documentation/Manual/cabs.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,40 @@ Development Rules
11541154
StartDirection ( 12 0 0 )
11551155
)
11561156

1157+
- If also a rear cab is present, a second ``ORTS3DCab`` has to be added,
1158+
as follows::
1159+
1160+
ORTS3DCab(
1161+
ORTS3DCabFile ( Cab.s )
1162+
ORTS3DCabHeadPos ( 0.9 2.4 5.2 )
1163+
RotationLimit ( 40 60 0 )
1164+
StartDirection ( 12 180 0 )
1165+
)
1166+
1167+
- Alternate 3D cab viewpoints may be added, as in the example here below::
1168+
1169+
ORTSAlternate3DCabViewPoints
1170+
(
1171+
ORTSAlternate3DCabViewPoint(
1172+
ORTS3DCabFile ( Cab.s )
1173+
ORTS3DCabHeadPos ( 0.9 2.4 5.2 )
1174+
RotationLimit ( 40 60 0 )
1175+
StartDirection ( 12 0 0 )
1176+
)
1177+
ORTSAlternate3DCabViewPoint(
1178+
ORTS3DCabFile ( Cab.s )
1179+
ORTS3DCabHeadPos ( -0.8 2.4 5.2 )
1180+
RotationLimit ( 40 60 0 )
1181+
StartDirection ( 12 30 0 )
1182+
)
1183+
)
1184+
1185+
1186+
- To switch between alternate cab viewpoints ``Ctrl-Shift-1`` must be pressed.
1187+
If there aren't alternate viewpoints defined, and if there is no rear cab,
1188+
pressing ``Ctrl-Shift-1`` toggles between the base viewpoint and a symmetrical
1189+
one on the longitudinal axis.
1190+
11571191
.. index::
11581192
single: EXTERNALWIPERS
11591193
single: AMMETER

Source/ORTS.Common/Input/UserCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public enum UserCommand
7777

7878
[GetString("Camera Cab")] CameraCab,
7979
[GetString("Camera Change Passenger Viewpoint")] CameraChangePassengerViewPoint,
80+
[GetString("Camera Change 3DCab Viewpoint")] CameraChange3DCabViewPoint,
8081
[GetString("Camera Toggle 3D Cab")] CameraToggleThreeDimensionalCab,
8182
[GetString("Camera Toggle Show Cab")] CameraToggleShowCab,
8283
[GetString("Camera Toggle Letterbox Cab")] CameraToggleLetterboxCab,

Source/ORTS.Settings/InputSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ static void InitializeCommands(UserCommandInput[] Commands)
332332
Commands[(int)UserCommand.CameraScrollLeft] = new UserCommandModifiableKeyInput(0x4B, KeyModifiers.Alt);
333333
Commands[(int)UserCommand.CameraScrollRight] = new UserCommandModifiableKeyInput(0x4D, KeyModifiers.Alt);
334334
Commands[(int)UserCommand.CameraChangePassengerViewPoint] = new UserCommandKeyInput(0x06, KeyModifiers.Shift);
335+
Commands[(int)UserCommand.CameraChange3DCabViewPoint] = new UserCommandKeyInput(0x02, KeyModifiers.Control | KeyModifiers.Shift);
335336
Commands[(int)UserCommand.CameraToggleLetterboxCab] = new UserCommandKeyInput(0x02, KeyModifiers.Control);
336337
Commands[(int)UserCommand.CameraToggleShowCab] = new UserCommandKeyInput(0x02, KeyModifiers.Shift);
337338
Commands[(int)UserCommand.CameraTrackside] = new UserCommandKeyInput(0x05);

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,13 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
15121512
}
15131513
else stf.SkipRestOfBlock();
15141514
break;
1515+
case "wagon(ortsalternate3dcabviewpoints": // accepted only if there is already a 3D cabview
1516+
if (Cab3DShapeFileName != null)
1517+
{
1518+
ParseAlternate3DCabViewPoints(stf);
1519+
}
1520+
else stf.SkipRestOfBlock();
1521+
break;
15151522
default:
15161523
if (MSTSBrakeSystem != null)
15171524
MSTSBrakeSystem.Parse(lowercasetoken, stf);
@@ -1752,6 +1759,15 @@ protected void ParseAlternatePassengerViewPoints(STFReader stf)
17521759
});
17531760
}
17541761

1762+
// parses additional 3Dcab viewpoints, if any
1763+
protected void ParseAlternate3DCabViewPoints(STFReader stf)
1764+
{
1765+
stf.MustMatch("(");
1766+
stf.ParseBlock(new[] {
1767+
new STFReader.TokenProcessor("ortsalternate3dcabviewpoint", ()=>{ Parse3DCab(stf); }),
1768+
});
1769+
}
1770+
17551771
public static float ParseFloat(string token)
17561772
{ // is there a better way to ignore any suffix?
17571773
while (token.Length > 0)

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,8 +2291,9 @@ public bool HasRear3DCab
22912291
{
22922292
var loco = this as MSTSLocomotive;
22932293
var i = (int)CabViewType.Rear;
2294-
if (loco == null || loco.CabView3D == null) return false;
2295-
return (loco.CabView3D.ViewPointList.Count > i);
2294+
if (loco == null || loco.CabView3D == null || loco.CabView3D.ViewPointList.Count <= i) return false;
2295+
var cabViewAngle = loco.CabView3D.ViewPointList[i].StartDirection.Y;
2296+
return ((cabViewAngle >= 90 && cabViewAngle <= 270) || (cabViewAngle <= -90 && cabViewAngle >= -270));
22962297
}
22972298
}
22982299

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,12 @@ public override void Reset()
17581758
XRadians = StartViewPointRotationXRadians;
17591759
YRadians = StartViewPointRotationYRadians;
17601760
}
1761+
1762+
public void SwitchSideCameraCar(TrainCar car)
1763+
{
1764+
attachedLocation.X = -attachedLocation.X;
1765+
RotationYRadians = -RotationYRadians;
1766+
}
17611767
}
17621768

17631769
public class PassengerCamera : InsideThreeDimCamera
@@ -1814,12 +1820,6 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
18141820
new CameraChangePassengerViewPointCommand(Viewer.Log);
18151821
}
18161822

1817-
public void SwitchSideCameraCar(TrainCar car)
1818-
{
1819-
attachedLocation.X = -attachedLocation.X;
1820-
RotationYRadians = -RotationYRadians;
1821-
}
1822-
18231823
public void ChangePassengerViewPoint(TrainCar car)
18241824
{
18251825
ActViewPoint++;
@@ -1890,7 +1890,7 @@ public void ChangeCab(TrainCar newCar)
18901890
var mstsLocomotive = newCar as MSTSLocomotive;
18911891
if (PrevCabWasRear != mstsLocomotive.UsingRearCab)
18921892
RotationYRadians += MathHelper.Pi;
1893-
ActViewPoint = mstsLocomotive.UsingRearCab ? 1 : 0;
1893+
ActViewPoint = mstsLocomotive.UsingRearCab && mstsLocomotive.HasFront3DCab ? 1 : 0;
18941894
PrevCabWasRear = mstsLocomotive.UsingRearCab;
18951895
SetCameraCar(newCar);
18961896
}
@@ -1925,6 +1925,20 @@ public override bool IsUnderground
19251925
return attachedCar.WorldPosition.Location.Y + TerrainAltitudeMargin < elevationAtCameraTarget || attachedCar.CarTunnelData.LengthMOfTunnelAheadFront > 0;
19261926
}
19271927
}
1928+
1929+
public override void HandleUserInput(ElapsedTime elapsedTime)
1930+
{
1931+
base.HandleUserInput(elapsedTime);
1932+
if (UserInput.IsPressed(UserCommand.CameraChange3DCabViewPoint))
1933+
new CameraChange3DCabViewPointCommand(Viewer.Log);
1934+
}
1935+
1936+
public void Change3DCabViewPoint(TrainCar car)
1937+
{
1938+
ActViewPoint++;
1939+
if (ActViewPoint >= car.CabViewpoints.Count) ActViewPoint = 0;
1940+
SetCameraCar(car);
1941+
}
19281942
}
19291943

19301944
public class HeadOutCamera : NonTrackingCamera

Source/RunActivity/Viewer3D/Commands.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,24 @@ public override void Redo()
947947
}
948948
}
949949

950+
[Serializable()]
951+
public sealed class CameraChange3DCabViewPointCommand : UseCameraCommand
952+
{
953+
954+
public CameraChange3DCabViewPointCommand(CommandLog log)
955+
: base(log)
956+
{
957+
Redo();
958+
}
959+
960+
public override void Redo()
961+
{
962+
if (Receiver.Camera.AttachedCar.CabViewpoints.Count == 1)
963+
Receiver.ThreeDimCabCamera.SwitchSideCameraCar(Receiver.Camera.AttachedCar);
964+
else Receiver.ThreeDimCabCamera.Change3DCabViewPoint(Receiver.Camera.AttachedCar);
965+
// Report();
966+
}
967+
}
950968
[Serializable()]
951969
public sealed class ToggleBrowseBackwardsCommand : UseCameraCommand
952970
{

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class Viewer
121121
/// <summary>
122122
/// Camera #1, 3D cab. Swaps with <see cref="CabCamera"/> with Alt+1.
123123
/// </summary>
124-
private readonly ThreeDimCabCamera ThreeDimCabCamera;
124+
public readonly ThreeDimCabCamera ThreeDimCabCamera;
125125
public HeadOutCamera HeadOutForwardCamera { get; private set; } // Camera 1+Up
126126
public HeadOutCamera HeadOutBackCamera { get; private set; } // Camera 2+Down
127127
public TrackingCamera FrontCamera { get; private set; } // Camera 2

0 commit comments

Comments
 (0)