Skip to content

Commit df0f361

Browse files
authored
Merge pull request #769 from Csantucci/partial-turntables
Partial turntables https://blueprints.launchpad.net/or/+spec/partial-turntable
2 parents 87ba54c + 1a99f43 commit df0f361

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

Source/Documentation/Manual/features-route.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ TrackShape block within the tsection.dat file. You only have to insert the diame
208208
the turntable and the degree step. Of course you have to take only the lines up to the
209209
one preceding the one with degrees = 180.
210210

211+
Also turntables which may rotate less than 360 degrees can be implemented, like the one in
212+
the picture here below:
213+
214+
.. image:: images/features-partial-turntable.png
215+
216+
In this case following line has to be added at the end of the ``Turntable()`` block
217+
in file ``turntables.dat`` for a turntable that can rotate only between 0 and 40 degrees::
218+
219+
MaxAngle ( 40 )
220+
221+
Angles increase clockwise.
222+
211223
Already many existing turntables have been successfully animated and many new other
212224
have been created. More can be read
213225
`in this forum thread <http://www.elvastower.com/forums/index.php?/topic/28591-operational-turntable/>`_ .
183 KB
Loading

Source/Orts.Simulation/Simulation/Turntables.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ public class Turntable : MovingTable
352352
public List<float> Angles = new List<float>();
353353
public float StartingY = 0; // starting yaw angle
354354
public float ThresholdForTarget; // Threshold to check if we can now go to the target
355+
public float MaxAngle = -1; // max angle extension for partial turntables (in radians)
355356
// Dynamic data
356357
public bool Clockwise; // clockwise motion on
357358
public bool Counterclockwise; // counterclockwise motion on
@@ -392,6 +393,7 @@ public Turntable(STFReader stf, Simulator simulator)
392393
TrackShapeIndex = stf.ReadIntBlock(-1);
393394
InitializeAnglesAndTrackNodes();
394395
}),
396+
new STFReader.TokenProcessor("maxangle", ()=>{ MaxAngle = MathHelper.ToRadians(stf.ReadFloatBlock(STFReader.UNITS.None , null));}),
395397
});
396398
}
397399

@@ -636,6 +638,18 @@ public override void StartContinuous(bool isClockwise)
636638

637639
public void GeneralStartContinuous(bool isClockwise)
638640
{
641+
if (MaxAngle > 0)
642+
{
643+
var positiveYAngle = YAngle >= 0 ? YAngle : YAngle + 2 * (float)Math.PI;
644+
if (!isClockwise && positiveYAngle < 0.2 || isClockwise && positiveYAngle <= 2 * (float)Math.PI - MaxAngle && positiveYAngle > 0.2)
645+
{
646+
Clockwise = false;
647+
Counterclockwise = false;
648+
Continuous = false;
649+
if (SendNotifications) Simulator.Confirmer.Warning(Simulator.Catalog.GetStringFmt("Turntable is at its bound, can't rotate"));
650+
return;
651+
}
652+
}
639653
if (TrainsOnMovingTable.Count > 1 || (TrainsOnMovingTable.Count == 1 && TrainsOnMovingTable[0].FrontOnBoard ^ TrainsOnMovingTable[0].BackOnBoard))
640654
{
641655
Clockwise = false;

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,17 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
15941594
AnimationKey = nextKey % animation.FrameCount;
15951595
if (AnimationKey < 0)
15961596
AnimationKey += animation.FrameCount;
1597+
// used if Turntable cannot turn 360 degrees
1598+
if (Turntable.MaxAngle > 0 && AnimationKey != 0)
1599+
{
1600+
if (AnimationKey < -SharedShape.Animations[0].FrameCount * Turntable.MaxAngle / (2 * Math.PI) + animation.FrameCount)
1601+
{
1602+
if (AnimationKey > 20)
1603+
AnimationKey = -SharedShape.Animations[0].FrameCount * Turntable.MaxAngle / (float)(2 * Math.PI) + animation.FrameCount;
1604+
else
1605+
AnimationKey = 0;
1606+
}
1607+
}
15971608
Turntable.YAngle = MathHelper.WrapAngle(nextKey / animation.FrameCount * 2 * (float)Math.PI);
15981609

15991610
if ((Turntable.Clockwise || Turntable.Counterclockwise || Turntable.AutoClockwise || Turntable.AutoCounterclockwise) && !Rotating)

0 commit comments

Comments
 (0)