diff --git a/rendering/common/locallights.cpp b/rendering/common/locallights.cpp index 524dbb6e4..e138be067 100644 --- a/rendering/common/locallights.cpp +++ b/rendering/common/locallights.cpp @@ -29,7 +29,6 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/Train.h" #include "simulation/simulation.h" #include "rendering/geometrybank.h" -#include "physics/vehicle.h" namespace { @@ -374,7 +373,7 @@ void gfx::local_lights::gather_vehicle(TDynamicObject *Vehicle, glm::dvec3 const { auto const &name{section.compartment->pName}; cabsection &= (name.size() >= 4) && name.starts_with("cab"); - auto const level{section.light_level * (cabsection ? 1.f : Vehicle->physics->CompartmentLights.intensity)}; + auto const level{section.light_level * (cabsection ? 1.f : Vehicle->CompartmentLightIntensity())}; if ((level <= 0.f) || (Global.fLuminance > section.compartment->fLight) || (section.compartment->iVisible == 0)) { continue; diff --git a/rendering/common/localshadows.cpp b/rendering/common/localshadows.cpp index 7e0d780c1..867473ed1 100644 --- a/rendering/common/localshadows.cpp +++ b/rendering/common/localshadows.cpp @@ -18,7 +18,6 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/DynObj.h" #include "vehicle/Train.h" #include "rendering/common/skyocclusion.h" -#include "physics/vehicle.h" namespace gfx { @@ -584,7 +583,7 @@ std::vector const &local_shadows::pick_headli if (std::max(beam.r, std::max(beam.g, beam.b)) <= 0.f) continue; // the part of the beam the shadows are cast in: from the end of the vehicle to the reach ahead of it - auto const &dimensions{light.owner->physics->Dim}; + auto const &dimensions{light.owner->Dimensions()}; auto const radius{range * 0.5 + std::max(dimensions.W, dimensions.H) + 2.0}; auto const centre{light.position + glm::dvec3{light.direction} * (range * 0.5 + 2.0)}; if (glm::length(centre - camera) - radius > range) diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp index de01564f4..515379f6b 100644 --- a/rendering/common/scenewalk.cpp +++ b/rendering/common/scenewalk.cpp @@ -30,7 +30,6 @@ http://mozilla.org/MPL/2.0/. #include "model/AnimModel.h" #include "model/Model3d.h" #include "rendering/common/skyocclusion.h" -#include "physics/vehicle.h" #include #include #include @@ -295,8 +294,8 @@ bool scene_walk::Render_coupler_adapter( TDynamicObject *Dynamic, float const Sq auto const position { glm::dvec3 { 0.f, - Dynamic->physics->Couplers[ End ].adapter_height, - ( Dynamic->physics->Couplers[ End ].adapter_length + Dynamic->physics->Dim.L * 0.5 ) * ( End == VehicleEnd::front ? 1 : -1 ) } }; + Dynamic->CouplerAdapterHeight( End ), + ( Dynamic->CouplerAdapterLength( End ) + Dynamic->Dimensions().L * 0.5 ) * ( End == VehicleEnd::front ? 1 : -1 ) } }; auto const angle { glm::vec3{ 0, diff --git a/rendering/common/screenreflections.cpp b/rendering/common/screenreflections.cpp index e519b21ff..c730d97bd 100644 --- a/rendering/common/screenreflections.cpp +++ b/rendering/common/screenreflections.cpp @@ -13,7 +13,6 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/DynObj.h" #include "gl/ubo.h" #include "utilities/Globals.h" -#include "physics/vehicle.h" namespace { @@ -60,7 +59,7 @@ void gfx::screen_reflections::begin_frame(glm::mat4 const &Projection, glm::dmat { m_reprojectioncab = glm::mat4{m_history.projection * glm::dmat4{m_history.view} * m_history.cab * glm::inverse(m_current.cab) * toworld}; // the vehicle stands on the origin of its model, along z, up to its height - auto const &dimensions{Cab->physics->Dim}; + auto const &dimensions{Cab->Dimensions()}; glm::dvec3 const lower{-0.5 * dimensions.W - CAB_BOX_MARGIN, -CAB_BOX_MARGIN, -0.5 * dimensions.L - CAB_BOX_MARGIN}; glm::dvec3 const upper{0.5 * dimensions.W + CAB_BOX_MARGIN, dimensions.H + CAB_BOX_MARGIN, 0.5 * dimensions.L + CAB_BOX_MARGIN}; auto const centre{0.5 * (lower + upper)}; diff --git a/rendering/common/windscreenwater.cpp b/rendering/common/windscreenwater.cpp index 619b6bf33..0a1746645 100644 --- a/rendering/common/windscreenwater.cpp +++ b/rendering/common/windscreenwater.cpp @@ -19,7 +19,6 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "vehicle/DynObj.h" #include "vehicle/Train.h" -#include "physics/vehicle.h" namespace gfx { @@ -340,7 +339,7 @@ void windscreen_water::update(double const Seconds) // the blades of the wipers of the vehicle, as the glasses read them (the channels of the mask follow the wipers of the cab // the vehicle is driven from) glm::vec4 blades{-1.f}; - if (auto const cabactive{vehicle->physics->CabActive}; cabactive != 0) + if (auto const cabactive{vehicle->ActiveCab()}; cabactive != 0) { auto const count{static_cast(vehicle->dWiperPos.size())}; for (int i = 0; i < 4; ++i) @@ -356,7 +355,7 @@ void windscreen_water::update(double const Seconds) auto const toworld{glm::dmat3{vehicle->mMatrix}}; auto const tomodel{glm::inverse(toworld)}; auto const up{glm::normalize(glm::vec3{tomodel * glm::dvec3{0.0, 1.0, 0.0}})}; - auto const air{glm::vec3{tomodel * (glm::dvec3{simulation::Environment.wind()} * WIND_SHARE - vehicle->VectorFront() * vehicle->physics->V)}}; + auto const air{glm::vec3{tomodel * (glm::dvec3{simulation::Environment.wind()} * WIND_SHARE - vehicle->VectorFront() * vehicle->Speed())}}; auto const heavy{std::clamp(Global.Overcast - 1.f, 0.f, 1.f)}; auto const snow{Global.Weather == "snow:"}; auto const fall{snow ? SNOW_FALL : RAIN_FALL}; diff --git a/rendering/lightarray.cpp b/rendering/lightarray.cpp index 01ff98ee0..bfa20349a 100644 --- a/rendering/lightarray.cpp +++ b/rendering/lightarray.cpp @@ -16,7 +16,6 @@ http://mozilla.org/MPL/2.0/. #include "stdafx.h" #include "rendering/lightarray.h" #include "vehicle/DynObj.h" -#include "physics/vehicle.h" void light_array::insert( TDynamicObject const *Owner ) { @@ -52,11 +51,10 @@ light_array::update() { light.direction.z = -light.direction.z; } // determine intensity of this light set - if( ( true == light.owner->physics->lowVoltage.Is24vAvailable() ) - || ( true == light.owner->physics->lowVoltage.Is110vAvailable() ) ) { + if( true == light.owner->LowVoltagePowered() ) { // with power on, the intensity depends on the state of activated switches // first we cross-check the list of enabled lights with the lights installed in the vehicle... - auto const lights { light.owner->physics->iLights[ light.index ] & light.owner->LightList( static_cast( light.index ) ) }; + auto const lights { light.owner->LightsSwitchedOn( static_cast( light.index ) ) & light.owner->LightList( static_cast( light.index ) ) }; // ...then check their individual state light.count = 0 + ( ( lights & light::headlight_left ) ? 1 : 0 ) @@ -70,18 +68,11 @@ light_array::update() { bool isEnabled = EndOf( light.index ) == VehicleEnd::front ? !light.owner->HeadlightsAoff : !light.owner->HeadlightsBoff; light.intensity = std::max(0.0f, std::log((float)light.count + 1.0f)); - if (light.owner->DimHeadlights && !light.owner->HighBeamLights && isEnabled) // tylko przyciemnione - light.intensity *= static_cast(light.owner->physics->dimMultiplier); - else if (!light.owner->DimHeadlights && !light.owner->HighBeamLights && isEnabled) // normalne - light.intensity *= static_cast(light.owner->physics->normMultiplier); - else if (light.owner->DimHeadlights && light.owner->HighBeamLights && isEnabled) // przyciemnione dlugie - light.intensity *= static_cast(light.owner->physics->highDimMultiplier); - else if (!light.owner->DimHeadlights && light.owner->HighBeamLights && isEnabled) // dlugie zwykle - light.intensity *= static_cast(light.owner->physics->highMultiplier); - else if (!isEnabled) - { + auto const multiplier{light.owner->HeadlightsMultiplier()}; + if (isEnabled) + light.intensity *= static_cast(multiplier); + else light.intensity = 0.0f; - } // TBD, TODO: intensity can be affected further by other factors light.state = { @@ -89,24 +80,9 @@ light_array::update() { ( ( lights & light::headlight_upper ) ? 1.f : 0.f ), ( ( lights & light::headlight_right | light::highbeamlight_right) ? 1.f : 0.f ) }; - light.color = { - static_cast(light.owner->physics->refR) / 255.0f, - static_cast(light.owner->physics->refG) / 255.0f, - static_cast(light.owner->physics->refB) / 255.0f - }; + light.color = light.owner->HeadlightsColor(); - if (light.owner->DimHeadlights && !light.owner->HighBeamLights) // tylko przyciemnione - light.state *= light.owner->physics->dimMultiplier; - else if (!light.owner->DimHeadlights && !light.owner->HighBeamLights) // normalne - light.state *= light.owner->physics->normMultiplier; - else if (light.owner->DimHeadlights && light.owner->HighBeamLights) // przyciemnione dlugie - light.state *= light.owner->physics->highDimMultiplier; - else if (!light.owner->DimHeadlights && light.owner->HighBeamLights) // dlugie zwykle - light.state *= light.owner->physics->highMultiplier; - else if (!isEnabled) - { - light.state = glm::vec3{0.f}; - } + light.state *= multiplier; } else { light.intensity = 0.0f; diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp index e1b65aa44..a79680f96 100644 --- a/rendering/opengl46/opengl46renderer.cpp +++ b/rendering/opengl46/opengl46renderer.cpp @@ -29,7 +29,6 @@ http://mozilla.org/MPL/2.0/. #include "rendering/opengl46/opengl46geometrybank.h" #include "rendering/screenshot.h" #include "rendering/editoroverlay.h" -#include "physics/vehicle.h" #include "vehicle/DynObj.h" #include @@ -1682,16 +1681,16 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode) // vehicle (V is along the front of the vehicle) glm::dvec3 air{glm::dvec3{simulation::Environment.wind()} * 0.5}; if (TDynamicObject const *owner = Global.pCamera.m_owner) - air -= owner->VectorFront() * owner->physics->V; + air -= owner->VectorFront() * owner->Speed(); scene_ubs.rain_wind = glm::vec4{glm::vec3{air}, 0.f}; } - if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->physics->CabActive) + if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->ActiveCab()) { for (int i = 0; i < 4; ++i) { if (i < owner->dWiperPos.size()) { - int index = owner->physics->CabActive > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; + int index = owner->ActiveCab() > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; scene_ubs.wiper_pos[i] = owner->dWiperPos[index]; if (owner->dWiperPos[index] > 0. && owner->wiperDirection[index]) { @@ -6761,7 +6760,7 @@ void opengl46_renderer::Render_lamp_shadow(std::size_t const Slot, bool const Ve void opengl46_renderer::Headlight_Projector(light_array::light_record const &Light, glm::dvec3 &Position, glm::mat3 &Rotation, glm::mat4 &Projection, float &Near, float &Fieldofview) { - auto const &ownerdimensions{Light.owner->physics->Dim}; + auto const &ownerdimensions{Light.owner->Dimensions()}; auto const up{static_cast(Light.owner->VectorUp())}; auto const size{static_cast(std::max(ownerdimensions.W, ownerdimensions.H) * 1.0)}; // ensure square ratio auto const cone{5.f}; diff --git a/rendering/particles.cpp b/rendering/particles.cpp index c0245be12..07e96d6b9 100644 --- a/rendering/particles.cpp +++ b/rendering/particles.cpp @@ -16,7 +16,6 @@ http://mozilla.org/MPL/2.0/. #include "simulation/simulationenvironment.h" #include "utilities/Logs.h" #include "vehicle/smoke.h" -#include "physics/vehicle.h" #include "vehicle/DynObj.h" @@ -346,22 +345,7 @@ smoke_source::launch_scales( float &Velocity, float &Opacity ) const { Opacity = 1.f; if( m_ownertype != owner_type::vehicle ) { return; } - Opacity = static_cast(m_owner.vehicle->physics->diesel.fill); - if (m_owner.vehicle->physics->EngineType == TEngineType::DieselElectric) - { - if (m_owner.vehicle->physics->diesel.spinningUp == true) - { - Velocity = static_cast(0.38*(((m_owner.vehicle->physics->enrot)/2)*0.5)); // / m_owner.vehicle->physics->diesel.fill *0.01)) ; - - } - else - { - - Velocity = static_cast((((m_owner.vehicle->physics->enrot)/60)*0.6) * (m_owner.vehicle->physics->EnginePower *0.03)); // / m_owner.vehicle->physics->diesel.fill *0.01)) ; - //Particle.velocity *= m_owner.vehicle->GetVelocity(); // / m_owner.vehicle->physics->diesel.fill *0.01)) ; - } - - } + m_owner.vehicle->ExhaustScales( Velocity, Opacity ); } // updates state of provided particle and bounding box. returns: true if particle is still alive afterwards, false otherwise diff --git a/rendering/vulkan14/vulkan14frame.cpp b/rendering/vulkan14/vulkan14frame.cpp index 1b802f3d5..b723551ca 100644 --- a/rendering/vulkan14/vulkan14frame.cpp +++ b/rendering/vulkan14/vulkan14frame.cpp @@ -32,7 +32,6 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Timer.h" #include "utilities/utilities.h" #include "utilities/color.h" -#include "physics/vehicle.h" #include @@ -1563,16 +1562,16 @@ void vulkan14_renderer::render_viewport(std::size_t const Index) // vehicle (V is along the front of the vehicle) glm::dvec3 air{glm::dvec3{simulation::Environment.wind()} * 0.5}; if (TDynamicObject const *owner = Global.pCamera.m_owner) - air -= owner->VectorFront() * owner->physics->V; + air -= owner->VectorFront() * owner->Speed(); scene_ubs.rain_wind = glm::vec4{glm::vec3{air}, 0.f}; } - if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->physics->CabActive) + if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->ActiveCab()) { for (int i = 0; i < 4; ++i) { if (i < owner->dWiperPos.size()) { - int index = owner->physics->CabActive > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; + int index = owner->ActiveCab() > 0 ? i : static_cast(owner->dWiperPos.size() - 1) - i; scene_ubs.wiper_pos[i] = owner->dWiperPos[index]; if (owner->dWiperPos[index] > 0. && owner->wiperDirection[index]) { @@ -4153,7 +4152,7 @@ void vulkan14_renderer::write_local_light(gl::light_element &Light, gfx::local_l void vulkan14_renderer::headlight_projector(light_array::light_record const &Light, glm::dvec3 &Position, glm::mat3 &Rotation, glm::mat4 &Projection, float &Near, float &Fieldofview) { - auto const &ownerdimensions{Light.owner->physics->Dim}; + auto const &ownerdimensions{Light.owner->Dimensions()}; auto const up{static_cast(Light.owner->VectorUp())}; auto const size{static_cast(std::max(ownerdimensions.W, ownerdimensions.H) * 1.0)}; auto const cone{5.f}; diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index 0e670f1d2..4566e17f0 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -902,6 +902,23 @@ public: double GetVelocity() const; double GetLength() const; double GetWidth() const; + // what the renderer reads of the physics of the vehicle (vehicle/dynamic/lights.cpp), so that it doesn't reach into it + TDimension const &Dimensions() const; + double Speed() const; // along the vehicle, signed [m/s] + int ActiveCab() const; // the cab the vehicle is driven from: 1 the front one, -1 the rear one, 0 none + float CompartmentLightIntensity() const; + double CouplerAdapterHeight( VehicleEnd End ) const; + double CouplerAdapterLength( VehicleEnd End ) const; + // the shares of the launch velocity and of the opacity of the smoke of the engine's exhaust, from the engine + void ExhaustScales( float &Velocity, float &Opacity ) const; + // the low voltage circuits have their power, for the lights + bool LowVoltagePowered() const; + // the lights switched on at an end, as the bits of light:: + int LightsSwitchedOn( VehicleEnd End ) const; + // the factor of the intensity of the headlights by the dimming and the high beam switches (DimHeadlights, HighBeamLights) + double HeadlightsMultiplier() const; + // the colour of the headlights, 0..1 + glm::vec3 HeadlightsColor() const; double radius() const; // calculates distance between event-starting axle and front of the vehicle double tracing_offset() const; diff --git a/vehicle/dynamic/lights.cpp b/vehicle/dynamic/lights.cpp index 663469aa9..8479de79f 100644 --- a/vehicle/dynamic/lights.cpp +++ b/vehicle/dynamic/lights.cpp @@ -250,3 +250,64 @@ bool TDynamicObject::has_signal_on( VehicleEnd const Side, int const Pattern ) c */ return physics->iLights[Side] == (Pattern & iInventory[Side]); } + +TDimension const &TDynamicObject::Dimensions() const { + return physics->Dim; +} + +double TDynamicObject::Speed() const { + return physics->V; +} + +int TDynamicObject::ActiveCab() const { + return physics->CabActive; +} + +float TDynamicObject::CompartmentLightIntensity() const { + return physics->CompartmentLights.intensity; +} + +double TDynamicObject::CouplerAdapterHeight( VehicleEnd const End ) const { + return physics->Couplers[ End ].adapter_height; +} + +double TDynamicObject::CouplerAdapterLength( VehicleEnd const End ) const { + return physics->Couplers[ End ].adapter_length; +} + +void TDynamicObject::ExhaustScales( float &Velocity, float &Opacity ) const { + Opacity = static_cast(physics->diesel.fill); + if (physics->EngineType == TEngineType::DieselElectric) + { + if (physics->diesel.spinningUp == true) + { + Velocity = static_cast(0.38*(((physics->enrot)/2)*0.5)); + } + else + { + Velocity = static_cast((((physics->enrot)/60)*0.6) * (physics->EnginePower *0.03)); + } + } +} + +bool TDynamicObject::LowVoltagePowered() const { + return ( true == physics->lowVoltage.Is24vAvailable() ) || ( true == physics->lowVoltage.Is110vAvailable() ); +} + +int TDynamicObject::LightsSwitchedOn( VehicleEnd const End ) const { + return physics->iLights[ End ]; +} + +double TDynamicObject::HeadlightsMultiplier() const { + if( DimHeadlights && !HighBeamLights ) { return physics->dimMultiplier; } // tylko przyciemnione + if( !DimHeadlights && !HighBeamLights ) { return physics->normMultiplier; } // normalne + if( DimHeadlights && HighBeamLights ) { return physics->highDimMultiplier; } // przyciemnione dlugie + return physics->highMultiplier; // dlugie zwykle +} + +glm::vec3 TDynamicObject::HeadlightsColor() const { + return { + static_cast(physics->refR) / 255.0f, + static_cast(physics->refG) / 255.0f, + static_cast(physics->refB) / 255.0f }; +}