16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 19:09:20 +02:00

light beam strength based on number of active lights, \r recognition in the parser, proper (lack) of depth test for the UI

This commit is contained in:
tmj-fstate
2017-02-13 19:28:04 +01:00
parent 6683738077
commit 83284e4bcc
2 changed files with 42 additions and 17 deletions

View File

@@ -1252,11 +1252,15 @@ bool TWorld::Update()
// przy 0.25 smuga gaśnie o 6:37 w Quarku, a mogłaby już 5:40
// Ra 2014-12: przy 0.15 się skarżyli, że nie widać smug => zmieniłem na 0.25
// changed light activation threshold to 0.5, paired with strength reduction in daylight
if (Train) // jeśli nie usunięty
Global::bSmudge =
FreeFlyModeFlag ? false : ((Train->Dynamic()->fShade <= 0.0) ?
(Global::fLuminance <= 0.25) :
(Train->Dynamic()->fShade * Global::fLuminance <= 0.25));
( FreeFlyModeFlag ?
false :
( Train->Dynamic()->fShade <= 0.0 ?
(Global::fLuminance <= 0.5) :
(Train->Dynamic()->fShade * Global::fLuminance <= 0.5) ) );
if (!Render())
return false;
@@ -1496,6 +1500,7 @@ bool TWorld::Render()
glColor3b(255, 255, 255);
// glColor3b(255, 0, 255);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc( GL_LEQUAL );
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity();
Camera.SetMatrix(); // ustawienie macierzy kamery względem początku scenerii
@@ -1575,20 +1580,36 @@ TWorld::Render_Cab() {
// 1. warunek na smugę wyznaczyc wcześniej
// 2. jeśli smuga włączona, nie renderować pojazdu użytkownika w DynObj
// 3. jeśli smuga właczona, wyrenderować pojazd użytkownia po dodaniu smugi do sceny
if( Train->Controlled()->Battery ) { // trochę na skróty z tą baterią
auto const &frontlights = Train->Controlled()->iLights[ 0 ];
float frontlightstrength = 0.f +
( ( frontlights & 1 ) ? 0.3f : 0.f ) +
( ( frontlights & 4 ) ? 0.3f : 0.f ) +
( ( frontlights & 16 ) ? 0.3f : 0.f );
frontlightstrength = std::max( frontlightstrength - Global::fLuminance, 0.0 );
auto const &rearlights = Train->Controlled()->iLights[ 1 ];
float rearlightstrength = 0.f +
( ( rearlights & 1 ) ? 0.3f : 0.f ) +
( ( rearlights & 4 ) ? 0.3f : 0.f ) +
( ( rearlights & 16 ) ? 0.3f : 0.f );
rearlightstrength = std::max( rearlightstrength - Global::fLuminance, 0.0 );
if( ( Train->Controlled()->Battery ) // trochę na skróty z tą baterią
&& ( ( frontlightstrength > 0.f )
|| ( rearlightstrength > 0.f ) ) ) {
if( Global::bOldSmudge == true ) {
glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_ONE );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
// glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_DST_COLOR);
// glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE);
glDisable( GL_DEPTH_TEST );
glDisable( GL_LIGHTING );
glDisable( GL_FOG );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glBindTexture( GL_TEXTURE_2D, light ); // Select our texture
glBegin( GL_QUADS );
float fSmudge =
dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
if( Train->Controlled()->iLights[ 0 ] & 21 ) { // wystarczy jeden zapalony z przodu
if( frontlightstrength > 0.f ) { // wystarczy jeden zapalony z przodu
glColor4f( 1.0f, 1.0f, 1.0f, 0.5f * frontlightstrength );
glTexCoord2f( 0, 0 );
glVertex3f( 15.0, 0.0, +fSmudge ); // rysowanie względem położenia modelu
glTexCoord2f( 1, 0 );
@@ -1598,7 +1619,8 @@ TWorld::Render_Cab() {
glTexCoord2f( 0, 1 );
glVertex3f( 15.0, 2.5, 250.0 );
}
if( Train->Controlled()->iLights[ 1 ] & 21 ) { // wystarczy jeden zapalony z tyłu
if( rearlightstrength > 0.f ) { // wystarczy jeden zapalony z tyłu
glColor4f( 1.0f, 1.0f, 1.0f, 0.5f * rearlightstrength );
glTexCoord2f( 0, 0 );
glVertex3f( -15.0, 0.0, -fSmudge );
glTexCoord2f( 1, 0 );
@@ -1616,6 +1638,7 @@ TWorld::Render_Cab() {
glEnable( GL_FOG );
}
else {
glBlendFunc( GL_DST_COLOR, GL_ONE );
glDepthFunc( GL_GEQUAL );
glAlphaFunc( GL_GREATER, 0.004 );
@@ -1627,23 +1650,24 @@ TWorld::Render_Cab() {
//float ddl = (0.15*Global::diffuseDayLight[0]+0.295*Global::diffuseDayLight[1]+0.055*Global::diffuseDayLight[2]); //0.24:0
glBegin( GL_QUADS );
float fSmudge = dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
if( Train->Controlled()->iLights[ 0 ] & 21 ) { // wystarczy jeden zapalony z przodu
if( frontlightstrength > 0.f ) { // wystarczy jeden zapalony z przodu
for( int i = 15; i <= 35; i++ ) {
float z = i * i * i * 0.01f;//25/4;
//float C = (36 - i*0.5)*0.005*(1.5 - sqrt(ddl));
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 );
glColor4f( C, C, C, 0.25f );
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 ) * frontlightstrength;
glColor4f( C, C, C, 0.35f );// *frontlightstrength );
glTexCoord2f( 0, 0 ); glVertex3f( -10 / 2 - 2 * i / 4, 6.0 + 0.3*z, 13 + 1.7*z / 3 );
glTexCoord2f( 1, 0 ); glVertex3f( 10 / 2 + 2 * i / 4, 6.0 + 0.3*z, 13 + 1.7*z / 3 );
glTexCoord2f( 1, 1 ); glVertex3f( 10 / 2 + 2 * i / 4, -5.0 - 0.5*z, 13 + 1.7*z / 3 );
glTexCoord2f( 0, 1 ); glVertex3f( -10 / 2 - 2 * i / 4, -5.0 - 0.5*z, 13 + 1.7*z / 3 );
}
}
if( Train->Controlled()->iLights[ 1 ] & 21 ) { // wystarczy jeden zapalony z tyłu
if( rearlightstrength > 0.f ) { // wystarczy jeden zapalony z tyłu
for( int i = 15; i <= 35; i++ ) {
float z = i * i * i * 0.01f;//25/4;
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 );
glColor4f( C, C, C, 0.25f );
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 ) * rearlightstrength;
glColor4f( C, C, C, 0.35f );// *rearlightstrength );
glTexCoord2f( 0, 0 ); glVertex3f( 10 / 2 + 2 * i / 4, 6.0 + 0.3*z, -13 - 1.7*z / 3 );
glTexCoord2f( 1, 0 ); glVertex3f( -10 / 2 - 2 * i / 4, 6.0 + 0.3*z, -13 - 1.7*z / 3 );
glTexCoord2f( 1, 1 ); glVertex3f( -10 / 2 - 2 * i / 4, -5.0 - 0.5*z, -13 - 1.7*z / 3 );
@@ -1917,6 +1941,7 @@ TWorld::Render_UI() {
Global::changeDynObj = NULL;
}
glDepthFunc( GL_ALWAYS );
glDisable( GL_LIGHTING );
if( Controlled )
SetWindowText( hWnd, Controlled->MoverParameters->Name.c_str() );