From 83f56b07f8438139de54212ca960cf06046bd85c Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Sat, 27 Oct 2018 03:22:49 +0200 Subject: [PATCH] celestial bodies scaling tweak, driver cab included in the compartment lighting system --- Driver.h | 1 + DynObj.cpp | 16 ++++++++++++++++ DynObj.h | 3 ++- Train.cpp | 18 +++++++----------- renderer.cpp | 21 ++++++++++++++------- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Driver.h b/Driver.h index 89bf75ef..de54094d 100644 --- a/Driver.h +++ b/Driver.h @@ -255,6 +255,7 @@ private: sound_source tsGuardSignal { sound_placement::internal }; std::array m_lighthints { -1 }; // suggested light patterns public: + int HelperState = 0; //stan pomocnika maszynisty double AccPreferred = 0.0; // preferowane przyspieszenie (wg psychiki kierującego, zmniejszana przy wykryciu kolizji) double AccDesired = AccPreferred; // przyspieszenie, jakie ma utrzymywać (<0:nie przyspieszaj,<-0.1:hamuj) double VelDesired = 0.0; // predkość, z jaką ma jechać, wynikająca z analizy tableki; <=VelSignal diff --git a/DynObj.cpp b/DynObj.cpp index af47f281..2c88a302 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -647,6 +647,22 @@ TDynamicObject::toggle_lights() { } } +void +TDynamicObject::set_cab_lights( float const Level ) { + + if( Level == InteriorLightLevel ) { return; } + + InteriorLightLevel = Level; + + for( auto §ion : Sections ) { + // cab compartments are placed at the beginning of the list, so we can bail out as soon as we find different compartment type + auto const sectionname { section.compartment->pName }; + if( sectionname.find( "cab" ) != 0 ) { return; } + + section.light_level = Level; + } +} + // ABu 29.01.05 przeklejone z render i renderalpha: ********************* void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) { // ABu290105: pozbierane i uporzadkowane powtarzajace diff --git a/DynObj.h b/DynObj.h index 1e3d8f08..8fc06a3d 100644 --- a/DynObj.h +++ b/DynObj.h @@ -612,8 +612,9 @@ private: void CouplersDettach(double MinDist, int MyScanDir); void RadioStop(); void Damage(char flag); - void RaLightsSet(int head, int rear); + void RaLightsSet(int head, int rear); int LightList( side const Side ) const { return iInventory[ Side ]; } + void set_cab_lights( float const Level ); TDynamicObject * FirstFind(int &coupler_nr, int cf = 1); float GetEPP(); // wyliczanie sredniego cisnienia w PG int DirectionSet(int d); // ustawienie kierunku w składzie diff --git a/Train.cpp b/Train.cpp index ae84a1bf..ddfaee0d 100644 --- a/Train.cpp +++ b/Train.cpp @@ -4709,13 +4709,10 @@ void TTrain::OnCommand_cabchangebackward( TTrain *Train, command_data const &Com // cab movement update, fixed step part void TTrain::UpdateMechPosition(double dt) -{ // Ra: mechanik powinien być - // telepany niezależnie od pozycji - // pojazdu +{ // Ra: mechanik powinien być telepany niezależnie od pozycji pojazdu // Ra: trzeba zrobić model bujania głową i wczepić go do pojazdu - // DynamicObject->vFront=DynamicObject->GetDirection(); //to jest już - // policzone + // DynamicObject->vFront=DynamicObject->GetDirection(); //to jest już policzone // Ra: tu by się przydało uwzględnić rozkład sił: // - na postoju horyzont prosto, kabina skosem @@ -4792,7 +4789,6 @@ void TTrain::UpdateMechPosition(double dt) shake *= 0.85; vMechVelocity -= ( shake + vMechVelocity * 100 ) * ( fMechSpringX + fMechSpringY + fMechSpringZ ) / ( 200 ); - // shake *= 0.95 * dt; // shake damping // McZapkie: pMechShake += vMechVelocity * dt; @@ -4804,8 +4800,6 @@ void TTrain::UpdateMechPosition(double dt) pMechOffset += vMechMovement * dt; // ABu011104: 5*pMechShake.y, zeby ladnie pudlem rzucalo :) pMechPosition = pMechOffset + Math3D::vector3( 1.5 * pMechShake.x, 2.0 * pMechShake.y, 1.5 * pMechShake.z ); - -// pMechShake = interpolate( pMechShake, Math3D::vector3(), clamp( dt, 0.0, 1.0 ) ); } else { // hamowanie rzucania przy spadku FPS pMechShake -= pMechShake * std::min( dt, 1.0 ); // po tym chyba potrafią zostać jakieś ułamki, które powodują zjazd @@ -5911,11 +5905,12 @@ bool TTrain::Update( double const Deltatime ) // calculate current level of interior illumination // TODO: organize it along with rest of train update in a more sensible arrangement + auto interiorlightlevel { 0.f }; switch( iCabLightFlag ) // Ra: uzeleżnic od napięcia w obwodzie sterowania { // hunter-091012: uzaleznienie jasnosci od przetwornicy case 0: { //światło wewnętrzne zgaszone - DynamicObject->InteriorLightLevel = 0.0f; + interiorlightlevel = 0.0f; break; } case 1: { @@ -5925,7 +5920,7 @@ bool TTrain::Update( double const Deltatime ) || ( ( ( mvOccupied->Couplers[ side::front ].CouplingFlag & coupling::permanent ) != 0 ) && mvOccupied->Couplers[ side::front ].Connected->ConverterFlag ) || ( ( ( mvOccupied->Couplers[ side::rear ].CouplingFlag & coupling::permanent ) != 0 ) && mvOccupied->Couplers[ side::rear ].Connected->ConverterFlag ) ) }; - DynamicObject->InteriorLightLevel = ( + interiorlightlevel = ( converteractive ? 0.4f : 0.2f ); @@ -5938,13 +5933,14 @@ bool TTrain::Update( double const Deltatime ) || ( ( ( mvOccupied->Couplers[ side::front ].CouplingFlag & coupling::permanent ) != 0 ) && mvOccupied->Couplers[ side::front ].Connected->ConverterFlag ) || ( ( ( mvOccupied->Couplers[ side::rear ].CouplingFlag & coupling::permanent ) != 0 ) && mvOccupied->Couplers[ side::rear ].Connected->ConverterFlag ) ) }; - DynamicObject->InteriorLightLevel = ( + interiorlightlevel = ( converteractive ? 1.0f : 0.5f ); break; } } + DynamicObject->set_cab_lights( interiorlightlevel ); // anti slip system activation, maintained while the control button is down if( mvOccupied->BrakeSystem != TBrakeSystem::ElectroPneumatic ) { diff --git a/renderer.cpp b/renderer.cpp index 55e6044a..769c651a 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -1488,7 +1488,10 @@ 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 = 0.045f; + float const size = interpolate( // TODO: expose distance/scale factor from the moon object + 0.0325f, + 0.0275f, + clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f ); ::glBegin( GL_TRIANGLE_STRIP ); ::glMultiTexCoord2f( m_diffusetextureunit, 1.f, 1.f ); ::glVertex3f( -size, size, 0.f ); ::glMultiTexCoord2f( m_diffusetextureunit, 1.f, 0.f ); ::glVertex3f( -size, -size, 0.f ); @@ -1518,8 +1521,8 @@ opengl_renderer::Render( world_environment *Environment ) { ::glTranslatef( moonposition.x, moonposition.y, moonposition.z ); float const size = interpolate( // TODO: expose distance/scale factor from the moon object - 0.0175f, - 0.015f, + 0.0160f, + 0.0135f, clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f ); // choose the moon appearance variant, based on current moon phase // NOTE: implementation specific, 8 variants are laid out in 3x3 arrangement @@ -2156,19 +2159,21 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) { if( Dynamic->mdLowPolyInt ) { // low poly interior if( FreeFlyModeFlag ? true : !Dynamic->mdKabina || !Dynamic->bDisplayCab ) { +/* // enable cab light if needed if( Dynamic->InteriorLightLevel > 0.0f ) { // crude way to light the cabin, until we have something more complete in place ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( Dynamic->InteriorLight * Dynamic->InteriorLightLevel ) ); } - +*/ Render( Dynamic->mdLowPolyInt, Dynamic->Material(), squaredistance ); - +/* if( Dynamic->InteriorLightLevel > 0.0f ) { // reset the overall ambient ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( m_baseambient ) ); } +*/ } } if( Dynamic->mdModel ) @@ -3241,19 +3246,21 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) { if( Dynamic->mdLowPolyInt ) { // low poly interior if( FreeFlyModeFlag ? true : !Dynamic->mdKabina || !Dynamic->bDisplayCab ) { +/* // enable cab light if needed if( Dynamic->InteriorLightLevel > 0.0f ) { // crude way to light the cabin, until we have something more complete in place ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( Dynamic->InteriorLight * Dynamic->InteriorLightLevel ) ); } - +*/ Render_Alpha( Dynamic->mdLowPolyInt, Dynamic->Material(), squaredistance ); - +/* if( Dynamic->InteriorLightLevel > 0.0f ) { // reset the overall ambient ::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( m_baseambient ) ); } +*/ } }