@@ -4483,25 +4483,27 @@ public void RepositionRearTraveller()
4483
4483
car.ComputePosition(traveller, false, 0, 0, SpeedMpS);
4484
4484
}
4485
4485
else
4486
- {
4486
+ {
4487
4487
// traveller is positioned at the front of the car
4488
4488
// advance to the first bogie
4489
4489
traveller.Move((car.CarLengthM - car.CarBogieCentreLengthM) / 2.0f);
4490
+ Vector3 frontLoc = traveller.CalcElevationPositionOffset(0.0f, Simulator.UseSuperElevation, out float rearRoll);
4491
+ frontLoc += traveller.Location;
4492
+
4490
4493
var tileX = traveller.TileX;
4491
4494
var tileZ = traveller.TileZ;
4492
- var x = traveller.X;
4493
- var y = traveller.Y;
4494
- var z = traveller.Z;
4495
4495
4496
4496
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
4497
- // Also determine roll angle for superelevation by averaging both bogies
4498
- float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation);
4497
+ // Outputs rotation angle for superelevation, used below
4499
4498
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4500
- roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation)) / 2.0f;
4499
+ Vector3 rearLoc = traveller.CalcElevationPositionOffset(0.0f, Simulator.UseSuperElevation, out float frontRoll);
4500
+ rearLoc += traveller.Location;
4501
+
4502
+ float roll = (rearRoll + frontRoll) / 2.0f;
4501
4503
4502
4504
// Normalize across tile boundaries
4503
- x += 2048 * (tileX - traveller.TileX);
4504
- z += 2048 * (tileZ - traveller.TileZ);
4505
+ frontLoc.X += 2048 * (tileX - traveller.TileX);
4506
+ frontLoc.Z += 2048 * (tileZ - traveller.TileZ);
4505
4507
4506
4508
car.WorldPosition.XNAMatrix = Matrix.Identity;
4507
4509
if (!car.Flipped)
@@ -4512,16 +4514,14 @@ public void RepositionRearTraveller()
4512
4514
}
4513
4515
4514
4516
// Position car based on position of the front and rear of the car
4515
- car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller .X, traveller .Y, traveller .Z, x, y, z );
4517
+ car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(rearLoc .X, rearLoc .Y, rearLoc .Z, frontLoc.X, frontLoc.Y, frontLoc.Z );
4516
4518
4517
4519
// Update gravity force when position is updated, but before any secondary motion is added
4518
4520
car.UpdateGravity();
4519
4521
4520
4522
// Apply superelevation to car
4521
- car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
4522
-
4523
- // note the railcar sits 0.275meters above the track database path TODO - is this always consistent?
4524
- car.WorldPosition.XNAMatrix.Translation += car.WorldPosition.XNAMatrix.Up * 0.275f;
4523
+ if (roll != 0)
4524
+ car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
4525
4525
4526
4526
car.WorldPosition.TileX = traveller.TileX;
4527
4527
car.WorldPosition.TileZ = traveller.TileZ;
@@ -4606,21 +4606,23 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
4606
4606
// traveller is positioned at the back of the car
4607
4607
// advance to the first bogie
4608
4608
traveller.Move((car.CarLengthM - car.CarBogieCentreLengthM) / 2.0f);
4609
+ Vector3 rearLoc = traveller.CalcElevationPositionOffset(0.0f, Simulator.UseSuperElevation, out float rearRoll);
4610
+ rearLoc += traveller.Location;
4611
+
4609
4612
var tileX = traveller.TileX;
4610
4613
var tileZ = traveller.TileZ;
4611
- var x = traveller.X;
4612
- var y = traveller.Y;
4613
- var z = traveller.Z;
4614
4614
4615
4615
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
4616
4616
// Outputs rotation angle for superelevation, used below
4617
- float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation);
4618
4617
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4619
- roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation)) / 2.0f;
4618
+ Vector3 frontLoc = traveller.CalcElevationPositionOffset(0.0f, Simulator.UseSuperElevation, out float frontRoll);
4619
+ frontLoc += traveller.Location;
4620
+
4621
+ float roll = (rearRoll + frontRoll) / 2.0f;
4620
4622
4621
4623
// Normalize across tile boundaries
4622
- x += 2048 * (tileX - traveller.TileX);
4623
- z += 2048 * (tileZ - traveller.TileZ);
4624
+ rearLoc.X += 2048 * (tileX - traveller.TileX);
4625
+ rearLoc.Z += 2048 * (tileZ - traveller.TileZ);
4624
4626
4625
4627
car.WorldPosition.XNAMatrix = Matrix.Identity;
4626
4628
if (car.Flipped)
@@ -4631,16 +4633,14 @@ public void CalculatePositionOfCars(float elapsedTime, float distance)
4631
4633
}
4632
4634
4633
4635
// Position car based on position of the front and rear of the car
4634
- car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller .X, traveller .Y, traveller .Z, x, y, z );
4636
+ car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(frontLoc .X, frontLoc .Y, frontLoc .Z, rearLoc.X, rearLoc.Y, rearLoc.Z );
4635
4637
4636
4638
// Update gravity force when position is updated, but before any secondary motion is added
4637
4639
car.UpdateGravity();
4638
4640
4639
4641
// Apply superelevation to car
4640
- car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
4641
-
4642
- // note the railcar sits 0.275meters above the track database path TODO - is this always consistent?
4643
- car.WorldPosition.XNAMatrix.Translation += car.WorldPosition.XNAMatrix.Up * 0.275f;
4642
+ if (roll != 0)
4643
+ car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
4644
4644
4645
4645
car.WorldPosition.TileX = traveller.TileX;
4646
4646
car.WorldPosition.TileZ = traveller.TileZ;
@@ -4685,21 +4685,23 @@ public void CalculatePositionOfEOT()
4685
4685
// traveller is positioned at the back of the car
4686
4686
// advance to the first bogie
4687
4687
traveller.Move((car.CarLengthM - car.CarBogieCentreLengthM) / 2.0f);
4688
+ Vector3 rearLoc = traveller.CalcElevationPositionOffset(0.0f, Simulator.UseSuperElevation, out float rearRoll);
4689
+ rearLoc += traveller.Location;
4690
+
4688
4691
var tileX = traveller.TileX;
4689
4692
var tileZ = traveller.TileZ;
4690
- var x = traveller.X;
4691
- var y = traveller.Y;
4692
- var z = traveller.Z;
4693
4693
4694
4694
// Update car's curve radius and superelevation based on bogie position and move traveller to front bogie
4695
4695
// Outputs rotation angle for superelevation, used below
4696
- float roll = traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation);
4697
4696
car.UpdateCurvePhys(traveller, new[] { 0, car.CarBogieCentreLengthM });
4698
- roll = (roll + traveller.GetVisualElevation(Simulator.Settings.UseSuperElevation)) / 2.0f;
4697
+ Vector3 frontLoc = traveller.CalcElevationPositionOffset(0.0f, Simulator.UseSuperElevation, out float frontRoll);
4698
+ frontLoc += traveller.Location;
4699
+
4700
+ float roll = (rearRoll + frontRoll) / 2.0f;
4699
4701
4700
4702
// Normalize across tile boundaries
4701
- x += 2048 * (tileX - traveller.TileX);
4702
- z += 2048 * (tileZ - traveller.TileZ);
4703
+ rearLoc.X += 2048 * (tileX - traveller.TileX);
4704
+ rearLoc.Z += 2048 * (tileZ - traveller.TileZ);
4703
4705
4704
4706
car.WorldPosition.XNAMatrix = Matrix.Identity;
4705
4707
if (car.Flipped)
@@ -4710,16 +4712,14 @@ public void CalculatePositionOfEOT()
4710
4712
}
4711
4713
4712
4714
// Position car based on position of the front and rear of the car
4713
- car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(traveller .X, traveller .Y, traveller .Z, x, y, z );
4715
+ car.WorldPosition.XNAMatrix *= Simulator.XNAMatrixFromMSTSCoordinates(frontLoc .X, frontLoc .Y, frontLoc .Z, rearLoc.X, rearLoc.Y, rearLoc.Z );
4714
4716
4715
4717
// Update gravity force when position is updated, but before any secondary motion is added
4716
4718
car.UpdateGravity();
4717
4719
4718
4720
// Apply superelevation to car
4719
- car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
4720
-
4721
- // note the railcar sits 0.275meters above the track database path TODO - is this always consistent?
4722
- car.WorldPosition.XNAMatrix.Translation += car.WorldPosition.XNAMatrix.Up * 0.275f;
4721
+ if (roll != 0)
4722
+ car.WorldPosition.XNAMatrix = Matrix.CreateRotationZ((car.Flipped ? -1.0f : 1.0f) * roll) * car.WorldPosition.XNAMatrix;
4723
4723
4724
4724
car.WorldPosition.TileX = traveller.TileX;
4725
4725
car.WorldPosition.TileZ = traveller.TileZ;
0 commit comments