Skip to content

Commit b9b077b

Browse files
committed
Rationalize CoG parameters
1 parent 25ac5e0 commit b9b077b

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

Source/Documentation/Manual/features-rollingstock.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -452,36 +452,36 @@ Improved wagon alignment tools
452452
Many MSTS and OR creators have encountered rolling stock shapes that were not correctly aligned,
453453
resulting in couplers/buffers clipping at one end of the wagon and separating at the other end.
454454
Normally, this would require inspecting the 3D model to determine exactly how off-center it was
455-
and carefully setting the Z value of ``CentreOfGravity ( x, y, z )`` to re-center the model.
455+
and carefully setting the Z value of ``CentreOfGravity ( x, y, z )`` to "nudge" the wagon shape
456+
until it is centered.
456457

457458
.. index::
458-
single: ORTSCentreOfGravity_X
459-
single: ORTSCentreOfGravity_Y
460-
single: ORTSCentreOfGravity_Z
459+
single: ORTSShapeNudge
461460

462461
In some cases, this approach could still be insufficient as the Z offset is limited to 2 meters in
463462
order to prevent unusual behaviors with some MSTS models that used unreasonably large Z offsets.
464-
To facilitate models that need large offsets without introducing errors, OR now has parameters
465-
to define the CoG dimensions individually without any artifical limits added afterward.
466-
To set the horizontal, vertical, and lengthwise CoG offset ``ORTSCentreOfGravity_X``, ``ORTSCentreOfGravity_Y``,
467-
and ``ORTSCentreOfGravity_Z`` respectively can be entered in the Wagon section of an engine or wagon.
463+
To facilitate models that need large offsets without introducing errors, OR now accepts this offset
464+
with the parameter ``ORTSShapeNudge ( z )``, which can be set to *any length offset without limit*.
468465

469-
If placed later in the file than the original ``CentreOfGravity`` parameter, the data entered in the X/Y/Z
470-
parameters will overwrite the original data, but only for the specific X/Y/Z component provided. For
471-
example, if ``ORTSCentreOfGravity_Z ( -1m )`` is placed after ``CentreOfGravity ( 0m 2.5m 0.5m )`` the
472-
resulting CoG offset will actually be 0m, 2.5m, -1m, overwriting the original 0.5m Z offset while
473-
leaving the X and Y components unchanged.
466+
.. index::
467+
single: CentreOfGravity
468+
469+
However, this does not entirely replace ``CentreOfGravity``. The Y (height) value of the CoG is
470+
still used by the physics system and should still be defined. In this case, simply use
471+
``CentreOfGravity ( y )`` where y is the CoG height in meters (or other units, as desired).
472+
Unlike entering all 3 values for the CoG, entering only the Y value will NOT affect the alignment
473+
of the 3D model, allowing the "physical" CoG to be entered separately from the "visual" CoG.
474474

475475
.. index::
476476
single: ORTSAutoCenter
477477

478-
However, in many cases it is desireable to simply center the 3D model lengthwise such that the
479-
couplers/buffers are equidistant from the centerpoint of the model. To make this specific case
480-
easier, OR now includes the ``ORTSAutoCenter`` parameter. When ``ORTSAutoCenter ( 1 )``
478+
And, for the sake of simplicity, it may be desired to just center the 3D model lengthwise
479+
such that the couplers/buffers are equidistant from the centerpoint of the model. To make this
480+
specific case easier, OR now includes the ``ORTSAutoCenter`` parameter. When ``ORTSAutoCenter ( 1 )``
481481
is included in the Wagon section of an engine or wagon, OR will inspect the main shape file used by
482482
the wagon to determine the exact Z value of CentreOfGravity required to re-center the shape in the
483-
simulation. This will overwrite the manually entered Z component of ``CentreOfGravity`` but will
484-
not change the X or Y components. Should no re-centering be required, none will be applied.
483+
simulation. This will overwrite the manually entered Z component of ``CentreOfGravity ( x y z )`` but
484+
will not change the X or Y components. Should no re-centering be required, none will be applied.
485485

486486
Some rolling stock will not align correctly when auto-centered. As with ``ORTSAutoSize``, this
487487
feature should be employed on rolling stock with standard buffers or couplers, and will

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,19 +1425,28 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
14251425
break;
14261426
case "wagon(centerofgravity":
14271427
case "wagon(centreofgravity":
1428-
InitialCentreOfGravityM = stf.ReadVector3Block(STFReader.UNITS.Distance, Vector3.Zero);
1429-
if (Math.Abs(InitialCentreOfGravityM.Z) > 2)
1428+
stf.MustMatch("(");
1429+
float initialValue = stf.ReadFloat(STFReader.UNITS.Distance, 0);
1430+
if (!stf.EndOfBlock()) // User has entered a 3-d vector
1431+
{
1432+
InitialCentreOfGravityM.X = initialValue;
1433+
InitialCentreOfGravityM.Y = stf.ReadFloat(STFReader.UNITS.Distance, 0);
1434+
InitialCentreOfGravityM.Z = stf.ReadFloat(STFReader.UNITS.Distance, 0);
1435+
1436+
if (Math.Abs(InitialCentreOfGravityM.Z) > 2)
1437+
{
1438+
STFException.TraceWarning(stf, string.Format("CentreOfGravity Z set to zero because value {0} outside range -2 to +2", InitialCentreOfGravityM.Z));
1439+
InitialCentreOfGravityM.Z = 0;
1440+
}
1441+
1442+
stf.SkipRestOfBlock();
1443+
}
1444+
else // User has entered a single value, only set the Y component to this value, leave other components unchanged
14301445
{
1431-
STFException.TraceWarning(stf, string.Format("CentreOfGravity Z set to zero because value {0} outside range -2 to +2", InitialCentreOfGravityM.Z));
1432-
InitialCentreOfGravityM.Z = 0;
1446+
InitialCentreOfGravityM.Y = initialValue;
14331447
}
14341448
break;
1435-
case "wagon(ortscenterofgravity_x":
1436-
case "wagon(ortscentreofgravity_x": InitialCentreOfGravityM.X = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
1437-
case "wagon(ortscenterofgravity_y":
1438-
case "wagon(ortscentreofgravity_y": InitialCentreOfGravityM.Y = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
1439-
case "wagon(ortscenterofgravity_z":
1440-
case "wagon(ortscentreofgravity_z": InitialCentreOfGravityM.Z = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
1449+
case "wagon(ortsshapenudge": InitialCentreOfGravityM.Z = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;
14411450
case "wagon(ortsautocentre":
14421451
case "wagon(ortsautocenter": AutoCenter = stf.ReadBoolBlock(true); break;
14431452
case "wagon(ortsunbalancedsuperelevation": MaxUnbalancedSuperElevationM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); break;

0 commit comments

Comments
 (0)