diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 10a5b88f..8e477746 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -1393,7 +1393,7 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap { auto const AccSprev{AccS}; // przyspieszenie styczne - AccS = interpolate(AccSprev, FTotal / TotalMass, 0.5); + AccS = std::lerp(AccSprev, FTotal / TotalMass, 0.5); // std::clamp( dt * 3.0, 0.0, 1.0 ) ); // prawo Newtona ale z wygladzaniem (średnia z poprzednim) if (TestFlag(DamageFlag, dtrain_out)) @@ -1416,7 +1416,7 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap } // tangential acceleration, from velocity change - AccSVBased = interpolate(AccSVBased, (V - Vprev) / dt, std::clamp(dt * 3.0, 0.0, 1.0)); + AccSVBased = std::lerp(AccSVBased, (V - Vprev) / dt, std::clamp(dt * 3.0, 0.0, 1.0)); // vertical acceleration AccVert = (std::abs(AccVert) < 0.01 ? 0.0 : AccVert * 0.5); @@ -1490,7 +1490,7 @@ double TMoverParameters::FastComputeMovement(double dt, const TTrackShape &Shape { auto const AccSprev{AccS}; // przyspieszenie styczne - AccS = interpolate(AccSprev, FTotal / TotalMass, 0.5); + AccS = std::lerp(AccSprev, FTotal / TotalMass, 0.5); // std::clamp( dt * 3.0, 0.0, 1.0 ) ); // prawo Newtona ale z wygladzaniem (średnia z poprzednim) if (TestFlag(DamageFlag, dtrain_out)) @@ -2098,7 +2098,7 @@ void TMoverParameters::HeatingCheck(double const Timestep) absrevolutions < generator.revolutions_min ? generator.voltage_min * absrevolutions / generator.revolutions_min : // absrevolutions > generator.revolutions_max ? generator.voltage_max * absrevolutions / generator.revolutions_max : - interpolate(generator.voltage_min, generator.voltage_max, + std::lerp(generator.voltage_min, generator.voltage_max, std::clamp((absrevolutions - generator.revolutions_min) / (generator.revolutions_max - generator.revolutions_min), 0.0, 1.0))) * sign(generator.revolutions); } @@ -2208,7 +2208,7 @@ void TMoverParameters::OilPumpCheck(double const Timestep) auto const minpressure{OilPump.pressure_minimum > 0.f ? OilPump.pressure_minimum : 0.15f}; // arbitrary fallback value OilPump.pressure_target = ( - enrot > 0.1 ? interpolate( minpressure, OilPump.pressure_maximum, static_cast( EngineRPMRatio() ) ) * OilPump.resource_amount : + enrot > 0.1 ? std::lerp( minpressure, OilPump.pressure_maximum, static_cast( EngineRPMRatio() ) ) * OilPump.resource_amount : true == OilPump.is_active ? std::min( minpressure + 0.1f, OilPump.pressure_maximum ) : // slight pressure margin to give time to switch off the pump and start the engine 0.f ); @@ -5950,7 +5950,7 @@ double TMoverParameters::TractionForce(double dt) // power curve drop // NOTE: disabled for the time being due to side-effects if( ( tmpV > 1 ) && ( EnginePower < tmp ) ) { - Ft = interpolate( + Ft = std::lerp( Ft, EnginePower / tmp, std::clamp( tmpV - 1.0, 0.0, 1.0 ) ); } @@ -8166,9 +8166,9 @@ void TMoverParameters::dizel_Heat(double const dt) auto const revolutionsfactor{EngineRPMRatio()}; auto const waterpump{WaterPump.is_active ? 1 : 0}; - auto const gw = engineon * interpolate(gwmin, gwmax, revolutionsfactor) + waterpump * 1000 + engineoff * 200; - auto const gw2 = engineon * interpolate(gwmin2, gwmax2, revolutionsfactor) + waterpump * 1000 + engineoff * 200; - auto const gwO = interpolate(gwmin, gwmax, revolutionsfactor); + auto const gw = engineon * std::lerp(gwmin, gwmax, revolutionsfactor) + waterpump * 1000 + engineoff * 200; + auto const gw2 = engineon * std::lerp(gwmin2, gwmax2, revolutionsfactor) + waterpump * 1000 + engineoff * 200; + auto const gwO = std::lerp(gwmin, gwmax, revolutionsfactor); dizel_heat.water.is_cold = ((dizel_heat.water.config.temp_min > 0) && (dizel_heat.temperatura1 < dizel_heat.water.config.temp_min - (Mains ? 5 : 0))); dizel_heat.water.is_hot = ((dizel_heat.water.config.temp_max > 0) && (dizel_heat.temperatura1 > dizel_heat.water.config.temp_max - (dizel_heat.water.is_hot ? 8 : 0))); diff --git a/audio/audiorenderer.cpp b/audio/audiorenderer.cpp index ba0afe4c..f8a1ffed 100644 --- a/audio/audiorenderer.cpp +++ b/audio/audiorenderer.cpp @@ -191,7 +191,7 @@ openal_source::sync_with( sound_properties const &State ) { // adjust the volume to a suitable fraction of nominal value auto const fadedistance { sound_range * 0.75f }; auto const rangefactor { - interpolate( + std::lerp( 1.f, 0.f, std::clamp( ( distancesquared - rangesquared ) / ( fadedistance * fadedistance ), 0.f, 1.f ) ) }; diff --git a/audio/sound.cpp b/audio/sound.cpp index d7670d41..59130232 100644 --- a/audio/sound.cpp +++ b/audio/sound.cpp @@ -781,7 +781,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { // based on how far the current soundpoint is in the range of previous chunk auto const &previouschunkdata{ m_soundchunks[ chunkindex - 1 ].second }; m_properties.pitch = - interpolate( + std::lerp( previouschunkdata.pitch / chunkdata.pitch, 1.f, std::clamp( @@ -796,7 +796,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { // based on how far the current soundpoint is in the range of this chunk auto const &nextchunkdata { m_soundchunks[ chunkindex + 1 ].second }; m_properties.pitch = - interpolate( + std::lerp( 1.f, nextchunkdata.pitch / chunkdata.pitch, std::clamp( @@ -816,7 +816,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { auto const fadeinwidth { chunkdata.threshold - chunkdata.fadein }; if( soundpoint < chunkdata.threshold ) { float lineargain = - interpolate( + std::lerp( 0.f, 1.f, std::clamp( ( soundpoint - chunkdata.fadein ) / fadeinwidth, @@ -836,7 +836,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { auto const fadeoutstart { chunkdata.fadeout - fadeoutwidth }; if( soundpoint > fadeoutstart ) { float lineargain = - interpolate( + std::lerp( 0.f, 1.f, std::clamp( ( soundpoint - fadeoutstart ) / fadeoutwidth, diff --git a/environment/skydome.cpp b/environment/skydome.cpp index 8c2e465d..178a445e 100644 --- a/environment/skydome.cpp +++ b/environment/skydome.cpp @@ -186,7 +186,7 @@ float CSkyDome::PerezFunctionO2( float Perezcoeffs[ 5 ], const float Icostheta, void CSkyDome::RebuildColors() { float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f; - auto gammacorrection = interpolate( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor ); + auto gammacorrection = glm::mix( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor ); // get zenith luminance float const chi = ( (4.0f / 9.0f) - (m_turbidity / 120.0f) ) * ( M_PI - (2.0f * m_thetasun) ); @@ -243,7 +243,7 @@ void CSkyDome::RebuildColors() { float const yclear = std::max( 0.01f, PerezFunctionO2( perezluminance, icostheta, gamma, cosgamma2, zenithluminance ) ); float const yover = std::max( 0.01f, zenithluminance * ( 1.0f + 2.0f * vertex.y ) / 3.0f ); - float const Y = interpolate( yclear, yover, m_overcast ); + float const Y = std::lerp( yclear, yover, m_overcast ); float const X = (x / y) * Y; float const Z = ((1.0f - x - y) / y) * Y; @@ -276,14 +276,14 @@ void CSkyDome::RebuildColors() { // correction is applied in linear manner from the bottom, becomes fully in effect for vertices with y = 0.50 auto const heightbasedphase = std::clamp( vertex.y * 2.0f, 0.0f, 1.0f ); // this height-based factor is reduced the farther the sun is up in the sky - float const shiftfactor = std::clamp( interpolate(heightbasedphase, sunbasedphase, sunbasedphase), 0.0f, 1.0f ); + float const shiftfactor = std::clamp( std::lerp(heightbasedphase, sunbasedphase, sunbasedphase), 0.0f, 1.0f ); // h = 210 makes for 'typical' sky tone shiftedcolor = glm::vec3( 210.0f, colorconverter.y, colorconverter.z ); shiftedcolor = colors::HSVtoRGB( shiftedcolor ); color = colors::HSVtoRGB(colorconverter); - color = interpolate( color, shiftedcolor, shiftfactor * Global.m_skyhuecorrection ); + color = glm::mix( color, shiftedcolor, shiftfactor * Global.m_skyhuecorrection ); // crude correction for the times where the model breaks (late night) // TODO: use proper night sky calculation for these times instead diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index 1e115690..f5a67108 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -164,10 +164,10 @@ drivermouse_input::init() { #ifdef _WIN32 DWORD systemkeyboardspeed; ::SystemParametersInfo( SPI_GETKEYBOARDSPEED, 0, &systemkeyboardspeed, 0 ); - m_updaterate = interpolate( 0.5, 0.04, systemkeyboardspeed / 31.0 ); + m_updaterate = std::lerp( 0.5, 0.04, systemkeyboardspeed / 31.0 ); DWORD systemkeyboarddelay; ::SystemParametersInfo( SPI_GETKEYBOARDDELAY, 0, &systemkeyboarddelay, 0 ); - m_updatedelay = interpolate( 0.25, 1.0, systemkeyboarddelay / 3.0 ); + m_updatedelay = std::lerp( 0.25, 1.0, systemkeyboarddelay / 3.0 ); #endif default_bindings(); diff --git a/input/gamepadinput.cpp b/input/gamepadinput.cpp index 1eea53f3..93453d89 100644 --- a/input/gamepadinput.cpp +++ b/input/gamepadinput.cpp @@ -41,7 +41,7 @@ glm::vec2 circle_to_square( glm::vec2 const &Point, int const Roundness = 0 ) { // Find the inner-roundness scaling factor and LERP auto const length = glm::length( Point ); auto const factor = std::pow( length, Roundness ); - return interpolate( Point, squared, (float)factor ); + return glm::mix( Point, squared, (float)factor ); } bool diff --git a/model/vertex.h b/model/vertex.h index 28b63b69..316102a6 100644 --- a/model/vertex.h +++ b/model/vertex.h @@ -19,6 +19,11 @@ struct world_vertex { glm::vec3 normal; glm::vec2 texture; + static world_vertex lerp(world_vertex const &a, world_vertex const &b, double factor) + { + return static_cast((a * (1.0f - factor)) + (b * factor)); + } + // overloads // operator+ template @@ -55,7 +60,7 @@ struct world_vertex { void set_half( world_vertex const &Vertex1, world_vertex const &Vertex2 ) { *this = - interpolate( + world_vertex::lerp( Vertex1, Vertex2, 0.5 ); } @@ -63,7 +68,7 @@ struct world_vertex { void set_from_x( world_vertex const &Vertex1, world_vertex const &Vertex2, double const X ) { *this = - interpolate( + world_vertex::lerp( Vertex1, Vertex2, ( X - Vertex1.position.x ) / ( Vertex2.position.x - Vertex1.position.x ) ); } @@ -71,7 +76,7 @@ struct world_vertex { void set_from_z( world_vertex const &Vertex1, world_vertex const &Vertex2, double const Z ) { *this = - interpolate( + world_vertex::lerp( Vertex1, Vertex2, ( Z - Vertex1.position.z ) / ( Vertex2.position.z - Vertex1.position.z ) ); } diff --git a/rendering/opengl33renderer.cpp b/rendering/opengl33renderer.cpp index 675c2849..af9420b9 100644 --- a/rendering/opengl33renderer.cpp +++ b/rendering/opengl33renderer.cpp @@ -1915,7 +1915,7 @@ bool opengl33_renderer::Render(world_environment *Environment) auto const fogfactor{std::clamp(Global.fFogEnd / 2000.f, 0.f, 1.f)}; // stronger fog reduces opacity of the celestial bodies float const duskfactor = 1.0f - std::clamp(std::abs(Environment->m_sun.getAngle()), 0.0f, 12.0f) / 12.0f; - glm::vec3 suncolor = interpolate(glm::vec3(255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f), glm::vec3(235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f), duskfactor); + glm::vec3 suncolor = glm::mix(glm::vec3(255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f), glm::vec3(235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f), duskfactor); // sun { @@ -1923,7 +1923,7 @@ bool opengl33_renderer::Render(world_environment *Environment) glm::vec4 color(suncolor.x, suncolor.y, suncolor.z, std::clamp(1.5f - Global.Overcast, 0.f, 1.f) * fogfactor); auto const sunvector = Environment->m_sun.getDirection(); - /*float const size = interpolate( // TODO: expose distance/scale factor from the moon object + /*float const size = std::lerp( // TODO: expose distance/scale factor from the moon object 0.0325f, 0.0275f, std::clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f );*/ @@ -2000,7 +2000,7 @@ bool opengl33_renderer::Render(world_environment *Environment) } /* - float const size = interpolate( // TODO: expose distance/scale factor from the moon object + float const size = std::lerp( // TODO: expose distance/scale factor from the moon object 0.0160f, 0.0135f, std::clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f );*/ @@ -2044,7 +2044,7 @@ bool opengl33_renderer::Render(world_environment *Environment) m_sunlight.apply_intensity(); // calculate shadow tone, based on positions of celestial bodies - m_shadowcolor = interpolate(glm::vec4{colors::shadow}, glm::vec4{colors::white}, std::clamp(-Environment->m_sun.getAngle(), 0.f, 6.f) / 6.f); + m_shadowcolor = glm::mix(glm::vec4{colors::shadow}, glm::vec4{colors::white}, std::clamp(-Environment->m_sun.getAngle(), 0.f, 6.f) / 6.f); if ((Environment->m_sun.getAngle() < -18.f) && (Environment->m_moon.getAngle() > 0.f)) { // turn on moon shadows after nautical twilight, if the moon is actually up @@ -3715,7 +3715,7 @@ void opengl33_renderer::Render_precipitation() ::glRotated(m_precipitationrotation, 0.0, 1.0, 0.0); model_ubs.set_modelview(OpenGLMatrices.data(GL_MODELVIEW)); - model_ubs.param[0] = interpolate(0.5f * (Global.DayLight.diffuse + Global.DayLight.ambient), colors::white, 0.5f * std::clamp((float)Global.fLuminance, 0.f, 1.f)); + model_ubs.param[0] = glm::mix(0.5f * (Global.DayLight.diffuse + Global.DayLight.ambient), colors::white, 0.5f * std::clamp((float)Global.fLuminance, 0.f, 1.f)); model_ubs.param[1].x = simulation::Environment.m_precipitation.get_textureoffset(); model_ubo->update(model_ubs); @@ -4161,7 +4161,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel) // NOTE: we're forced here to redo view angle calculations etc, because this data isn't instanced but stored along with the single mesh // TODO: separate instance data from reusable geometry auto const &modelview = OpenGLMatrices.data(GL_MODELVIEW); - auto const lightcenter = modelview * interpolate(glm::vec4(0.f, 0.f, -0.05f, 1.f), glm::vec4(0.f, 0.f, -0.25f, 1.f), + auto const lightcenter = modelview * glm::mix(glm::vec4(0.f, 0.f, -0.05f, 1.f), glm::vec4(0.f, 0.f, -0.25f, 1.f), static_cast(TSubModel::fSquareDist / Submodel->fSquareMaxDist)); // pozycja punktu świecącego względem kamery Submodel->fCosViewAngle = glm::dot(glm::normalize(modelview * glm::vec4(0.f, 0.f, -1.f, 1.f) - lightcenter), glm::normalize(-lightcenter)); @@ -4236,7 +4236,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel) // additionally reduce light strength for farther sources in rain or snow if (Global.Overcast > 0.75f) { - float const precipitationfactor{interpolate(interpolate(1.f, 0.25f, std::clamp(Global.Overcast * 0.75f - 0.5f, 0.f, 1.f)), 1.f, distancefactor)}; + float const precipitationfactor{std::lerp(std::lerp(1.f, 0.25f, std::clamp(Global.Overcast * 0.75f - 0.5f, 0.f, 1.f)), 1.f, distancefactor)}; lightlevel *= precipitationfactor; } @@ -4263,7 +4263,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel) if (Global.Overcast > 1.0f) { // fake fog halo - float const fogfactor{interpolate(1.5f, 1.f, std::clamp(Global.fFogEnd / 2000, 0.f, 1.f)) * std::max(1.f, Global.Overcast)}; + float const fogfactor{std::lerp(1.5f, 1.f, std::clamp(Global.fFogEnd / 2000, 0.f, 1.f)) * std::max(1.f, Global.Overcast)}; model_ubs.param[1].x = pointsize * fogfactor * 4.0f; model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * std::min(1.f, lightlevel) * 0.5f); diff --git a/rendering/openglrenderer.cpp b/rendering/openglrenderer.cpp index d91eb8fc..e0bdbca8 100644 --- a/rendering/openglrenderer.cpp +++ b/rendering/openglrenderer.cpp @@ -1507,7 +1507,7 @@ bool opengl_renderer::Render( world_environment *Environment ) { // calculate shadow tone, based on positions of celestial bodies - m_shadowcolor = interpolate( + m_shadowcolor = glm::mix( glm::vec4{ colors::shadow }, glm::vec4{ colors::white }, std::clamp( -Environment->m_sun.getAngle(), 0.f, 6.f ) / 6.f ); @@ -1570,7 +1570,7 @@ opengl_renderer::Render( world_environment *Environment ) { auto const fogfactor { std::clamp( Global.fFogEnd / 2000.f, 0.f, 1.f ) }; // closer/denser fog reduces opacity of the celestial bodies float const duskfactor = 1.0f - std::clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f; - glm::vec3 suncolor = interpolate( + glm::vec3 suncolor = glm::mix( glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ), glm::vec3( 235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f ), duskfactor ); @@ -1586,7 +1586,7 @@ opengl_renderer::Render( world_environment *Environment ) { ::glLoadIdentity(); // macierz jedynkowa ::glTranslatef( sunposition.x, sunposition.y, sunposition.z ); // początek układu zostaje bez zmian - float const size = interpolate( // TODO: expose distance/scale factor from the moon object + float const size = std::lerp( // TODO: expose distance/scale factor from the moon object 0.0325f, 0.0275f, std::clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f ); @@ -1619,7 +1619,7 @@ opengl_renderer::Render( world_environment *Environment ) { ::glLoadIdentity(); // macierz jedynkowa ::glTranslatef( moonposition.x, moonposition.y, moonposition.z ); - float const size = interpolate( // TODO: expose distance/scale factor from the moon object + float const size = std::lerp( // TODO: expose distance/scale factor from the moon object 0.0160f, 0.0135f, std::clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f ); @@ -1662,8 +1662,8 @@ opengl_renderer::Render( world_environment *Environment ) { ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( - interpolate( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f ) - * interpolate( 1.f, 0.35f, Global.Overcast / 2.f ) // overcast darkens the clouds + glm::mix( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f ) + * std::lerp( 1.f, 0.35f, Global.Overcast / 2.f ) // overcast darkens the clouds * 0.5f // arbitrary adjustment factor ) ); // render @@ -2911,7 +2911,7 @@ opengl_renderer::Render( TSubModel *Submodel ) { auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW ); auto const lightcenter = modelview - * interpolate( + * glm::mix( glm::vec4( 0.f, 0.f, -0.05f, 1.f ), glm::vec4( 0.f, 0.f, -0.25f, 1.f ), static_cast( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery @@ -2933,8 +2933,8 @@ opengl_renderer::Render( TSubModel *Submodel ) { // additionally reduce light strength for farther sources in rain or snow if( Global.Overcast > 0.75f ) { float const precipitationfactor{ - interpolate( - interpolate( 1.f, 0.25f, std::clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ), + std::lerp( + std::lerp( 1.f, 0.25f, std::clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ), 1.f, distancefactor ) }; lightlevel *= precipitationfactor; @@ -2968,7 +2968,7 @@ opengl_renderer::Render( TSubModel *Submodel ) { if( Global.Overcast > 1.f ) { // fake fog halo float const fogfactor { - interpolate( + std::lerp( 2.f, 1.f, std::clamp( Global.fFogEnd / 2000, 0.f, 1.f ) ) * std::max( 1.f, Global.Overcast ) }; @@ -3343,7 +3343,7 @@ opengl_renderer::Render_precipitation() { // ::glColor4fv( glm::value_ptr( glm::vec4( glm::min( glm::vec3( Global.fLuminance ), glm::vec3( 1 ) ), 1 ) ) ); ::glColor4fv( glm::value_ptr( - interpolate( + glm::mix( 0.5f * ( Global.DayLight.diffuse + Global.DayLight.ambient ), colors::white, 0.5f * std::clamp( (float)Global.fLuminance, 0.f, 1.f ) ) ) ); @@ -3935,7 +3935,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) { auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW ); auto const lightcenter = modelview - * interpolate( + * glm::mix( glm::vec4( 0.f, 0.f, -0.05f, 1.f ), glm::vec4( 0.f, 0.f, -0.10f, 1.f ), static_cast( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery diff --git a/rendering/openglskydome.cpp b/rendering/openglskydome.cpp index cc689a05..58951f17 100644 --- a/rendering/openglskydome.cpp +++ b/rendering/openglskydome.cpp @@ -60,7 +60,7 @@ void opengl_skydome::update() { auto &colors{ skydome.colors() }; /* float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f; - auto gamma = interpolate( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor ); + auto gamma = std::lerp( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor ); for( auto & color : colors ) { color = glm::pow( color, gamma ); } diff --git a/rendering/particles.cpp b/rendering/particles.cpp index 7155eab0..12eaa737 100644 --- a/rendering/particles.cpp +++ b/rendering/particles.cpp @@ -282,7 +282,7 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) { } // determine bounding area from calculated bounding box if( false == m_particles.empty() ) { - m_area.center = interpolate( boundingbox[ value_limit::min ], boundingbox[ value_limit::max ], 0.5 ); + m_area.center = glm::mix(boundingbox[value_limit::min], boundingbox[value_limit::max], 0.5); m_area.radius = 0.5 * ( glm::length( boundingbox[ value_limit::max ] - boundingbox[ value_limit::min ] ) ); } else { diff --git a/scene/scenenode.cpp b/scene/scenenode.cpp index fcd6b450..784fb14f 100644 --- a/scene/scenenode.cpp +++ b/scene/scenenode.cpp @@ -434,7 +434,7 @@ shape_node::merge( shape_node &Shape ) { } // add geometry from provided node m_data.area.center = - interpolate( + glm::mix( m_data.area.center, Shape.m_data.area.center, static_cast( Shape.m_data.vertices.size() ) / ( Shape.m_data.vertices.size() + m_data.vertices.size() ) ); m_data.vertices.insert( @@ -659,7 +659,7 @@ lines_node::merge( lines_node &Lines ) { } // add geometry from provided node m_data.area.center = - interpolate( + glm::mix( m_data.area.center, Lines.m_data.area.center, static_cast( Lines.m_data.vertices.size() ) / ( Lines.m_data.vertices.size() + m_data.vertices.size() ) ); m_data.vertices.insert( diff --git a/simulation/simulationenvironment.cpp b/simulation/simulationenvironment.cpp index e1c2138f..0f5548be 100644 --- a/simulation/simulationenvironment.cpp +++ b/simulation/simulationenvironment.cpp @@ -128,7 +128,7 @@ world_environment::update() { m_skydome.SetTurbidity( 2.25f + std::clamp( Global.Overcast, 0.f, 1.f ) - + interpolate( 0.f, 1.f, std::clamp( twilightfactor * 1.5f, 0.f, 1.f ) ) ); + + std::lerp( 0.f, 1.f, std::clamp( twilightfactor * 1.5f, 0.f, 1.f ) ) ); m_skydome.SetOvercastFactor( Global.Overcast ); m_skydome.Update( m_sun.getDirection() ); @@ -156,7 +156,7 @@ world_environment::update() { m_lightintensity = 1.0f; // include 'golden hour' effect in twilight lighting float const duskfactor = 1.25f - std::clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f; - keylightcolor = interpolate( + keylightcolor = glm::mix( glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ), glm::vec3( 235.0f / 255.0f, 120.0f / 255.0f, 36.0f / 255.0f ), duskfactor ); @@ -172,7 +172,7 @@ world_environment::update() { // but whether it'd _look_ better is something to be tested auto const intensity = std::min( 1.15f * ( 0.05f + keylightintensity + skydomehsv.z ), 1.25f ); // the impact of sun component is reduced proportionally to overcast level, as overcast increases role of ambient light - auto const diffuselevel = interpolate( keylightintensity, intensity * ( 1.0f - twilightfactor ), 1.0f - std::min( 1.f, Global.Overcast ) * 0.75f ); + auto const diffuselevel = std::lerp( keylightintensity, intensity * ( 1.0f - twilightfactor ), 1.0f - std::min( 1.f, Global.Overcast ) * 0.75f ); // ...update light colours and intensity. keylightcolor = keylightcolor * diffuselevel; Global.DayLight.diffuse = glm::vec4( keylightcolor, Global.DayLight.diffuse.a ); @@ -182,9 +182,9 @@ world_environment::update() { // (this is pure conjecture, aimed more to 'look right' than be accurate) float const ambienttone = std::clamp( 1.0f - ( Global.SunAngle / 90.0f ), 0.0f, 1.0f ); float const ambientintensitynightfactor = 1.f - 0.75f * std::clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f; - Global.DayLight.ambient[ 0 ] = interpolate( skydomehsv.z, skydomecolour.r, ambienttone ) * ambientintensitynightfactor; - Global.DayLight.ambient[ 1 ] = interpolate( skydomehsv.z, skydomecolour.g, ambienttone ) * ambientintensitynightfactor; - Global.DayLight.ambient[ 2 ] = interpolate( skydomehsv.z, skydomecolour.b, ambienttone ) * ambientintensitynightfactor; + Global.DayLight.ambient[ 0 ] = std::lerp( skydomehsv.z, skydomecolour.r, ambienttone ) * ambientintensitynightfactor; + Global.DayLight.ambient[ 1 ] = std::lerp( skydomehsv.z, skydomecolour.g, ambienttone ) * ambientintensitynightfactor; + Global.DayLight.ambient[ 2 ] = std::lerp( skydomehsv.z, skydomecolour.b, ambienttone ) * ambientintensitynightfactor; Global.fLuminance = intensity; diff --git a/utilities/utilities.h b/utilities/utilities.h index 23ba31be..b0ad2e61 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -299,18 +299,6 @@ template T min_speed(T const Left, T const Right) return std::min(Left, Right); } -template Type_ interpolate(Type_ const &First, Type_ const &Second, float const Factor) -{ - - return static_cast((First * (1.0f - Factor)) + (Second * Factor)); -} - -template Type_ interpolate(Type_ const &First, Type_ const &Second, double const Factor) -{ - - return static_cast((First * (1.0 - Factor)) + (Second * Factor)); -} - template Type_ smoothInterpolate(Type_ const &First, Type_ const &Second, double Factor) { // Apply smoothing (ease-in-out quadratic) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 709e866d..57aeeaeb 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -935,7 +935,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN if( brakingdistance > 0.0 ) { // maintain desired acc while we have enough room to brake safely, when close enough start paying attention // try to make a smooth transition instead of sharp change - a = interpolate( a, AccPreferred, std::clamp( ( d - brakingdistance ) / brakingdistance, 0.0, 1.0 ) ); + a = std::lerp( a, AccPreferred, std::clamp( ( d - brakingdistance ) / brakingdistance, 0.0, 1.0 ) ); } } if( ( d < fMinProximityDist ) @@ -1740,7 +1740,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const { && ( Targetvelocity == 0.f ) ) { auto const multiplier { std::clamp( 1.f + iVehicles * 0.5f, 2.f, 4.f ) }; return ( - interpolate( + std::lerp( multiplier, 1.f, static_cast( mvOccupied->Vel / 40.0 ) ) * frictionmultiplier ); @@ -1750,7 +1750,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const { && ( ( true == IsCargoTrain ) || ( fAccGravity > 0.025 ) ) ) { return ( - interpolate( + std::lerp( 1.f, 2.f, std::clamp( ( fBrake_a0[ 1 ] - 0.2 ) / 0.2, @@ -1762,7 +1762,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const { } // stretch the braking distance up to 3 times; the lower the speed, the greater the stretch return ( - interpolate( + std::lerp( 3.f, 1.f, ( Targetvelocity - 5.f ) / 60.f ) * frictionmultiplier ); @@ -3180,7 +3180,7 @@ bool TController::IncBrake() auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos }; auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax ) }; mvOccupied->BrakeLevelSet( - interpolate( + std::lerp( mvOccupied->Handle->GetPos( bh_EPR ), mvOccupied->Handle->GetPos( bh_EPB ), std::clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); @@ -3312,7 +3312,7 @@ bool TController::DecBrake() { auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos }; auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax ) }; mvOccupied->BrakeLevelSet( - interpolate( + std::lerp( mvOccupied->Handle->GetPos( bh_EPR ), mvOccupied->Handle->GetPos( bh_EPB ), std::clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); @@ -3454,7 +3454,7 @@ bool TController::IncSpeed() auto const minvoltage { ( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? mvPantographUnit->EnginePowerSource.CollectorParameters.MinV : 0.0 ) }; auto const maxvoltage { ( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? mvPantographUnit->EnginePowerSource.CollectorParameters.MaxV : 0.0 ) }; auto const seriesmodevoltage { - interpolate( + std::lerp( minvoltage, maxvoltage, ( IsHeavyCargoTrain ? 0.35 : 0.40 ) ) }; @@ -6447,7 +6447,7 @@ TController::control_handles() { } // if the power station is heavily burdened drop down to series mode to reduce the load auto const useseriesmodevoltage { - interpolate( + std::lerp( mvControlling->EnginePowerSource.CollectorParameters.MinV, mvControlling->EnginePowerSource.CollectorParameters.MaxV, ( IsHeavyCargoTrain ? 0.35 : 0.40 ) ) }; @@ -7768,7 +7768,7 @@ TController::adjust_desired_speed_for_current_speed() { // stop accelerating when close enough to target speed AccDesired = std::min( AccDesired, // but don't override decceleration for VelNext - interpolate( // ease off as you close to the target velocity + std::lerp( // ease off as you close to the target velocity EU07_AI_NOACCELERATION, AccPreferred, std::clamp( VelDesired - speedestimate, 0.0, fVelMinus ) / fVelMinus ) ); } diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index ae298980..0b64368e 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -724,7 +724,7 @@ void TDynamicObject::UpdatePlatformTranslate( TAnim *pAnim ) { pAnim->smAnimated->SetTranslate( glm::vec3{ - interpolate( 0.f, MoverParameters->Doors.step_range, door.step_position ), + std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ), 0.0, 0.0 } ); } @@ -741,7 +741,7 @@ void TDynamicObject::UpdatePlatformRotate( TAnim *pAnim ) { pAnim->smAnimated->SetRotate( float3( 0, 1, 0 ), - interpolate( 0.f, MoverParameters->Doors.step_range, door.step_position ) ); + std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ) ); } // mirror animation, rotate @@ -758,11 +758,11 @@ void TDynamicObject::UpdateMirror( TAnim *pAnim ) { if( pAnim->iNumber & 1 ) pAnim->smAnimated->SetRotate( float3( 0, 1, 0 ), - interpolate( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveR * isactive ) ); + std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveR * isactive ) ); else pAnim->smAnimated->SetRotate( float3( 0, 1, 0 ), - interpolate( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveL * isactive ) ); + std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveL * isactive ) ); } // wipers @@ -2753,7 +2753,7 @@ void TDynamicObject::Move(double fDistance) case e_tunnel: { shadefrom = 0.2f; break; } default: {break; } } - fShade = interpolate( shadefrom, shadeto, static_cast( d ) ); + fShade = std::lerp( shadefrom, shadeto, static_cast( d ) ); /* switch (t0->eEnvironment) { // typ zmiany oświetlenia - zakładam, że @@ -3076,7 +3076,7 @@ TDynamicObject::update_load_offset() { 0.0 : 100.0 * MoverParameters->LoadAmount / MoverParameters->MaxLoad ) }; - LoadOffset = interpolate( MoverParameters->LoadType.offset_min, 0.f, std::clamp( 0.0, 1.0, loadpercentage * 0.01 ) ); + LoadOffset = std::lerp( MoverParameters->LoadType.offset_min, 0.f, std::clamp( 0.0, 1.0, loadpercentage * 0.01 ) ); } void @@ -3683,7 +3683,7 @@ bool TDynamicObject::Update(double dt, double dt1) if( MoverParameters->Vel > 0 ) { // TODO: track quality and/or environment factors as separate subroutine auto volume = - interpolate( + std::lerp( 0.8, 1.2, std::clamp( MyTrack->iQualityFlag / 10.0, @@ -4634,7 +4634,7 @@ void TDynamicObject::RenderSounds() { m_emergencybrakeflow = ( m_emergencybrakeflow == 0.0 ? MoverParameters->EmergencyValveFlow : - interpolate( m_emergencybrakeflow, MoverParameters->EmergencyValveFlow, 0.1 ) ); + std::lerp( m_emergencybrakeflow, MoverParameters->EmergencyValveFlow, 0.1 ) ); // scale volume based on the flow rate and on the pressure in the main pipe auto const flowpressure { std::clamp( m_emergencybrakeflow, 0.0, 1.0 ) + std::clamp( 0.1 * MoverParameters->PipePress, 0.0, 0.5 ) }; m_emergencybrake @@ -4651,7 +4651,7 @@ void TDynamicObject::RenderSounds() { if( m_lastbrakepressure != -1.f ) { // calculate rate of pressure drop in brake cylinder, once it's been initialized auto const brakepressuredifference{ m_lastbrakepressure - MoverParameters->BrakePress }; - m_brakepressurechange = interpolate( m_brakepressurechange, brakepressuredifference / dt, 0.05f ); + m_brakepressurechange = std::lerp( m_brakepressurechange, brakepressuredifference / dt, 0.05f ); } m_lastbrakepressure = MoverParameters->BrakePress; // ensure some basic level of volume and scale it up depending on pressure in the cylinder; scale this by the air release rate @@ -4719,7 +4719,7 @@ void TDynamicObject::RenderSounds() { 0.0, 1.0 ); rsBrake .pitch( rsBrake.m_frequencyoffset + MoverParameters->Vel * rsBrake.m_frequencyfactor ) - .gain( rsBrake.m_amplitudeoffset + std::sqrt( brakeforceratio * interpolate( 0.4, 1.0, ( MoverParameters->Vel / ( 1 + MoverParameters->Vmax ) ) ) ) * rsBrake.m_amplitudefactor ) + .gain( rsBrake.m_amplitudeoffset + std::sqrt( brakeforceratio * std::lerp( 0.4, 1.0, ( MoverParameters->Vel / ( 1 + MoverParameters->Vmax ) ) ) ) * rsBrake.m_amplitudefactor ) .play( sound_flags::exclusive | sound_flags::looping ); } else { @@ -4736,7 +4736,7 @@ void TDynamicObject::RenderSounds() { // McZapkie-280302 - pisk mocno zacisnietych hamulcow if( MoverParameters->Vel > 2.5 ) { - volume = rsPisk.m_amplitudeoffset + interpolate( -1.0, 1.0, brakeforceratio ) * rsPisk.m_amplitudefactor; + volume = rsPisk.m_amplitudeoffset + std::lerp( -1.0, 1.0, brakeforceratio ) * rsPisk.m_amplitudefactor; if( volume > 0.075 ) { rsPisk .pitch( @@ -4964,7 +4964,7 @@ void TDynamicObject::RenderSounds() { // scale volume by track quality // TODO: track quality and/or environment factors as separate subroutine volume *= - interpolate( + std::lerp( 0.8, 1.2, std::clamp( MyTrack->iQualityFlag / 20.0, @@ -4972,7 +4972,7 @@ void TDynamicObject::RenderSounds() { // for single sample sounds muffle the playback at low speeds if( false == bogiesound.is_combined() ) { volume *= - interpolate( + std::lerp( 0.0, 1.0, std::clamp( MoverParameters->Vel / 40.0, @@ -5051,7 +5051,7 @@ void TDynamicObject::RenderSounds() { // scale volume with curve radius and vehicle speed volume = std::abs( MoverParameters->AccN ) // * MoverParameters->AccN - * interpolate( + * std::lerp( 0.5, 1.0, std::clamp( MoverParameters->Vel / 40.0, @@ -8090,7 +8090,7 @@ TDynamicObject::update_shake( double const Timedelta ) { ( MoverParameters->enrot - EngineShake.fadein_offset ) * EngineShake.fadein_factor, 0.0, 1.0 ) // fade out with rpm above threshold - * interpolate( + * std::lerp( 1.0, 0.0, std::clamp( ( MoverParameters->enrot - EngineShake.fadeout_offset ) * EngineShake.fadeout_factor, @@ -8103,7 +8103,7 @@ TDynamicObject::update_shake( double const Timedelta ) { // hunting oscillation HuntingAngle = clamp_circular( HuntingAngle + 4.0 * HuntingShake.frequency * Timedelta * MoverParameters->Vel, 360.0 ); auto const huntingamount = - interpolate( + std::lerp( 0.0, 1.0, std::clamp( ( MoverParameters->Vel - HuntingShake.fadein_begin ) / ( HuntingShake.fadein_end - HuntingShake.fadein_begin ), @@ -8376,7 +8376,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub fake_engine.stop(); } - engine_volume = interpolate( engine_volume, volume, 0.25 ); + engine_volume = std::lerp( engine_volume, volume, 0.25 ); if( engine_volume < 0.05 ) { engine.stop(); } @@ -8519,7 +8519,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub + std::abs( Vehicle.Mm ) / 60.0 * Deltatime, 0.0, 1.25 ); volume *= std::max( 0.25f, motor_momentum ); - motor_volume = interpolate( motor_volume, volume, 0.25 ); + motor_volume = std::lerp( motor_volume, volume, 0.25 ); if( motor_volume >= 0.05 ) { // apply calculated parameters to all motor instances for( auto &motor : motors ) { diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index cefd8a97..1b68561b 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -457,7 +457,7 @@ float TGauge::GetScaledValue() const { ( false == m_interpolatescale ) ? m_value * m_scale + m_offset : m_value - * interpolate( + * std::lerp( m_scale, m_endscale, std::clamp( m_value / m_endvalue, diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 521573cd..e098dbe3 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -1713,7 +1713,7 @@ void TTrain::OnCommand_trainbrakeset( TTrain *Train, command_data const &Command if( Command.action != GLFW_RELEASE ) { // press or hold Train->mvOccupied->BrakeLevelSet( - interpolate( + std::lerp( Train->mvOccupied->Handle->GetPos( bh_MIN ), Train->mvOccupied->Handle->GetPos( bh_MAX ), std::clamp( @@ -8552,7 +8552,7 @@ TTrain::update_sounds( double const Deltatime ) { if( m_lastlocalbrakepressure != -1.f ) { // calculate rate of pressure drop in local brake cylinder, once it's been initialized auto const brakepressuredifference { mvOccupied->LocBrakePress - m_lastlocalbrakepressure }; - m_localbrakepressurechange = interpolate( m_localbrakepressurechange, 10 * ( brakepressuredifference / Deltatime ), 0.1f ); + m_localbrakepressurechange = std::lerp( m_localbrakepressurechange, 10 * ( brakepressuredifference / Deltatime ), 0.1f ); } m_lastlocalbrakepressure = mvOccupied->LocBrakePress; // local brake, release @@ -8593,7 +8593,7 @@ TTrain::update_sounds( double const Deltatime ) { || ( mvOccupied->BrakeHandle == TBrakeHandle::FVel6 ) ) { // upuszczanie z PG if( rsHiss ) { - fPPress = interpolate( fPPress, static_cast( mvOccupied->Handle->GetSound( s_fv4a_b ) ), 0.05f ); + fPPress = std::lerp( fPPress, static_cast( mvOccupied->Handle->GetSound( s_fv4a_b ) ), 0.05f ); volume = ( fPPress > 0 ? rsHiss->m_amplitudefactor * fPPress * 0.25 + rsHiss->m_amplitudeoffset : @@ -8608,7 +8608,7 @@ TTrain::update_sounds( double const Deltatime ) { } // napelnianie PG if( rsHissU ) { - fNPress = interpolate( fNPress, static_cast( mvOccupied->Handle->GetSound( s_fv4a_u ) ), 0.25f ); + fNPress = std::lerp( fNPress, static_cast( mvOccupied->Handle->GetSound( s_fv4a_u ) ), 0.25f ); volume = ( fNPress > 0 ? rsHissU->m_amplitudefactor * fNPress + rsHissU->m_amplitudeoffset : @@ -8703,7 +8703,7 @@ TTrain::update_sounds( double const Deltatime ) { FreeFlyModeFlag ? 0.0 : rsBrake->m_amplitudeoffset - + std::sqrt( brakeforceratio * interpolate( 0.4, 1.0, ( mvOccupied->Vel / ( 1 + mvOccupied->Vmax ) ) ) ) * rsBrake->m_amplitudefactor ); + + std::sqrt( brakeforceratio * std::lerp( 0.4, 1.0, ( mvOccupied->Vel / ( 1 + mvOccupied->Vmax ) ) ) ) * rsBrake->m_amplitudefactor ); rsBrake->pitch( rsBrake->m_frequencyoffset + mvOccupied->Vel * rsBrake->m_frequencyfactor ); rsBrake->gain( volume ); rsBrake->play( sound_flags::exclusive | sound_flags::looping ); @@ -8776,7 +8776,7 @@ TTrain::update_sounds( double const Deltatime ) { update_sounds_runningnoise( *rsHuntingNoise ); // modify calculated sound volume by hunting amount auto const huntingamount = - interpolate( + std::lerp( 0.0, 1.0, std::clamp( ( mvOccupied->Vel - DynamicObject->HuntingShake.fadein_begin ) / ( DynamicObject->HuntingShake.fadein_end - DynamicObject->HuntingShake.fadein_begin ), @@ -8905,7 +8905,7 @@ void TTrain::update_sounds_resonancenoise(sound_source &Sound) auto const frequency{Sound.m_frequencyoffset + Sound.m_frequencyfactor * mvOccupied->Vel * normalizer}; // volume calculation - auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * interpolate(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0, 0.5); // scale base volume between 0.5-1.0 + auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * std::lerp(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0, 0.5); // scale base volume between 0.5-1.0 if (volume > 0.05) { @@ -8930,7 +8930,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) { // volume calculation auto volume = Sound.m_amplitudeoffset - + Sound.m_amplitudefactor * interpolate( + + Sound.m_amplitudefactor * std::lerp( mvOccupied->Vel / ( 1 + mvOccupied->Vmax ), 1.0, 0.5 ); // scale base volume between 0.5-1.0 if( std::abs( mvOccupied->nrot ) > 0.01 ) { @@ -8945,7 +8945,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) { // scale volume by track quality // TODO: track quality and/or environment factors as separate subroutine volume *= - interpolate( + std::lerp( 0.8, 1.2, std::clamp( DynamicObject->MyTrack->iQualityFlag / 20.0, @@ -8953,7 +8953,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) { // for single sample sounds muffle the playback at low speeds if( false == Sound.is_combined() ) { volume *= - interpolate( + std::lerp( 0.0, 1.0, std::clamp( mvOccupied->Vel / 25.0, @@ -9542,7 +9542,7 @@ glm::dvec3 TTrain::MirrorPosition(bool lewe) glm::dvec4( mvOccupied->Dim.W * ( 0.5 * shiftdirection ) + ( 0.2 * shiftdirection ), 1.5 + Cabine[iCabn].CabPos1.y, - interpolate( Cabine[ iCabn ].CabPos1.z , Cabine[ iCabn ].CabPos2.z, 0.5 ), 1.0); + std::lerp( Cabine[ iCabn ].CabPos1.z , Cabine[ iCabn ].CabPos2.z, 0.5 ), 1.0); }; void TTrain::DynamicSet(TDynamicObject *d) diff --git a/world/Segment.cpp b/world/Segment.cpp index 05124233..41bfacf0 100644 --- a/world/Segment.cpp +++ b/world/Segment.cpp @@ -198,7 +198,7 @@ double TSegment::GetTFromS(double const s) const // initial guess for Newton's method double fTolerance = 0.001; double fRatio = s / RombergIntegral(0, 1); - double fTime = interpolate( 0.0, 1.0, fRatio ); + double fTime = std::lerp( 0.0, 1.0, fRatio ); int iteration = 0; double fDifference {}; // exposed for debug down the road @@ -243,7 +243,7 @@ double TSegment::ComputeLength() const // McZapkie-150503: dlugosc miedzy punkta for (int i = 1; i <= m; i++) { t = double(i) / double(m); // wyznaczenie parametru na krzywej z przedziału (0,1> - // tmp=Interpolate(t,p1,cp1,cp2,p2); + // tmp=std::lerp(t,p1,cp1,cp2,p2); tmp = RaInterpolate0(t); // obliczenie punktu dla tego parametru t = glm::length(tmp - last); // obliczenie długości wektora l += t; // zwiększenie wyliczanej długości @@ -323,13 +323,13 @@ Math3D::vector3 TSegment::GetPoint(double const fDistance) const if (bCurve) { // można by wprowadzić uproszczony wzór dla okręgów płaskich double t = GetTFromS(fDistance); // aproksymacja dystansu na krzywej Beziera - // return Interpolate(t,Point1,CPointOut,CPointIn,Point2); + // return std::lerp(t,Point1,CPointOut,CPointIn,Point2); return RaInterpolate(t); } else { // wyliczenie dla odcinka prostego jest prostsze return - interpolate( + std::lerp( Point1, Point2, std::clamp( fDistance / fLength, @@ -344,7 +344,7 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &p, glm::vec3 &a auto const t = GetTFromS(fDistance); // aproksymacja dystansu na krzywej Beziera na parametr (t) p = FastGetPoint( t ); // przechyłka w danym miejscu (zmienia się liniowo) - a.x = interpolate( fRoll1, fRoll2, t ); + a.x = std::lerp( fRoll1, fRoll2, t ); // pochodna jest 3*A*t^2+2*B*t+C auto const tangent = t * ( t * 3.0 * vA + vB + vB ) + vC; // pochylenie krzywej (w pionie) @@ -357,7 +357,7 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &p, glm::vec3 &a auto const t = fDistance / fLength; // zerowych torów nie ma p = FastGetPoint( t ); // przechyłka w danym miejscu (zmienia się liniowo) - a.x = interpolate( fRoll1, fRoll2, t ); + a.x = std::lerp( fRoll1, fRoll2, t ); a.y = fStoop; // pochylenie toru prostego a.z = fDirection; // kierunek toru w planie } @@ -365,11 +365,10 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &p, glm::vec3 &a glm::dvec3 TSegment::FastGetPoint(double const t) const { - // return (bCurve?Interpolate(t,Point1,CPointOut,CPointIn,Point2):((1.0-t)*Point1+(t)*Point2)); + // return (bCurve?std::lerp(t,Point1,CPointOut,CPointIn,Point2):((1.0-t)*Point1+(t)*Point2)); return ( ( ( true == bCurve ) || ( iSegCount != 1 ) ) ? - RaInterpolate( t ) : - interpolate( Point1, Point2, t ) ); + RaInterpolate( t ) : glm::mix(Point1, Point2, t)); } bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin, const gfx::vertex_array &ShapePoints, bool const Transition, double fTextureLength, double Texturescale, int iSkip, int iEnd, std::pair fOffsetX, glm::vec3 **p, bool bRender) diff --git a/world/Segment.h b/world/Segment.h index 24725d78..f678048a 100644 --- a/world/Segment.h +++ b/world/Segment.h @@ -105,7 +105,7 @@ public: inline float GetRoll(double const Distance) const { - return interpolate( fRoll1, fRoll2, static_cast(Distance / fLength) ); } + return std::lerp( fRoll1, fRoll2, static_cast(Distance / fLength) ); } inline void GetRolls(float &r1, float &r2) const { diff --git a/world/Traction.cpp b/world/Traction.cpp index db7d033b..d660ac02 100644 --- a/world/Traction.cpp +++ b/world/Traction.cpp @@ -156,7 +156,7 @@ TTraction::Load( cParser *parser, glm::dvec3 const &pOrigin ) { Init(); // przeliczenie parametrów // calculate traction location - location( interpolate( pPoint2, pPoint1, 0.5 ) ); + location( glm::mix( pPoint2, pPoint1, 0.5 ) ); } // retrieves list of the track's end points