Skip to content

Commit 1339d8b

Browse files
committed
Automatic merge of T1.5.1-689-g9d41208f0 and 19 pull requests
- Pull request #570 at c59c788: Experimental glTF 2.0 support with PBR lighting - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #865 at 67014b7: Dispatcher window improvements - Pull request #874 at f8dbeab: Dynamic brake controller refactoring - Pull request #875 at 43bf33e: Bug fix for https://bugs.launchpad.net/or/+bug/2036346 Player train switching doesn't work with 3D cabs - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #878 at 8a6acee: Implement Polach Adhesion - Pull request #882 at 753b622: Blueprint/train car operations UI window - Pull request #883 at edcc2dd: SwitchPanel disconnect/connect handling - Pull request #885 at c81447b: feat: Add notifications to Menu - Pull request #886 at fabfc5a: Scene viewer extension to TrackViewer - Pull request #888 at d7daf62: docs: Document player application model - Pull request #889 at 43341cf: No speed update - Pull request #890 at 39a9fa4: Allow depart early - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #893 at bf8876b: Signal errors - Pull request #894 at 794fddf: Correct Decrease Colour - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #897 at 64a29c8: feat: Improved system information collection
21 parents 8025b85 + 9d41208 + c59c788 + d00beb9 + 67014b7 + f8dbeab + 43bf33e + f92de76 + 8a6acee + 753b622 + edcc2dd + c81447b + fabfc5a + d7daf62 + 43341cf + 39a9fa4 + 1f5ba4c + bf8876b + 794fddf + 5866028 + 64a29c8 commit 1339d8b

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

Source/Contrib/TrackViewer/SceneViewer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class SceneViewer
5656
internal StaticShape SelectedObject;
5757
internal Orts.Formats.Msts.WorldObject SelectedWorldObject;
5858
Viewer Viewer;
59-
ViewerCamera Camera;
59+
OrbitingCamera Camera;
6060

6161
/// <summary>The command-line arguments</summary>
6262
private string[] CommandLineArgs;
@@ -138,7 +138,7 @@ public void Update(GameTime gameTime)
138138
Viewer = Viewer ?? TrackViewer.RenderProcess?.Viewer;
139139
if (Viewer == null)
140140
return;
141-
Camera = Camera ?? Viewer.ViewerCamera;
141+
Camera = Camera ?? Viewer.OrbitingCamera;
142142

143143
Viewer.EditorShapes.MouseCrosshairEnabled = true;
144144

@@ -216,7 +216,7 @@ public async Task SetCameraLocation()
216216
break;
217217
}
218218
mouseLocation.Location.Y = elevatedLocation + 15;
219-
TrackViewer.RenderProcess.Viewer.ViewerCamera.SetLocation(mouseLocation);
219+
TrackViewer.RenderProcess.Viewer.OrbitingCamera.SetLocation(mouseLocation);
220220
}
221221

222222
void SelectedObjectChanged()

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -802,16 +802,17 @@ protected override void ZoomIn(float speed)
802802
}
803803
}
804804

805-
public class ViewerCamera : FreeRoamCamera
805+
public class OrbitingCamera : FreeRoamCamera
806806
{
807-
Vector3 RotationOrigin;
808-
Vector3 RotationDirection;
809-
WorldLocation RotationLocation;
810-
float RotationRadius;
811-
float RotationReferenceAngleX;
812-
float RotationReferenceAngleY;
813-
814-
public ViewerCamera(Viewer viewer)
807+
Vector3 StoredOrigin;
808+
Vector3 StoredDirection = Vector3.UnitZ;
809+
Vector3 StoredForward = Vector3.UnitZ;
810+
WorldLocation StoredLocation;
811+
float StoredRadius;
812+
float StoredAngleX;
813+
float StoredAngleY;
814+
815+
public OrbitingCamera(Viewer viewer)
815816
: base(viewer)
816817
{
817818
}
@@ -851,44 +852,40 @@ public override void RotateByMouse()
851852
RotationXRadians = MathHelper.WrapAngle(RotationXRadians + GetMouseDelta(UserInput.MouseMoveY));
852853
RotationYRadians = MathHelper.WrapAngle(RotationYRadians + GetMouseDelta(UserInput.MouseMoveX));
853854

854-
// Method 1
855-
//var deltaAngleX = MathHelper.WrapAngle(GetMouseDelta(UserInput.MouseMoveY));
856-
//var deltaAngleY = MathHelper.WrapAngle(GetMouseDelta(UserInput.MouseMoveX));
857-
//var direction = Vector3.Normalize(XnaLocation(CameraWorldLocation) - RotationOrigin);
858-
//var transform = Matrix.CreateFromYawPitchRoll(-deltaAngleY, -deltaAngleX, 0);
859-
//var newLocation = RotationOrigin + RotationRadius * Vector3.Transform(direction, transform);
860-
//newLocation.Z *= -1;
861-
//var newWorldLocation = CameraWorldLocation;
862-
//newWorldLocation.Location = newLocation;
855+
var deltaAngleX = MathHelper.WrapAngle(RotationXRadians - StoredAngleX);
856+
var deltaAngleY = MathHelper.WrapAngle(RotationYRadians - StoredAngleY);
863857

864-
// Method 2
865-
//var deltaAngleX = MathHelper.WrapAngle(RotationXRadians - RotationReferenceAngleX);
866-
//var deltaAngleY = MathHelper.WrapAngle(RotationYRadians - RotationReferenceAngleY);
867-
//var transform = Matrix.CreateFromYawPitchRoll(-deltaAngleY, -deltaAngleX, 0);
868-
//var newLocation = RotationOrigin + RotationRadius * Vector3.Transform(RotationDirection, transform);
858+
var dax = StoredForward.Z * deltaAngleX;
859+
var daz = StoredForward.X * deltaAngleX;
860+
var transform = Matrix.CreateRotationX(dax);
861+
transform *= Matrix.CreateRotationZ(daz);
862+
transform *= Matrix.CreateRotationY(-deltaAngleY);
869863

870-
// Method 3
871-
//var deltaAngleX = MathHelper.WrapAngle(RotationXRadians);
872-
//var deltaAngleY = MathHelper.WrapAngle(RotationYRadians);
873-
//var transform = Matrix.CreateFromYawPitchRoll(-deltaAngleY, -deltaAngleX, 0);
874-
//var newLocation = RotationOrigin + RotationRadius * Vector3.Transform(Vector3.UnitZ, transform);
864+
// FIXME: The math is still wrong here somewhere...
875865

876-
//newLocation.Z *= -1;
877-
//var newWorldLocation = RotationLocation;
878-
//newWorldLocation.Location = newLocation;
866+
var newWorldLocation = StoredLocation;
867+
newWorldLocation.Location = StoredOrigin + StoredRadius * Vector3.Transform(StoredDirection, transform);
868+
newWorldLocation.Location.Z *= -1;
879869

880-
//SetLocation(newWorldLocation);
870+
cameraLocation = newWorldLocation;
881871
}
882872

883873
public void StoreRotationOrigin(Vector3 rotationOrigin)
884874
{
885-
RotationOrigin = Viewer.TerrainPoint;
886-
RotationLocation = CameraWorldLocation;
887-
RotationDirection = XnaLocation(CameraWorldLocation) - RotationOrigin;
888-
RotationRadius = RotationDirection.Length();
889-
RotationDirection = Vector3.Normalize(RotationDirection);
890-
RotationReferenceAngleX = MathHelper.WrapAngle(RotationXRadians);
891-
RotationReferenceAngleY = MathHelper.WrapAngle(RotationYRadians);
875+
StoredOrigin = Viewer.TerrainPoint;
876+
StoredLocation = CameraWorldLocation;
877+
StoredDirection = XnaLocation(CameraWorldLocation) - StoredOrigin;
878+
StoredRadius = StoredDirection.Length();
879+
StoredDirection = Vector3.Normalize(StoredDirection);
880+
StoredAngleX = MathHelper.WrapAngle(RotationXRadians);
881+
StoredAngleY = MathHelper.WrapAngle(RotationYRadians);
882+
StoredForward = xnaView.Forward;
883+
}
884+
885+
public void SetOrientation(float rotationXRadians, float rotationYRadians)
886+
{
887+
RotationXRadians = rotationXRadians;
888+
RotationYRadians = rotationYRadians;
892889
}
893890

894891
public void PanByMouse()

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public class Viewer
139139
public BrakemanCamera BrakemanCamera { get; private set; } // Camera 6
140140
public List<FreeRoamCamera> FreeRoamCameraList = new List<FreeRoamCamera>();
141141
public FreeRoamCamera FreeRoamCamera { get { return FreeRoamCameraList[0]; } } // Camera 8
142-
public ViewerCamera ViewerCamera { get; private set; }
142+
public OrbitingCamera OrbitingCamera { get; private set; }
143143

144144
/// <summary>
145145
/// Activate the 2D or 3D cab camera depending on the current player preference.
@@ -180,7 +180,7 @@ void CameraActivate()
180180
if (PlayerLocomotive != null)
181181
FrontCamera.Activate();
182182
else
183-
ViewerCamera.Activate();
183+
OrbitingCamera.Activate();
184184
}
185185
else
186186
Camera.Activate();
@@ -329,7 +329,7 @@ public Viewer(Simulator simulator, Orts.Viewer3D.Processes.Game game)
329329
WellKnownCameras.Add(SpecialTracksideCamera = new SpecialTracksideCamera(this));
330330
FreeRoamCameraList.Add(new FreeRoamCamera(this, FrontCamera)); // Any existing camera will suffice to satisfy .Save() and .Restore()
331331
WellKnownCameras.Add(FreeRoamCamera);
332-
WellKnownCameras.Add(ViewerCamera = new ViewerCamera(this));
332+
WellKnownCameras.Add(OrbitingCamera = new OrbitingCamera(this));
333333
WellKnownCameras.Add(ThreeDimCabCamera = new ThreeDimCabCamera(this));
334334

335335
string ORfilepath = System.IO.Path.Combine(Simulator.RoutePath, "OpenRails");

0 commit comments

Comments
 (0)