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