16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 19:49:19 +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 // 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 // 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 if (Train) // jeśli nie usunięty
Global::bSmudge = Global::bSmudge =
FreeFlyModeFlag ? false : ((Train->Dynamic()->fShade <= 0.0) ? ( FreeFlyModeFlag ?
(Global::fLuminance <= 0.25) : false :
(Train->Dynamic()->fShade * Global::fLuminance <= 0.25)); ( Train->Dynamic()->fShade <= 0.0 ?
(Global::fLuminance <= 0.5) :
(Train->Dynamic()->fShade * Global::fLuminance <= 0.5) ) );
if (!Render()) if (!Render())
return false; return false;
@@ -1496,6 +1500,7 @@ bool TWorld::Render()
glColor3b(255, 255, 255); glColor3b(255, 255, 255);
// glColor3b(255, 0, 255); // glColor3b(255, 0, 255);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc( GL_LEQUAL );
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); glLoadIdentity();
Camera.SetMatrix(); // ustawienie macierzy kamery względem początku scenerii Camera.SetMatrix(); // ustawienie macierzy kamery względem początku scenerii
@@ -1575,20 +1580,36 @@ TWorld::Render_Cab() {
// 1. warunek na smugę wyznaczyc wcześniej // 1. warunek na smugę wyznaczyc wcześniej
// 2. jeśli smuga włączona, nie renderować pojazdu użytkownika w DynObj // 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 // 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 ) { 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_ONE_MINUS_DST_COLOR, GL_DST_COLOR);
// glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE); // glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE);
glDisable( GL_DEPTH_TEST ); glDisable( GL_DEPTH_TEST );
glDisable( GL_LIGHTING ); glDisable( GL_LIGHTING );
glDisable( GL_FOG ); glDisable( GL_FOG );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glBindTexture( GL_TEXTURE_2D, light ); // Select our texture glBindTexture( GL_TEXTURE_2D, light ); // Select our texture
glBegin( GL_QUADS ); glBegin( GL_QUADS );
float fSmudge = float fSmudge =
dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę 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 ); glTexCoord2f( 0, 0 );
glVertex3f( 15.0, 0.0, +fSmudge ); // rysowanie względem położenia modelu glVertex3f( 15.0, 0.0, +fSmudge ); // rysowanie względem położenia modelu
glTexCoord2f( 1, 0 ); glTexCoord2f( 1, 0 );
@@ -1598,7 +1619,8 @@ TWorld::Render_Cab() {
glTexCoord2f( 0, 1 ); glTexCoord2f( 0, 1 );
glVertex3f( 15.0, 2.5, 250.0 ); 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 ); glTexCoord2f( 0, 0 );
glVertex3f( -15.0, 0.0, -fSmudge ); glVertex3f( -15.0, 0.0, -fSmudge );
glTexCoord2f( 1, 0 ); glTexCoord2f( 1, 0 );
@@ -1616,6 +1638,7 @@ TWorld::Render_Cab() {
glEnable( GL_FOG ); glEnable( GL_FOG );
} }
else { else {
glBlendFunc( GL_DST_COLOR, GL_ONE ); glBlendFunc( GL_DST_COLOR, GL_ONE );
glDepthFunc( GL_GEQUAL ); glDepthFunc( GL_GEQUAL );
glAlphaFunc( GL_GREATER, 0.004 ); 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 //float ddl = (0.15*Global::diffuseDayLight[0]+0.295*Global::diffuseDayLight[1]+0.055*Global::diffuseDayLight[2]); //0.24:0
glBegin( GL_QUADS ); glBegin( GL_QUADS );
float fSmudge = dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę 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++ ) { for( int i = 15; i <= 35; i++ ) {
float z = i * i * i * 0.01f;//25/4; 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*(1.5 - sqrt(ddl));
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 ); float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 ) * frontlightstrength;
glColor4f( C, C, C, 0.25f ); 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( 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, 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( 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 ); 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++ ) { for( int i = 15; i <= 35; i++ ) {
float z = i * i * i * 0.01f;//25/4; 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 ); float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 ) * rearlightstrength;
glColor4f( C, C, C, 0.25f ); 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( 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, 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( 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; Global::changeDynObj = NULL;
} }
glDepthFunc( GL_ALWAYS );
glDisable( GL_LIGHTING ); glDisable( GL_LIGHTING );
if( Controlled ) if( Controlled )
SetWindowText( hWnd, Controlled->MoverParameters->Name.c_str() ); SetWindowText( hWnd, Controlled->MoverParameters->Name.c_str() );

View File

@@ -77,7 +77,7 @@ class cParser //: public std::stringstream
{ {
return !mStream->fail(); return !mStream->fail();
}; };
bool getTokens(int Count = 1, bool ToLower = true, const char *Break = "\n\t ;"); bool getTokens(int Count = 1, bool ToLower = true, const char *Break = "\n\r\t ;");
// returns percentage of file processed so far // returns percentage of file processed so far
int getProgress() const; int getProgress() const;
// add custom definition of text which should be ignored when retrieving tokens // add custom definition of text which should be ignored when retrieving tokens
@@ -85,9 +85,9 @@ class cParser //: public std::stringstream
private: private:
// methods: // methods:
std::string readToken(bool ToLower = true, const char *Break = "\n\t ;"); std::string readToken(bool ToLower = true, const char *Break = "\n\r\t ;");
std::string readQuotes( char const Quote = '\"' ); std::string readQuotes( char const Quote = '\"' );
std::string readComment( std::string const &Break = "\n\t ;" ); std::string readComment( std::string const &Break = "\n\r\t ;" );
// std::string trtest; // std::string trtest;
bool findQuotes( std::string &String ); bool findQuotes( std::string &String );
bool trimComments( std::string &String ); bool trimComments( std::string &String );