mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 08:55:22 +01:00
fix(vehicle): articulated joints keep their length, hoses bend smoothly from their cocks, buffers take the deflection of their end
- A joint of two cars (a rooted bonebend whose head is held to the whole turn of the next car) keeps the pieces of its spine as long as made (bones::keep_lengths): the bellows and the roof cables turn with the cars, no longer stretched and pressed by the play of the articulated coupling as the train brakes and pulls. - The turn is spread evenly along a rooted bend only for such a joint; a hose hanging from its cock (rooted, its head held to a line) turns along its chain, and is halved into small triangles like any other hose. - Each buffer is pressed in by the deflection of its end as the coupling has it (half the distance of the couplers, or that of the end in the physical model of the coupling) and by half of what its head stands nearer to the one it meets than the axis does: on the straight as before, on a curve the inside more. Assets (SVN pctga, scratchpad tool weze.py, not committed there yet): the .mmd of 404 vehicles get hose chains (hz_*: from each cock of pneumatic<n>[r]_On and cpneumatic<n>[r]_On to the point the heads share with the next vehicle), and those with automatic couplers a bone turning coupler<n>/cctrl<n>_on towards the pivot of the next one; the EN57 through a new attachments_<stem>_w.inc. The whole control cables of ukrotnienie.py are rehung smoothly from socket to socket. Without them the vehicles are drawn as before.
This commit is contained in:
+5
-3
@@ -85,9 +85,11 @@ bonebend: <submodel> <point> <point> ... [head <point> <point> [<point>]] [roote
|
||||
before. A whole cable is bent through the joint by a `rooted` `bonebend` from the socket, as the roof cables above.
|
||||
- A rubber collar gangway round the end door is a submodel of its own, bent the same way from the face of the body to
|
||||
the coupling plane: on a curve the collars of two coaches turn half the angle each and meet face to face.
|
||||
- The buffers (`buffer_left0<n>`, `buffer_right0<n>`) of two coupled vehicles are pressed in each as its head stands
|
||||
against the nearest head of the other vehicle on the track, half the overlap each, up to `DmaxB`: on a curve those
|
||||
on the inside press in, those on the outside stand clear. `gfx.buffers.curve no` in `eu07.ini` presses both buffers
|
||||
- The buffers (`buffer_left0<n>`, `buffer_right0<n>`) of two coupled vehicles are pressed in each by the deflection of
|
||||
its end as the coupling has it (half the distance of the couplers, or that of the end in the physical model of the
|
||||
coupling, by the springs of both ends), and by half of what its head stands nearer to the head it meets than the axis
|
||||
of the vehicle does, up to `DmaxB`: on a curve those on the inside press in more, those on the outside less or not at
|
||||
all, and on the straight both as before. `gfx.buffers.curve no` in `eu07.ini` presses both buffers
|
||||
of an end alike, by half the distance of the couplers, as before.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -520,6 +520,24 @@ TEST_CASE("bones: a hose on a running vehicle is drawn with its ends, not left b
|
||||
CHECK(glm::distance(bones::drawn(state, 1), before + travelled) < 1.0e-9);
|
||||
}
|
||||
|
||||
TEST_CASE("bones: a joint keeps the lengths of its pieces as made, stretched or pressed by the play of the coupling") {
|
||||
std::vector<glm::dvec3> const rest{{0.0, 0.0, 2.0}, {0.0, 0.2, 2.0}, {0.0, 0.4, 2.0}};
|
||||
// the next car 3 cm farther, turned a little round a curve
|
||||
std::vector<glm::dvec3> now{{0.0, 0.0, 2.0}, {0.01, 0.215, 2.0}, {0.03, 0.43, 2.0}};
|
||||
auto const turned{glm::normalize(now[2] - now[1])};
|
||||
bones::keep_lengths(rest, now);
|
||||
CHECK(now[0] == glm::dvec3{0.0, 0.0, 2.0});
|
||||
CHECK(glm::distance(now[1], now[0]) == doctest::Approx(0.2));
|
||||
CHECK(glm::distance(now[2], now[1]) == doctest::Approx(0.2));
|
||||
// each piece still pointing where it pointed
|
||||
auto const kept{glm::normalize(now[2] - now[1])};
|
||||
CHECK(glm::dot(kept, turned) == doctest::Approx(1.0));
|
||||
// pressed together, the same
|
||||
std::vector<glm::dvec3> pressed{{0.0, 0.0, 2.0}, {0.0, 0.18, 2.0}, {0.0, 0.36, 2.0}};
|
||||
bones::keep_lengths(rest, pressed);
|
||||
CHECK(pressed[2].y == doctest::Approx(0.4));
|
||||
}
|
||||
|
||||
TEST_CASE("bones: a joint held to the whole turn of the next car, spread evenly along it from either side") {
|
||||
bones::rig rig;
|
||||
REQUIRE(bones::add_point(rig, {"root", "fixed", "0", "0", "2"}).empty());
|
||||
|
||||
+16
-6
@@ -848,8 +848,11 @@ void TDynamicObject::bind_flex( std::vector<std::size_t> const &Bends ) {
|
||||
flex_data flex;
|
||||
flex.original = original;
|
||||
flex.bends = Bends;
|
||||
// a hose is halved into small triangles to bend smoothly; a rooted part, the end of a car body, is taken as made
|
||||
auto const halved { std::ranges::any_of( Bends, [ this ]( std::size_t const Bend ) { return false == m_rig.bends[ Bend ].rooted; } ) };
|
||||
// a hose is halved into small triangles to bend smoothly, one hanging from its cock too; a part of a joint of two cars
|
||||
// (rooted, its head held to the whole turn of the next car), the end of a car body, is taken as made
|
||||
auto const halved { std::ranges::any_of( Bends, [ this ]( std::size_t const Bend ) {
|
||||
auto const &bend { m_rig.bends[ Bend ] };
|
||||
return false == bend.rooted || bend.head_up < 0; } ) };
|
||||
flex.rest = halved ? subdivided( model_file_vertices( original ), max_flex_edge ) : model_file_vertices( original );
|
||||
if( flex.rest.empty() ) { return; }
|
||||
std::vector<glm::dvec3> points;
|
||||
@@ -981,10 +984,13 @@ void TDynamicObject::pose_flexes( std::vector<glm::dvec3> const &Now ) {
|
||||
}
|
||||
// the root held to the body as made
|
||||
bones::hold_root( bend, turns );
|
||||
if( bend.rooted && bend.head_from >= 0 ) {
|
||||
if( bend.rooted && bend.head_up >= 0 ) {
|
||||
// the joint of two cars: the turn spread evenly from the body to the next car, as the next car spreads it
|
||||
// the other way, so the parts of the two that overlap (the bellows, the roof cables) stay together
|
||||
bones::spread_turns( rest, turns );
|
||||
// and as long as made: the bellows and the cables turn with the cars, not stretched by the play of the
|
||||
// coupling of the articulated joint as the train brakes and pulls
|
||||
bones::keep_lengths( rest, now );
|
||||
}
|
||||
nodes.emplace_back( now.begin(), now.end() );
|
||||
nodeturns.emplace_back( turns.begin(), turns.end() );
|
||||
@@ -8367,16 +8373,20 @@ std::optional<std::array<double, 2>> TDynamicObject::buffers_pressed( int const
|
||||
return Vehicle.GetWorldPosition( frame * glm::dvec3 { Head.x, along, Head.y } ); };
|
||||
// outwards from our end
|
||||
auto const outwards { glm::normalize( head( *this, End, { 0.0, 0.0 } ) - GetWorldPosition( glm::dvec3 { 0.0 } ) ) };
|
||||
auto const limit { MoverParameters->Couplers[ End ].DmaxB };
|
||||
auto const &coupler { MoverParameters->Couplers[ End ] };
|
||||
auto const first { head( *neighbour.vehicle, neighbour.vehicle_end, *theirs[ 0 ] ) };
|
||||
auto const second { head( *neighbour.vehicle, neighbour.vehicle_end, *theirs[ 1 ] ) };
|
||||
// the gap of the two ends on their axis, as the gaps of the buffers are measured
|
||||
auto const centre { glm::dot( head( *neighbour.vehicle, neighbour.vehicle_end, { 0.0, 0.0 } ) - head( *this, End, { 0.0, 0.0 } ), outwards ) };
|
||||
std::array<double, 2> pressed {};
|
||||
for( std::size_t side = 0; side < pressed.size(); ++side ) {
|
||||
auto const here { head( *this, End, *ours[ side ] ) };
|
||||
auto const &facing { ( glm::distance( here, first ) < glm::distance( here, second ) ? first : second ) };
|
||||
// the gap to it along our end, negative where the two overlap: each buffer takes half of it
|
||||
// the deflection of our end as the coupling has it (half the distance of the couplers, or ours of the physical
|
||||
// model of the coupling), and half of what this buffer stands nearer to or farther from its pair than the axis
|
||||
// does: on a curve the inside presses in more, the outside less or not at all
|
||||
auto const gap { glm::dot( facing - here, outwards ) };
|
||||
pressed[ side ] = safe_clamp( gap / 2.0, -limit, 0.0 );
|
||||
pressed[ side ] = safe_clamp( coupler.Dist / 2.0 + ( gap - centre ) / 2.0, -coupler.DmaxB, 0.0 );
|
||||
}
|
||||
return pressed;
|
||||
}
|
||||
|
||||
+3
-2
@@ -922,8 +922,9 @@ private:
|
||||
int DettachStatus(int dir);
|
||||
int Dettach(int dir);
|
||||
TDynamicObject * Neighbour(int &dir);
|
||||
// how far each buffer of the end (left, right) is pressed in, as its head stands against the nearest one of the next
|
||||
// vehicle on the track: half the overlap each; none without a coupled vehicle with buffers known on both
|
||||
// how far each buffer of the end (left, right) is pressed in: the deflection of the end as the coupling has it, and
|
||||
// half of what the head stands nearer to the one it meets than the axis does; none without a coupled vehicle with
|
||||
// buffers known on both
|
||||
std::optional<std::array<double, 2>> buffers_pressed( int const End ) const;
|
||||
// whether both vehicles at the end have their control cables modelled whole (cctrl<n>_xon), drawn by the owner only
|
||||
bool control_cables_shared( int const End ) const;
|
||||
|
||||
@@ -425,6 +425,24 @@ void spread_turns(std::vector<glm::dvec3> const &Rest, std::vector<glm::dquat> &
|
||||
}
|
||||
}
|
||||
|
||||
void keep_lengths(std::vector<glm::dvec3> const &Rest, std::vector<glm::dvec3> &Now)
|
||||
{
|
||||
if (Rest.size() != Now.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// the pieces as they stand now, before any node is moved
|
||||
std::vector<glm::dvec3> const was{Now};
|
||||
for (std::size_t node{1}; node < Now.size(); ++node)
|
||||
{
|
||||
auto const piece{was[node] - was[node - 1]};
|
||||
auto const length{glm::length(piece)};
|
||||
auto const made{glm::distance(Rest[node], Rest[node - 1])};
|
||||
auto const direction{length > 1e-9 ? piece / length : Rest[node] - Rest[node - 1]};
|
||||
Now[node] = Now[node - 1] + (length > 1e-9 ? made : 1.0) * direction;
|
||||
}
|
||||
}
|
||||
|
||||
skin_pose pose_skin(skin_bind const &Bind, std::vector<glm::dvec3> const &Now, std::vector<glm::dquat> const &Turns)
|
||||
{
|
||||
if (Bind.piece + 1 >= Now.size() || Bind.piece + 1 >= Turns.size())
|
||||
|
||||
@@ -214,6 +214,10 @@ void hold_root(bend const &Bend, std::vector<glm::dquat> &Turns);
|
||||
// the turns of the nodes between the first and the last spread evenly along the spine as made, from the turn of the first
|
||||
// to that of the last: a joint bent the same seen from either car
|
||||
void spread_turns(std::vector<glm::dvec3> const &Rest, std::vector<glm::dquat> &Turns);
|
||||
// the nodes after the first moved along the spine so that each piece keeps its length as made, its direction kept: the
|
||||
// joint of two cars as stiff as the bellows over it, which turns with the cars but doesn't stretch with the play of
|
||||
// their coupling
|
||||
void keep_lengths(std::vector<glm::dvec3> const &Rest, std::vector<glm::dvec3> &Now);
|
||||
|
||||
// the move of a bone: turned about its anchor to face its aim again, its anchor moved
|
||||
struct motion {
|
||||
|
||||
Reference in New Issue
Block a user