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

working vehicle spotlights

This commit is contained in:
tmj-fstate
2017-02-25 21:02:27 +01:00
parent 259e9042e1
commit 493340e602
11 changed files with 353 additions and 184 deletions

399
World.cpp
View File

@@ -264,89 +264,34 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Max texture size: " + std::to_string(Global::iMaxTextureSize));
}
/*-----------------------Render Initialization----------------------*/
if (Global::fOpenGL >= 1.2) // poniższe nie działa w 1.1
glTexEnvf(TEXTURE_FILTER_CONTROL_EXT, TEXTURE_LOD_BIAS_EXT, -1);
GLfloat FogColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear screen and depth buffer
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
// WriteLog("glClearColor (FogColor[0], FogColor[1], FogColor[2], 0.0); ");
// glClearColor (1.0, 0.0, 0.0, 0.0); // Background Color
// glClearColor (FogColor[0], FogColor[1], FogColor[2], 0.0);
// Background // Color
glClearColor(Global::Background[0], Global::Background[1], Global::Background[2], 1.0); // Background Color
WriteLog("glFogfv(GL_FOG_COLOR, FogColor);");
glFogfv(GL_FOG_COLOR, FogColor); // Set Fog Color
glClearDepth( 1.0f ); // ZBuffer Value
glClearColor( 51.0f / 255.0f, 106.0f / 255.0f, 85.0f / 255.0f, 1.0f ); // Background Color
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Clear screen and depth buffer
WriteLog("glClearDepth(1.0f); ");
glClearDepth(1.0f); // ZBuffer Value
// glEnable(GL_NORMALIZE);
// glEnable(GL_RESCALE_NORMAL);
// glEnable(GL_CULL_FACE);
WriteLog("glEnable(GL_TEXTURE_2D);");
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
WriteLog("glShadeModel(GL_SMOOTH);");
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
WriteLog("glEnable(GL_DEPTH_TEST);");
glEnable(GL_DEPTH_TEST);
// McZapkie:261102-uruchomienie polprzezroczystosci (na razie linie) pod kierunkiem Marcina
// if (Global::bRenderAlpha) //Ra: wywalam tę flagę
{
WriteLog("glEnable(GL_BLEND);");
glEnable(GL_BLEND);
WriteLog("glEnable(GL_ALPHA_TEST);");
glEnable(GL_ALPHA_TEST);
WriteLog("glAlphaFunc(GL_GREATER,0.04);");
glAlphaFunc(GL_GREATER, 0.04);
WriteLog("glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);");
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
WriteLog("glDepthFunc(GL_LEQUAL);");
glDepthFunc(GL_LEQUAL);
}
/*
else
{
WriteLog("glEnable(GL_ALPHA_TEST);");
glEnable(GL_ALPHA_TEST);
WriteLog("glAlphaFunc(GL_GREATER,0.5);");
glAlphaFunc(GL_GREATER,0.5);
WriteLog("glDepthFunc(GL_LEQUAL);");
glDepthFunc(GL_LEQUAL);
WriteLog("glDisable(GL_BLEND);");
glDisable(GL_BLEND);
}
*/
/* zakomentowanie to co bylo kiedys mieszane
WriteLog("glEnable(GL_ALPHA_TEST);");
glEnable(GL_ALPHA_TEST);//glGetIntegerv()
WriteLog("glAlphaFunc(GL_GREATER,0.5);");
// glAlphaFunc(GL_LESS,0.5);
glAlphaFunc(GL_GREATER,0.5);
// glBlendFunc(GL_SRC_ALPHA,GL_ONE);
WriteLog("glDepthFunc(GL_LEQUAL);");
glDepthFunc(GL_LEQUAL);//EQUAL);
// The Type Of Depth Testing To Do
// glEnable(GL_BLEND);
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
*/
WriteLog("glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);");
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
WriteLog("glPolygonMode(GL_FRONT, GL_FILL);");
glPolygonMode(GL_FRONT, GL_FILL);
WriteLog("glFrontFace(GL_CCW);");
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
WriteLog("glEnable(GL_CULL_FACE); ");
glEnable(GL_CULL_FACE); // Cull back-facing triangles
WriteLog("glLineWidth(1.0f);");
glLineWidth(1.0f);
// glLineWidth(2.0f);
WriteLog("glPointSize(3.0f);");
glPointSize(3.0f);
#ifdef EU07_USE_OLD_LIGHTING_MODEL
// ----------- LIGHTING SETUP -----------
@@ -378,39 +323,18 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
glEnable(GL_LIGHT0);
#endif
// glColor() ma zmieniać kolor wybrany w glColorMaterial()
WriteLog("glEnable(GL_COLOR_MATERIAL);");
glEnable(GL_COLOR_MATERIAL);
WriteLog("glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);");
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glColor4fv(Global::whiteLight);
// WriteLog("glMaterialfv( GL_FRONT, GL_AMBIENT, whiteLight );");
// glMaterialfv( GL_FRONT, GL_AMBIENT, Global::whiteLight );
WriteLog("glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, whiteLight );");
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Global::whiteLight);
/*
WriteLog("glMaterialfv( GL_FRONT, GL_SPECULAR, noLight );");
glMaterialfv( GL_FRONT, GL_SPECULAR, Global::noLight );
*/
WriteLog("glEnable(GL_LIGHTING);");
glEnable(GL_LIGHTING);
WriteLog("glFogi(GL_FOG_MODE, GL_LINEAR);");
glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode
WriteLog("glFogfv(GL_FOG_COLOR, FogColor);");
GLfloat FogColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glFogfv(GL_FOG_COLOR, FogColor); // Set Fog Color
// glFogf(GL_FOG_DENSITY, 0.594f); // How Dense Will The
//Fog
// Be
// glHint(GL_FOG_HINT, GL_NICEST); // Fog Hint Value
WriteLog("glFogf(GL_FOG_START, 1000.0f);");
glFogf(GL_FOG_START, 10.0f); // Fog Start Depth
WriteLog("glFogf(GL_FOG_END, 2000.0f);");
glFogf(GL_FOG_END, 200.0f); // Fog End Depth
WriteLog("glEnable(GL_FOG);");
glEnable(GL_FOG); // Enables GL_FOG
// Ra: ustawienia testowe
@@ -480,7 +404,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
glLoadIdentity();
// glColor4f(0.3f,0.0f,0.0f,0.0f);
glTranslatef(0.0f, 0.0f, -0.50f);
// glTranslatef(0.0f, 0.0f, -0.50f);
// glRasterPos2f(-0.25f, -0.10f);
#ifdef EU07_USE_OLD_LIGHTING_MODEL
glColor3f( 3.0f, 3.0f, 3.0f );
@@ -491,23 +415,25 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
auto logo = GfxRenderer.GetTextureId( "logo", szTexturePath, 6 );
GfxRenderer.Bind(logo); // Select our texture
float const widthratio = ( 4.0f / 3.0f ) / ( (float)Global::iWindowWidth / Global::iWindowHeight );
glBegin(GL_QUADS); // Drawing using triangles
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f); // bottom left of the texture and quad
glVertex2f( -widthratio, -1.0f ); // bottom left of the texture and quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f); // bottom right of the texture and quad
glVertex2f(widthratio, -1.0f); // bottom right of the texture and quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f); // top right of the texture and quad
glVertex2f(widthratio, 1.0f); // top right of the texture and quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f); // top left of the texture and quad
glVertex2f( -widthratio, 1.0f ); // top left of the texture and quad
glEnd();
//~logo; Ra: to jest bez sensu zapis
glColor3f(0.0f, 0.0f, 1.0f);
if (Global::detonatoryOK)
{
glRasterPos2f(-0.85f, -0.25f);
glRasterPos2f(-0.85f * widthratio, -0.25f);
glPrint("Uruchamianie / Initializing...");
glRasterPos2f(-0.85f, -0.30f);
glRasterPos2f(-0.85f * widthratio, -0.30f);
glPrint("Dzwiek / Sound...");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -519,7 +445,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Sound Init OK");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.25f, -0.30f);
glRasterPos2f(-0.25f * widthratio, -0.30f);
glPrint("OK.");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -530,7 +456,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Textures init");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.85f, -0.35f);
glRasterPos2f(-0.85f * widthratio, -0.35f);
glPrint("Tekstury / Textures...");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -540,7 +466,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Textures init OK");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.25f, -0.35f);
glRasterPos2f( -0.25f * widthratio, -0.35f );
glPrint("OK.");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -548,7 +474,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Models init");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.85f, -0.40f);
glRasterPos2f( -0.85f * widthratio, -0.40f );
glPrint("Modele / Models...");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -558,7 +484,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Models init OK");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.25f, -0.40f);
glRasterPos2f( -0.25f * widthratio, -0.40f );
glPrint("OK.");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -566,7 +492,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Ground init");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.85f, -0.45f);
glRasterPos2f( -0.85f * widthratio, -0.45f );
glPrint("Sceneria / Scenery (please wait)...");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -586,6 +512,25 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
Global::DayLight.diffuse[ 0 ] = 255.0 / 255.0;
Global::DayLight.diffuse[ 1 ] = 242.0 / 255.0;
Global::DayLight.diffuse[ 2 ] = 231.0 / 255.0;
Global::VehicleLight.id = opengl_renderer::vehiclelight;
// directional light
Global::VehicleLight.position[ 3 ] = 1.0f;
::glLightf( opengl_renderer::vehiclelight, GL_SPOT_CUTOFF, 20.0f );
::glLightf( opengl_renderer::vehiclelight, GL_SPOT_EXPONENT, 10.0f );
::glLightf( opengl_renderer::vehiclelight, GL_CONSTANT_ATTENUATION, 0.0f );
::glLightf( opengl_renderer::vehiclelight, GL_LINEAR_ATTENUATION, 0.035f );
// halogen light. TODO: allow light type definition
Global::VehicleLight.diffuse[ 0 ] = 255.0 / 255.0;
Global::VehicleLight.diffuse[ 1 ] = 241.0 / 255.0;
Global::VehicleLight.diffuse[ 2 ] = 224.0 / 255.0;
// rear light
Global::VehicleLightRear = Global::VehicleLight;
Global::VehicleLightRear.id = opengl_renderer::vehiclelightrear;
::glLightf( opengl_renderer::vehiclelightrear, GL_SPOT_CUTOFF, 20.0f );
::glLightf( opengl_renderer::vehiclelightrear, GL_SPOT_EXPONENT, 10.0f );
::glLightf( opengl_renderer::vehiclelightrear, GL_CONSTANT_ATTENUATION, 0.0f );
::glLightf( opengl_renderer::vehiclelightrear, GL_LINEAR_ATTENUATION, 0.035f );
#endif
Ground.Init(Global::SceneryFile, hDC);
@@ -594,7 +539,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Ground init OK");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.25f, -0.45f);
glRasterPos2f( -0.25f * widthratio, -0.45f );
glPrint("OK.");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -611,7 +556,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
char buff[255] = "Player train init: ";
if (Global::detonatoryOK)
{
glRasterPos2f(-0.85f, -0.50f);
glRasterPos2f( -0.85f * widthratio, -0.50f );
glPrint("Przygotowanie kabiny do sterowania...");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -632,7 +577,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Player train init OK");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.25f, -0.50f);
glRasterPos2f( -0.25f * widthratio, -0.50f );
glPrint("OK.");
}
FollowView();
@@ -644,7 +589,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie
if (Global::detonatoryOK)
{
glRasterPos2f(-0.85f, -0.50f);
glRasterPos2f( -0.85f * widthratio, -0.50f );
glPrint("Blad inicjalizacji sterowanego pojazdu!");
}
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -660,7 +605,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
Error("Player train not exist!");
if (Global::detonatoryOK)
{
glRasterPos2f(-0.85f, -0.55f);
glRasterPos2f( -0.85f * widthratio, -0.55f );
glPrint("Wybrany pojazd nie istnieje w scenerii!");
}
}
@@ -790,59 +735,97 @@ void TWorld::OnKeyDown(int cKey)
}
else if ((cKey >= VK_F1) ? (cKey <= VK_F12) : false)
{
switch (cKey)
{
case VK_F1: // czas i relacja
case VK_F3:
case VK_F5: // przesiadka do innego pojazdu
case VK_F8: // FPS
case VK_F9: // wersja, typ wyświetlania, błędy OpenGL
case VK_F10:
if (Global::iTextMode == cKey)
Global::iTextMode =
(Global::iPause && (cKey != VK_F1) ? VK_F1 :
0); // wyłączenie napisów, chyba że pauza
else
Global::iTextMode = cKey;
break;
case VK_F2: // parametry pojazdu
if (Global::iTextMode == cKey) // jeśli kolejne naciśnięcie
++Global::iScreenMode[cKey - VK_F1]; // kolejny ekran
else
{ // pierwsze naciśnięcie daje pierwszy (tzn. zerowy) ekran
Global::iTextMode = cKey;
Global::iScreenMode[cKey - VK_F1] = 0;
}
break;
case VK_F12: // coś tam jeszcze
if (Console::Pressed(VK_CONTROL) && Console::Pressed(VK_SHIFT))
DebugModeFlag = !DebugModeFlag; // taka opcjonalna funkcja, może się czasem przydać
/* //Ra 2F1P: teraz włączanie i wyłączanie klawiszami cyfrowymi po użyciu [F12]
else if (Console::Pressed(VK_SHIFT))
{//odpalenie logu w razie "W"
if ((Global::iWriteLogEnabled&2)==0) //nie było okienka
{//otwarcie okna
AllocConsole();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
}
Global::iWriteLogEnabled|=3;
} */
else
Global::iTextMode = cKey;
break;
case VK_F4:
InOutKey();
break;
case VK_F6:
if (DebugModeFlag)
{ // przyspieszenie symulacji do testowania scenerii... uwaga na FPS!
// Global::iViewMode=VK_F6;
if (Console::Pressed(VK_CONTROL))
Global::fTimeSpeed = (Console::Pressed(VK_SHIFT) ? 10.0 : 5.0);
switch (cKey) {
case VK_F1: {
// czas i relacja
if( Global::iTextMode == cKey )
Global::iTextMode =
( Global::iPause && ( cKey != VK_F1 ) ?
VK_F1 :
0 ); // wyłączenie napisów, chyba że pauza
else
Global::fTimeSpeed = (Console::Pressed(VK_SHIFT) ? 2.0 : 1.0);
Global::iTextMode = cKey;
// advance world clock in debug mode
if( DebugModeFlag ) {
if( Console::Pressed( VK_CONTROL ) ) {
// ctrl-f3
GlobalTime->UpdateMTableTime( 20.0 * 60.0 );
}
else if( Console::Pressed( VK_SHIFT ) ) {
// shift-f3
GlobalTime->UpdateMTableTime( 5.0 * 60.0 );
}
}
break;
}
case VK_F2: {
// parametry pojazdu
if( Global::iTextMode == cKey ) {
// jeśli kolejne naciśnięcie
++Global::iScreenMode[ cKey - VK_F1 ]; // kolejny ekran
}
else {
// pierwsze naciśnięcie daje pierwszy (tzn. zerowy) ekran
Global::iTextMode = cKey;
Global::iScreenMode[ cKey - VK_F1 ] = 0;
}
break;
}
case VK_F3: {
Global::iTextMode = cKey;
break;
}
case VK_F4: {
InOutKey();
break;
}
case VK_F5: {
// przesiadka do innego pojazdu
Global::iTextMode = cKey;
break;
}
case VK_F6: {
Global::iTextMode = cKey;
// przyspieszenie symulacji do testowania scenerii... uwaga na FPS!
if( DebugModeFlag ) {
if( Console::Pressed( VK_CONTROL ) ) { Global::fTimeSpeed = ( Console::Pressed( VK_SHIFT ) ? 60.0 : 20.0 ); }
else { Global::fTimeSpeed = ( Console::Pressed( VK_SHIFT ) ? 5.0 : 1.0 ); }
}
break;
}
case VK_F8: {
Global::iTextMode = cKey;
// FPS
break;
}
case VK_F9: {
Global::iTextMode = cKey;
// wersja, typ wyświetlania, błędy OpenGL
break;
}
case VK_F10: {
if( Global::iTextMode == cKey ) {
Global::iTextMode =
( Global::iPause && ( cKey != VK_F1 ) ?
VK_F1 :
0 ); // wyłączenie napisów, chyba że pauza
}
else {
Global::iTextMode = cKey;
}
break;
}
case VK_F12: {
// coś tam jeszcze
if( Console::Pressed( VK_CONTROL )
&& Console::Pressed( VK_SHIFT ) )
DebugModeFlag = !DebugModeFlag; // taka opcjonalna funkcja, może się czasem przydać
else
Global::iTextMode = cKey;
break;
}
break;
}
// if (cKey!=VK_F4)
return; // nie są przekazywane do pojazdu wcale
@@ -1181,7 +1164,8 @@ bool TWorld::Update()
iCheckFPS = 0.25 * Timer::GetFPS(); // tak za 0.25 sekundy sprawdzić ponownie (jeszcze przycina?)
}
Timer::UpdateTimers(Global::iPause);
if (!Global::iPause)
if( (Global::iPause == false)
|| (m_init == false) )
{ // jak pauza, to nie ma po co tego przeliczać
GlobalTime->UpdateMTableTime(Timer::GetDeltaTime()); // McZapkie-300302: czas rozkladowy
// Ra 2014-07: przeliczenie kąta czasu (do animacji zależnych od czasu)
@@ -1278,13 +1262,24 @@ 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
if( Train ) {
// jeśli nie usunięty
Global::bSmudge =
( FreeFlyModeFlag ?
false :
( Train->Dynamic()->fShade <= 0.0 ?
(Global::fLuminance <= 0.5) :
(Train->Dynamic()->fShade * Global::fLuminance <= 0.5) ) );
( Global::fLuminance <= 0.5 ) :
( Train->Dynamic()->fShade * Global::fLuminance <= 0.5 ) ) );
// match the vehicle light position with new position of the vehicle
Global::VehicleLight.set_position( Train->Dynamic()->GetPosition() + ( Train->Dynamic()->VectorFront() * Train->Dynamic()->GetLength() * 0.45 ) );
Global::VehicleLight.direction = Train->Dynamic()->VectorFront();
Global::VehicleLightRear.set_position( Train->Dynamic()->GetPosition() - ( Train->Dynamic()->VectorFront() * Train->Dynamic()->GetLength() * 0.45 ) );
Global::VehicleLightRear.direction = Train->Dynamic()->VectorFront();
Global::VehicleLightRear.direction.RotateY( M_PI );
}
m_init = true;
if (!Render())
return false;
@@ -1556,6 +1551,51 @@ bool TWorld::Render()
Environment.render();
}
// enable vehicle light, if it's present and on
if( nullptr != Train ) {
auto const &frontlights = Train->Controlled()->iLights[ 0 ];
int const frontlightcount = 0 +
( ( frontlights & 1 ) ? 1 : 0 ) +
( ( frontlights & 4 ) ? 1 : 0 ) +
( ( frontlights & 16 ) ? 1 : 0 );
if( frontlightcount > 0 ) {
// halogen light. TODO: allow light type definition
Global::VehicleLight.ambient[ 0 ] = 0.15f * 255.0 * frontlightcount / 255.0;
Global::VehicleLight.ambient[ 1 ] = 0.15f * 241.0 * frontlightcount / 255.0;
Global::VehicleLight.ambient[ 2 ] = 0.15f * 224.0 * frontlightcount / 255.0;
::glLightf( opengl_renderer::vehiclelight, GL_LINEAR_ATTENUATION, 0.3f / pow(frontlightcount, 2) );
glEnable( GfxRenderer.vehiclelight );
Global::VehicleLight.apply_intensity();
Global::VehicleLight.apply_angle();
}
else {
glDisable( GfxRenderer.vehiclelight );
}
auto const &rearlights = Train->Controlled()->iLights[ 1 ];
int const rearlightcount = 0 +
( ( rearlights & 1 ) ? 1 : 0 ) +
( ( rearlights & 4 ) ? 1 : 0 ) +
( ( rearlights & 16 ) ? 1 : 0 );
if( rearlightcount > 0 ) {
// halogen light. TODO: allow light type definition
Global::VehicleLightRear.ambient[ 0 ] = 0.15f * 255.0 * rearlightcount / 255.0;
Global::VehicleLightRear.ambient[ 1 ] = 0.15f * 241.0 * rearlightcount / 255.0;
Global::VehicleLightRear.ambient[ 2 ] = 0.15f * 224.0 * rearlightcount / 255.0;
::glLightf( opengl_renderer::vehiclelightrear, GL_LINEAR_ATTENUATION, 0.3f / pow( rearlightcount, 2 ) );
glEnable( GfxRenderer.vehiclelightrear );
Global::VehicleLightRear.apply_intensity();
Global::VehicleLightRear.apply_angle();
}
else {
glDisable( GfxRenderer.vehiclelightrear );
}
}
if (Global::bUseVBO)
{ // renderowanie przez VBO
if (!Ground.RenderVBO(Camera.Pos))
@@ -1618,10 +1658,11 @@ TWorld::Render_Cab() {
glLoadIdentity(); // zacząć od macierzy jedynkowej
Camera.SetCabMatrix( pos ); // widok z kamery po przesunięciu
glMultMatrixd( dynamic->mMatrix.getArray() ); // ta macierz nie ma przesunięcia
/*
//*yB: moje smuuugi 1
if( Global::bSmudge ) { // Ra: uwzględniłem zacienienie pojazdu przy zapalaniu smug
// 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
// 3. jeśli smuga właczona, wyrenderować pojazd użytkownia po dodaniu smugi do sceny
auto const &frontlights = Train->Controlled()->iLights[ 0 ];
@@ -1694,24 +1735,25 @@ 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( frontlightstrength > 0.f ) { // 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 ) * frontlightstrength;
glColor4f( C, C, C, 1.0f );// *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, 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( rearlightstrength > 0.f ) { // 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 ) * rearlightstrength;
glColor4f( C, C, C, 0.35f );// *rearlightstrength );
glColor4f( C, C, C, 1.0f );// *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 );
@@ -1728,15 +1770,18 @@ TWorld::Render_Cab() {
glEnable( GL_FOG );
}
}
*/
glEnable( GL_LIGHTING ); // po renderowaniu smugi jest to wyłączone
// Ra: pojazd użytkownika należało by renderować po smudze, aby go nie rozświetlała
Global::bSmudge = false; // aby model użytkownika się teraz wyrenderował
dynamic->Render();
dynamic->RenderAlpha(); // przezroczyste fragmenty pojazdów na torach
} // yB: moje smuuugi 1 - koniec*/
/*
} // yB: moje smuuugi 1 - koniec
else
glEnable( GL_LIGHTING ); // po renderowaniu drutów może być to wyłączone
glEnable( GL_LIGHTING ); // po renderowaniu drutów może być to wyłączone. TODO: have the wires render take care of its own shit
*/
if( dynamic->mdKabina ) // bo mogła zniknąć przy przechodzeniu do innego pojazdu
{
#ifdef EU07_USE_OLD_LIGHTING_MODEL
@@ -1822,6 +1867,10 @@ TWorld::Render_Cab() {
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseCabLight );
glLightfv( GL_LIGHT0, GL_SPECULAR, specularCabLight );
#else
// cab shouldn't get affected by the vehicle light, so we disable it here
::glDisable( GfxRenderer.vehiclelight );
::glDisable( GfxRenderer.vehiclelightrear );
if( dynamic->InteriorLightLevel > 0.0f ) {
// crude way to light the cabin, until we have something more complete in place
@@ -1866,9 +1915,9 @@ TWorld::Render_UI() {
glLoadIdentity();
if( DebugModeFlag && !Global::iTextMode ) {
OutText1 = " FPS: ";
OutText1 = "FPS: ";
OutText1 += to_string( Timer::GetFPS(), 2 );
OutText1 += Global::iSlowMotion ? "s" : "n";
OutText1 += Global::iSlowMotion ? "(s)" : "(n)";
OutText1 += ( Timer::GetDeltaTime() >= 0.2 ) ? "!" : " ";
// if (GetDeltaTime()>=0.2) //Ra: to za bardzo miota tekstem!
@@ -1883,7 +1932,7 @@ TWorld::Render_UI() {
if( Global::iTextMode == VK_F8 ) {
Global::iViewMode = VK_F8;
OutText1 = " FPS: ";
OutText1 = "FPS: ";
OutText1 += to_string( Timer::GetFPS(), 2 );
//OutText1 += sprintf();
if( Global::iSlowMotion )
@@ -2318,7 +2367,7 @@ TWorld::Render_UI() {
OutText1 +=
" " +
std::string( "S SEE NEN NWW SW" )
.substr( 1 + 2 * floor( fmod( 8 + ( Camera.Yaw + 0.5 * M_PI_4 ) / M_PI_4, 8 ) ), 2 );
.substr( 0 + 2 * floor( fmod( 8 + ( Camera.Yaw + 0.5 * M_PI_4 ) / M_PI_4, 8 ) ), 2 );
// current luminance level
OutText2 = "Light level: " + to_string( Global::fLuminance, 3 );
}
@@ -3033,9 +3082,7 @@ world_environment::update() {
auto const position = m_sun.getPosition();
// ...update the global data to match new sun state...
Global::SunAngle = m_sun.getAngle();
Global::DayLight.position[ 0 ] = position.x;
Global::DayLight.position[ 1 ] = position.y;
Global::DayLight.position[ 2 ] = position.z;
Global::DayLight.set_position( position );
Global::DayLight.direction = -1.0 * m_sun.getDirection();
// ...update skydome to match the current sun position as well...
m_skydome.Update( position );