mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 02:56:01 +01:00
Merge remote-tracking branch 'origin/master' into feat/elf-master-controller-emergency-brake
# Conflicts: # McZapkie/Mover.cpp
This commit is contained in:
@@ -15,6 +15,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "vehicle/DynObj.h"
|
||||
|
||||
#include "vehicle/lightsprogrammer.h"
|
||||
|
||||
#include "simulation/simulation.h"
|
||||
#include "rendering/lightarray.h"
|
||||
#include "vehicle/Camera.h"
|
||||
@@ -29,6 +31,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "audio/sound.h"
|
||||
#include "model/MdlMngr.h"
|
||||
#include "model/Model3d.h"
|
||||
#include "vehicle/doorwings.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "application/uitranscripts.h"
|
||||
#include "input/messaging.h"
|
||||
@@ -557,20 +560,79 @@ void TDynamicObject::UpdateAxle(TAnim *pAnim)
|
||||
pAnim->smAnimated->future_transform = glm::rotate((float)glm::radians(m_future_wheels_angle[wheel_id]), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
};
|
||||
|
||||
// angle of a slotted lever for given angle of the wheel, which drives the coupling rod with the pin
|
||||
// all points of the coupling rod move along circles of crank radius, the lever follows the pin sliding in its slot
|
||||
double TDynamicObject::slottedlever_angle( slottedlever_data const &Lever, double const Wheelangle ) {
|
||||
// crank turned around X axis, the same way as the wheel
|
||||
auto const wheelangle { glm::radians( Wheelangle ) };
|
||||
auto const crank { glm::dvec2(
|
||||
Lever.crank.x * std::cos( wheelangle ) - Lever.crank.y * std::sin( wheelangle ),
|
||||
Lever.crank.x * std::sin( wheelangle ) + Lever.crank.y * std::cos( wheelangle ) ) };
|
||||
auto const pin { Lever.pin - Lever.crank + crank };
|
||||
// angle relative to the pose of the lever in the model, which matches wheel angle 0
|
||||
return glm::degrees( std::atan2( pin.y, pin.x ) - std::atan2( Lever.pin.y, Lever.pin.x ) );
|
||||
}
|
||||
|
||||
void TDynamicObject::update_slottedlevers() {
|
||||
|
||||
for( auto const &lever : m_slottedlevers ) {
|
||||
auto const wheelid { (
|
||||
( lever.axle < iAnimType[ ANIM_WHEELS ] ) && ( lever.axle < static_cast<int>( pAnimations.size() ) ) ?
|
||||
pAnimations[ lever.axle ].dWheelAngle :
|
||||
1 ) }; // driving wheels and coupling rods by default
|
||||
auto const angle { slottedlever_angle( lever, dWheelAngle[ wheelid ] ) };
|
||||
auto const futureangle { slottedlever_angle( lever, dWheelAngle[ wheelid ] + m_future_wheels_angle[ wheelid ] ) };
|
||||
lever.submodel->SetRotate( float3( 1, 0, 0 ), angle );
|
||||
lever.submodel->future_transform = glm::rotate( (float)glm::radians( std::remainder( futureangle - angle, 360.0 ) ), glm::vec3( 1.0f, 0.0f, 0.0f ) );
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// the position of the door the animated wing belongs to: its shift or angle from closed
|
||||
float door_position( TMoverParameters const &Mover, TAnim const *Animation ) {
|
||||
|
||||
return Mover.Doors.instances[ (
|
||||
door_wings::on_right_side( Animation->iNumber ) ?
|
||||
side::right :
|
||||
side::left ) ].position;
|
||||
}
|
||||
|
||||
// the wing in the main model, and its namesake in the low poly interior; either can be missing
|
||||
std::array<TSubModel *, 2> wing_parts( TAnim const *Animation ) {
|
||||
|
||||
return { Animation->smAnimated, Animation->smInterior };
|
||||
}
|
||||
|
||||
// folding door: the smaller wing turns, the larger wing (its child) the other way, the step (child of that) under it
|
||||
void fold_wing( TSubModel *Wing, door_wings::fold_angles const &Angles ) {
|
||||
|
||||
if( Wing == nullptr ) { return; }
|
||||
// skrzydło mniejsze
|
||||
Wing->SetRotate( float3( 0, 0, 1 ), Angles.smaller );
|
||||
// skrzydło większe
|
||||
auto *larger { Wing->ChildGet() };
|
||||
if( larger == nullptr ) { return; }
|
||||
larger->SetRotate( float3( 0, 0, 1 ), Angles.larger );
|
||||
// podnóżek?
|
||||
auto *step { larger->ChildGet() };
|
||||
if( step == nullptr ) { return; }
|
||||
step->SetRotate( float3( 0, 1, 0 ), Angles.step );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// animacja drzwi - przesuw
|
||||
void TDynamicObject::UpdateDoorTranslate(TAnim *pAnim) {
|
||||
|
||||
if( pAnim->smAnimated == nullptr ) { return; }
|
||||
|
||||
auto const &door { MoverParameters->Doors.instances[ (
|
||||
( pAnim->iNumber & 1 ) == 0 ?
|
||||
side::right :
|
||||
side::left ) ] };
|
||||
|
||||
pAnim->smAnimated->SetTranslate(
|
||||
glm::vec3{
|
||||
0.0,
|
||||
0.0,
|
||||
door.position } );
|
||||
auto const shift { door_wings::slide( door_position( *MoverParameters, pAnim ) ) };
|
||||
for( auto *wing : wing_parts( pAnim ) ) {
|
||||
if( wing != nullptr ) {
|
||||
wing->SetTranslate( shift );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// animacja drzwi - obrót
|
||||
@@ -578,14 +640,12 @@ void TDynamicObject::UpdateDoorRotate(TAnim *pAnim) {
|
||||
|
||||
if( pAnim->smAnimated == nullptr ) { return; }
|
||||
|
||||
auto const &door { MoverParameters->Doors.instances[ (
|
||||
( pAnim->iNumber & 1 ) == 0 ?
|
||||
side::right :
|
||||
side::left ) ] };
|
||||
|
||||
pAnim->smAnimated->SetRotate(
|
||||
float3(1, 0, 0),
|
||||
door.position );
|
||||
auto const angle { door_position( *MoverParameters, pAnim ) };
|
||||
for( auto *wing : wing_parts( pAnim ) ) {
|
||||
if( wing != nullptr ) {
|
||||
wing->SetRotate( float3( 1, 0, 0 ), angle );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// animacja drzwi - obrót
|
||||
@@ -593,31 +653,10 @@ void TDynamicObject::UpdateDoorFold(TAnim *pAnim) {
|
||||
|
||||
if( pAnim->smAnimated == nullptr ) { return; }
|
||||
|
||||
auto const &door { MoverParameters->Doors.instances[ (
|
||||
( pAnim->iNumber & 1 ) == 0 ?
|
||||
side::right :
|
||||
side::left ) ] };
|
||||
|
||||
// skrzydło mniejsze
|
||||
pAnim->smAnimated->SetRotate(
|
||||
float3(0, 0, 1),
|
||||
door.position);
|
||||
|
||||
// skrzydło większe
|
||||
auto *sm = pAnim->smAnimated->ChildGet();
|
||||
if( sm == nullptr ) { return; }
|
||||
|
||||
sm->SetRotate(
|
||||
float3(0, 0, 1),
|
||||
-door.position - door.position);
|
||||
|
||||
// podnóżek?
|
||||
sm = sm->ChildGet();
|
||||
if( sm == nullptr ) { return; }
|
||||
|
||||
sm->SetRotate(
|
||||
float3(0, 1, 0),
|
||||
door.position);
|
||||
auto const angles { door_wings::fold( door_position( *MoverParameters, pAnim ) ) };
|
||||
for( auto *wing : wing_parts( pAnim ) ) {
|
||||
fold_wing( wing, angles );
|
||||
}
|
||||
};
|
||||
|
||||
// animacja drzwi - odskokprzesuw
|
||||
@@ -625,20 +664,12 @@ void TDynamicObject::UpdateDoorPlug(TAnim *pAnim) {
|
||||
|
||||
if( pAnim->smAnimated == nullptr ) { return; }
|
||||
|
||||
auto const &door { MoverParameters->Doors.instances[ (
|
||||
( pAnim->iNumber & 1 ) == 0 ?
|
||||
side::right :
|
||||
side::left ) ] };
|
||||
|
||||
pAnim->smAnimated->SetTranslate(
|
||||
glm::vec3{
|
||||
std::min(
|
||||
door.position * 2.f,
|
||||
MoverParameters->Doors.range_out ),
|
||||
0.0,
|
||||
std::max(
|
||||
0.f,
|
||||
door.position - MoverParameters->Doors.range_out * 0.5f ) } );
|
||||
auto const shift { door_wings::plug( door_position( *MoverParameters, pAnim ), MoverParameters->Doors.range_out ) };
|
||||
for( auto *wing : wing_parts( pAnim ) ) {
|
||||
if( wing != nullptr ) {
|
||||
wing->SetTranslate( shift );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TDynamicObject::UpdatePant(TAnim *pAnim)
|
||||
@@ -841,6 +872,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
|
||||
animation.yUpdate( &animation );
|
||||
}
|
||||
}
|
||||
update_slottedlevers();
|
||||
|
||||
if( mdModel != nullptr
|
||||
&& ObjSqrDist < 50 * 50 ) {
|
||||
@@ -1713,7 +1745,8 @@ TDynamicObject::couple( int const Side ) {
|
||||
if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::control ) ) {
|
||||
// ukrotnionko
|
||||
if( (coupler.AllowedFlag & othercoupler.AllowedFlag & coupling::control) == coupling::control
|
||||
&& coupler.control_type == othercoupler.control_type ) {
|
||||
&& coupler.control_type == othercoupler.control_type
|
||||
&& ( MoverParameters->CompatibleCoupling( Side, *othervehicleparams, neighbour.vehicle_end, coupler.CouplingFlag | coupling::control ) & coupling::control ) != 0 ) {
|
||||
if( MoverParameters->Attach(
|
||||
Side, neighbour.vehicle_end,
|
||||
othervehicleparams,
|
||||
@@ -2417,6 +2450,8 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
|
||||
for( auto const &nameprefix : nameprefixes ) {
|
||||
init_sections( mdLowPolyInt, nameprefix, MoverParameters->CompartmentLights.start_type == start_t::manual );
|
||||
}
|
||||
// the inside of the door wings, if the interior has them
|
||||
init_interior_doors();
|
||||
}
|
||||
// destination sign
|
||||
if( mdModel ) {
|
||||
@@ -2561,6 +2596,26 @@ TDynamicObject::init_sections( TModel3d const *Model, std::string const &Namepre
|
||||
return sectioncount;
|
||||
}
|
||||
|
||||
// a door wing of the main model is seen from the outside, lit as the exterior. its namesake in the low poly interior,
|
||||
// if the model has one, follows its moves and is lit with the interior, by its compartment section if it's in one
|
||||
void
|
||||
TDynamicObject::init_interior_doors() {
|
||||
|
||||
if( mdLowPolyInt == nullptr ) { return; }
|
||||
|
||||
for( auto &animation : pAnimations ) {
|
||||
// the door animation is only set up for a wing found in the main model
|
||||
if( false == door_wings::is_wing( animation.iFlags ) ) { continue; }
|
||||
if( ( animation.yUpdate == nullptr ) || ( animation.smAnimated == nullptr ) ) { continue; }
|
||||
|
||||
auto *interiorwing { mdLowPolyInt->GetFromName( animation.smAnimated->pName ) };
|
||||
if( ( interiorwing == nullptr ) || ( interiorwing == animation.smAnimated ) ) { continue; }
|
||||
|
||||
interiorwing->WillBeAnimated();
|
||||
animation.smInterior = interiorwing;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
TDynamicObject::init_destination( TModel3d *Model ) {
|
||||
|
||||
@@ -5740,6 +5795,35 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
||||
}
|
||||
}
|
||||
|
||||
else if( token == "animslottedlever:" ) {
|
||||
// lever with a slot, turned by a pin on the coupling rod (e.g. speedometer drive)
|
||||
// parameters: submodel name, number of axle (from animwheelprefix) driving the coupling rod, crank radius [m],
|
||||
// pin position relative to the lever axis [m] and crank angle [deg] for wheel angle 0, in local (Y, Z) plane of the lever
|
||||
// angle is measured from Y axis towards Z axis, i.e. in the direction of rotation around X axis
|
||||
slottedlever_data lever;
|
||||
int axle { 1 };
|
||||
double crankradius { 0.0 };
|
||||
double crankangle { 0.0 };
|
||||
parser.getTokens( 6, false );
|
||||
parser
|
||||
>> asAnimName
|
||||
>> axle
|
||||
>> crankradius
|
||||
>> lever.pin.x
|
||||
>> lever.pin.y
|
||||
>> crankangle;
|
||||
lever.submodel = GetSubmodelFromName( mdModel, asAnimName );
|
||||
if( lever.submodel != nullptr ) {
|
||||
lever.submodel->WillBeAnimated();
|
||||
lever.axle = std::max( 0, axle - 1 );
|
||||
lever.crank = crankradius * glm::dvec2( std::cos( glm::radians( crankangle ) ), std::sin( glm::radians( crankangle ) ) );
|
||||
m_slottedlevers.emplace_back( lever );
|
||||
}
|
||||
else {
|
||||
ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model );
|
||||
}
|
||||
}
|
||||
|
||||
else if( token == "animdoorprefix:" ) {
|
||||
// nazwa animowanych drzwi
|
||||
int i, j;
|
||||
@@ -7198,7 +7282,8 @@ void TDynamicObject::RadioStop()
|
||||
if( Mechanik ) {
|
||||
// o ile ktoś go prowadzi
|
||||
if( MoverParameters->SecuritySystem.radiostop_available()
|
||||
&& MoverParameters->Radio ) {
|
||||
&& MoverParameters->Radio
|
||||
&& MoverParameters->RadioFuse ) {
|
||||
// jeśli pojazd ma RadioStop i jest on aktywny
|
||||
// HACK cast until math types unification
|
||||
glm::dvec3 pos = static_cast<glm::dvec3>(vPosition);
|
||||
@@ -7290,26 +7375,22 @@ void TDynamicObject::SetLights() {
|
||||
auto const isfrontcaboccupied { MoverParameters->CabOccupied * DirectionGet() >= 0 };
|
||||
int const automaticmarkers { MoverParameters->CabActive == 0 && MoverParameters->InactiveCabFlag & activation::redmarkers
|
||||
? light::redmarker_left + light::redmarker_right : 0 };
|
||||
int const front { ( isfrontcaboccupied ? end::front : end::rear ) };
|
||||
int const rear { 1 - front };
|
||||
auto const lightpos { MoverParameters->LightsPos - 1 };
|
||||
auto const frontlights { automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ front ][ lightpos ] };
|
||||
auto const rearlights { automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ rear ][ lightpos ] };
|
||||
std::array<int, 2> const cablights {
|
||||
automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::front ][ lightpos ],
|
||||
automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::rear ][ lightpos ] };
|
||||
// the custom position keeps the lights lit at coupled ends as well
|
||||
auto const ignorecouplings { MoverParameters->LightsPos == 18 };
|
||||
auto *vehicle { GetFirstDynamic( MoverParameters->CabOccupied >= 0 ? end::front : end::rear, coupling::control ) };
|
||||
while( vehicle != nullptr ) {
|
||||
// set lights on given side if there's no coupling with another vehicle, turn them off otherwise
|
||||
auto const *frontvehicle{(isfrontcaboccupied ? vehicle->Prev(coupling::coupler) : vehicle->Next(coupling::coupler))};
|
||||
auto const *rearvehicle{(isfrontcaboccupied ? vehicle->Next(coupling::coupler) : vehicle->Prev(coupling::coupler))};
|
||||
|
||||
if (MoverParameters->LightsPos == 18)
|
||||
{
|
||||
frontvehicle = nullptr;
|
||||
rearvehicle = nullptr;
|
||||
}
|
||||
|
||||
vehicle->RaLightsSet(
|
||||
frontvehicle == nullptr ? frontlights : 0,
|
||||
rearvehicle == nullptr ? rearlights : 0 );
|
||||
auto const iscoupled { [ vehicle, ignorecouplings ]( end const Side ) {
|
||||
return false == ignorecouplings
|
||||
&& ( vehicle->MoverParameters->Couplers[ Side ].CouplingFlag & coupling::coupler ) != 0
|
||||
&& vehicle->MoverParameters->Neighbours[ Side ].vehicle != nullptr; } };
|
||||
auto const lights { lights_programmer::vehicle_lights(
|
||||
cablights, isfrontcaboccupied, vehicle->iDirection, { iscoupled( end::front ), iscoupled( end::rear ) } ) };
|
||||
vehicle->RaLightsSet( lights.head, lights.rear );
|
||||
vehicle = isfrontcaboccupied ? vehicle->Next(coupling::control) : vehicle->Prev(coupling::control);
|
||||
}
|
||||
};
|
||||
@@ -7351,9 +7432,7 @@ void TDynamicObject::RaLightsSet(int head, int rear)
|
||||
bool tRight = MoverParameters->iLights[vehicleend] & (light::auxiliary_right | light::headlight_right); // a tu z prawej
|
||||
if (Controller == Humandriver) {
|
||||
|
||||
int ¤tDimPos = MoverParameters->modernDimmerPosition;
|
||||
auto &dimmerPositions = MoverParameters->dimPositions;
|
||||
TMoverParameters::dimPosition dps = dimmerPositions[currentDimPos];
|
||||
auto const dps{MoverParameters->currentDimPosition()};
|
||||
|
||||
// domyślnie
|
||||
HighBeamLights = false;
|
||||
@@ -7415,9 +7494,7 @@ void TDynamicObject::SetLightDimmings()
|
||||
if (Controller == Humandriver)
|
||||
{
|
||||
|
||||
int ¤tDimPos = MoverParameters->modernDimmerPosition;
|
||||
auto &dimmerPositions = MoverParameters->dimPositions;
|
||||
TMoverParameters::dimPosition dps = dimmerPositions[currentDimPos];
|
||||
auto const dps{MoverParameters->currentDimPosition()};
|
||||
|
||||
// domyślnie
|
||||
HighBeamLights = false;
|
||||
|
||||
Reference in New Issue
Block a user