mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 03:09:18 +02:00
ui panels continued, early matrix stack work
This commit is contained in:
51
Camera.cpp
51
Camera.cpp
@@ -115,37 +115,48 @@ vector3 TCamera::GetDirection()
|
||||
// bool TCamera::GetMatrix(matrix4x4 &Matrix)
|
||||
bool TCamera::SetMatrix()
|
||||
{
|
||||
glRotated(-Roll * 180.0f / M_PI, 0, 0, 1); // po wyłączeniu tego kręci się pojazd, a sceneria
|
||||
// nie
|
||||
glRotated(-Pitch * 180.0f / M_PI, 1, 0, 0);
|
||||
glRotated(-Yaw * 180.0f / M_PI, 0, 1, 0); // w zewnętrznym widoku: kierunek patrzenia
|
||||
glRotated( -Roll * 180.0f / M_PI, 0, 0, 1 ); // po wyłączeniu tego kręci się pojazd, a sceneria nie
|
||||
glRotated( -Pitch * 180.0f / M_PI, 1, 0, 0 );
|
||||
glRotated( -Yaw * 180.0f / M_PI, 0, 1, 0 ); // w zewnętrznym widoku: kierunek patrzenia
|
||||
|
||||
if (Type == tp_Follow)
|
||||
if( Type == tp_Follow )
|
||||
{
|
||||
// gluLookAt(Pos.x+pOffset.x,Pos.y+pOffset.y,Pos.z+pOffset.z,
|
||||
// LookAt.x+pOffset.x,LookAt.y+pOffset.y,LookAt.z+pOffset.z,vUp.x,vUp.y,vUp.z);
|
||||
// gluLookAt(Pos.x+pOffset.x,Pos.y+pOffset.y,Pos.z+pOffset.z,
|
||||
// LookAt.x+pOffset.x,LookAt.y+pOffset.y,LookAt.z+pOffset.z,vUp.x,vUp.y,vUp.z);
|
||||
gluLookAt(Pos.x, Pos.y, Pos.z, LookAt.x, LookAt.y, LookAt.z, vUp.x, vUp.y,
|
||||
vUp.z); // Ra: pOffset is zero
|
||||
// gluLookAt(Pos.x,Pos.y,Pos.z,Pos.x+Velocity.x,Pos.y+Velocity.y,Pos.z+Velocity.z,0,1,0);
|
||||
// return true;
|
||||
gluLookAt(
|
||||
Pos.x, Pos.y, Pos.z,
|
||||
LookAt.x, LookAt.y, LookAt.z,
|
||||
vUp.x, vUp.y, vUp.z); // Ra: pOffset is zero
|
||||
}
|
||||
|
||||
if (Type == tp_Satelite)
|
||||
Pitch = M_PI * 0.5;
|
||||
|
||||
if (Type != tp_Follow)
|
||||
{
|
||||
glTranslated(-Pos.x, -Pos.y, -Pos.z); // nie zmienia kierunku patrzenia
|
||||
else {
|
||||
glTranslated( -Pos.x, -Pos.y, -Pos.z ); // nie zmienia kierunku patrzenia
|
||||
}
|
||||
|
||||
Global::SetCameraPosition(Pos); // było +pOffset
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TCamera::SetMatrix( glm::mat4 &Matrix ) {
|
||||
|
||||
Matrix = glm::rotate( Matrix, (float)-Roll, glm::vec3( 0.0f, 0.0f, 1.0f ) ); // po wyłączeniu tego kręci się pojazd, a sceneria nie
|
||||
Matrix = glm::rotate( Matrix, (float)-Pitch, glm::vec3( 1.0f, 0.0f, 0.0f ) );
|
||||
Matrix = glm::rotate( Matrix, (float)-Yaw, glm::vec3( 0.0f, 1.0f, 0.0f ) ); // w zewnętrznym widoku: kierunek patrzenia
|
||||
|
||||
if( Type == tp_Follow ) {
|
||||
|
||||
Matrix = glm::lookAt(
|
||||
glm::vec3( Pos.x, Pos.y, Pos.z ),
|
||||
glm::vec3( LookAt.x, LookAt.y, LookAt.z ),
|
||||
glm::vec3( vUp.x, vUp.y, vUp.z ) );
|
||||
}
|
||||
else {
|
||||
Matrix = glm::translate( Matrix, glm::vec3( -Pos.x, -Pos.y, -Pos.z ) ); // nie zmienia kierunku patrzenia
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TCamera::SetCabMatrix(vector3 &p)
|
||||
{ // ustawienie widoku z kamery bez przesunięcia robionego przez OpenGL - nie powinno tak trząść
|
||||
|
||||
glRotated(-Roll * 180.0f / M_PI, 0, 0, 1);
|
||||
glRotated(-Pitch * 180.0f / M_PI, 1, 0, 0);
|
||||
glRotated(-Yaw * 180.0f / M_PI, 0, 1, 0); // w zewnętrznym widoku: kierunek patrzenia
|
||||
|
||||
7
Camera.h
7
Camera.h
@@ -7,8 +7,7 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#ifndef CameraH
|
||||
#define CameraH
|
||||
#pragma once
|
||||
|
||||
#include "dumb3d.h"
|
||||
#include "dynobj.h"
|
||||
@@ -51,10 +50,10 @@ class TCamera
|
||||
// vector3 inline GetCrossPos() { return Pos+GetDirection()*CrossDist+CrossPos; };
|
||||
|
||||
bool SetMatrix();
|
||||
void SetCabMatrix(vector3 &p);
|
||||
bool SetMatrix(glm::mat4 &Matrix);
|
||||
void SetCabMatrix( vector3 &p );
|
||||
void RaLook();
|
||||
void Stop();
|
||||
// bool GetMatrix(matrix4x4 &Matrix);
|
||||
vector3 PtNext, PtPrev;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -216,7 +216,7 @@ public:
|
||||
{
|
||||
return &e[i << 2];
|
||||
}
|
||||
const float * readArray(void)
|
||||
const float * readArray(void) const
|
||||
{
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ int Global::iCameraLast = -1;
|
||||
std::string Global::asRelease = "16.0.1172.482";
|
||||
std::string Global::asVersion =
|
||||
"Compilation 2017-01-10, release " + Global::asRelease + "."; // tutaj, bo wysyłany
|
||||
int Global::iViewMode = 0; // co aktualnie widać: 0-kabina, 1-latanie, 2-sprzęgi, 3-dokumenty
|
||||
int Global::iTextMode = 0; // tryb pracy wyświetlacza tekstowego
|
||||
int Global::iScreenMode[12] = {0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0}; // numer ekranu wyświetlacza tekstowego
|
||||
|
||||
@@ -270,7 +270,6 @@ class Global
|
||||
static int iCameraLast;
|
||||
static std::string asRelease; // numer
|
||||
static std::string asVersion; // z opisem
|
||||
static int iViewMode; // co aktualnie widać: 0-kabina, 1-latanie, 2-sprzęgi, 3-dokumenty, 4-obwody
|
||||
static GLint iMaxTextureSize; // maksymalny rozmiar tekstury
|
||||
static int iTextMode; // tryb pracy wyświetlacza tekstowego
|
||||
static int iScreenMode[12]; // numer ekranu wyświetlacza tekstowego
|
||||
|
||||
@@ -2620,7 +2620,7 @@ bool TGround::Init(std::string File)
|
||||
while (token != "") //(!Parser->EndOfFile)
|
||||
{
|
||||
++processed;
|
||||
if( processed % 50 == 0 )
|
||||
if( processed % 25 == 0 )
|
||||
{
|
||||
UILayer.set_progress( parser.getProgress(), parser.getFullProgress() );
|
||||
GfxRenderer.Render();
|
||||
|
||||
407
World.cpp
407
World.cpp
@@ -36,7 +36,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
TDynamicObject *Controlled = NULL; // pojazd, który prowadzimy
|
||||
|
||||
std::shared_ptr<ui_panel> UIHeader = std::make_shared<ui_panel>( 20, 20 ); // header ui panel
|
||||
std::shared_ptr<ui_panel> UITable = std::make_shared<ui_panel>( 100, 50 ); // schedule or scan table
|
||||
std::shared_ptr<ui_panel> UITable = std::make_shared<ui_panel>( 20, 100 ); // schedule or scan table
|
||||
std::shared_ptr<ui_panel> UITranscripts = std::make_shared<ui_panel>( 85, 600 ); // voice transcripts
|
||||
|
||||
extern "C"
|
||||
@@ -166,6 +166,9 @@ bool TWorld::Init( GLFWwindow *w ) {
|
||||
initpanel->text_lines.emplace_back( "Loading scenery / Wczytywanie scenerii:", float4( 0.0f, 0.0f, 0.0f, 1.0f ) );
|
||||
initpanel->text_lines.emplace_back( Global::SceneryFile.substr(0, 40), float4( 0.0f, 0.0f, 0.0f, 1.0f ) );
|
||||
UILayer.push_back( initpanel );
|
||||
UILayer.set_progress(0.01);
|
||||
|
||||
GfxRenderer.Render();
|
||||
|
||||
WriteLog( "Ground init" );
|
||||
Ground.Init(Global::SceneryFile);
|
||||
@@ -245,10 +248,10 @@ bool TWorld::Init( GLFWwindow *w ) {
|
||||
Timer::ResetTimers();
|
||||
|
||||
// make 4 empty lines for the ui header, to cut down on work down the road
|
||||
UIHeader->text_lines.emplace_back( "", float4( 100.0 / 255.0f, 230.0f / 255.0f, 230.0f / 255.0f, 1.0f ) );
|
||||
UIHeader->text_lines.emplace_back( "", float4( 100.0 / 255.0f, 230.0f / 255.0f, 230.0f / 255.0f, 1.0f ) );
|
||||
UIHeader->text_lines.emplace_back( "", float4( 100.0 / 255.0f, 230.0f / 255.0f, 230.0f / 255.0f, 1.0f ) );
|
||||
UIHeader->text_lines.emplace_back( "", float4( 100.0 / 255.0f, 230.0f / 255.0f, 230.0f / 255.0f, 1.0f ) );
|
||||
UIHeader->text_lines.emplace_back( "", float4( 225.0 / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f, 1.0f ) );
|
||||
UIHeader->text_lines.emplace_back( "", float4( 225.0 / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f, 1.0f ) );
|
||||
UIHeader->text_lines.emplace_back( "", float4( 225.0 / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f, 1.0f ) );
|
||||
UIHeader->text_lines.emplace_back( "", float4( 225.0 / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f, 1.0f ) );
|
||||
// bind the panels with ui object. maybe not the best place for this but, eh
|
||||
UILayer.push_back( UIHeader );
|
||||
UILayer.push_back( UITable );
|
||||
@@ -641,9 +644,6 @@ void TWorld::DistantView( bool const Near )
|
||||
|
||||
void TWorld::FollowView(bool wycisz)
|
||||
{ // ustawienie śledzenia pojazdu
|
||||
// ABu 180404 powrot mechanika na siedzenie albo w okolicę pojazdu
|
||||
// if (Console::Pressed(VK_F4)) Global::iViewMode=VK_F4;
|
||||
// Ra: na zewnątrz wychodzimy w Train.cpp
|
||||
Camera.Reset(); // likwidacja obrotów - patrzy horyzontalnie na południe
|
||||
if (Controlled) // jest pojazd do prowadzenia?
|
||||
{
|
||||
@@ -831,6 +831,8 @@ bool TWorld::Update()
|
||||
// variable step render time routines
|
||||
Update_Camera( dt ); // TODO: move the fixed step cab camera updates to fixed step secondary routines section
|
||||
|
||||
Update_UI();
|
||||
|
||||
GfxRenderer.Update( dt );
|
||||
ResourceSweep();
|
||||
|
||||
@@ -882,12 +884,6 @@ TWorld::Update_Camera( double const Deltatime ) {
|
||||
Global::ZoomFactor = std::max( 1.0f, Global::ZoomFactor - 15.0f * static_cast<float>( Deltatime ) );
|
||||
}
|
||||
|
||||
/*
|
||||
else if( Global::iTextMode == -1 ) { // tu mozna dodac dopisywanie do logu przebiegu lokomotywy
|
||||
WriteLog( "Number of textures used: " + std::to_string( Global::iTextures ) );
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
Camera.Update(); // uwzględnienie ruchu wywołanego klawiszami
|
||||
/*
|
||||
if( Camera.Type == tp_Follow ) {
|
||||
@@ -1348,17 +1344,278 @@ TWorld::Render_Cab() {
|
||||
}
|
||||
|
||||
void
|
||||
TWorld::Render_UI() {
|
||||
/*
|
||||
// set the UI mode projection. TODO: rework it all into somethinig more elegant... eventually
|
||||
glMatrixMode( GL_PROJECTION ); // select the Projection Matrix
|
||||
glLoadIdentity(); // reset the Projection Matrix
|
||||
// calculate the aspect ratio of the window
|
||||
gluPerspective( 45.0f, (GLdouble)Global::ScreenWidth / std::max((GLdouble)Global::ScreenHeight, 1.0), 0.2f, 2500.0f );
|
||||
glMatrixMode( GL_MODELVIEW ); // Select The Modelview Matrix
|
||||
glLoadIdentity();
|
||||
*/
|
||||
TWorld::Update_UI() {
|
||||
|
||||
OutText1 = OutText2 = OutText3 = OutText4 = "";
|
||||
UITable->text_lines.clear();
|
||||
|
||||
switch( Global::iTextMode ) {
|
||||
|
||||
case( GLFW_KEY_F1 ) : {
|
||||
// f1, default mode: current time and timetable excerpt
|
||||
OutText1 =
|
||||
"Time: "
|
||||
+ to_string( (int)GlobalTime->hh ) + ":"
|
||||
+ ( GlobalTime->mm < 10 ? "0" : "" ) + to_string( GlobalTime->mm ) + ":"
|
||||
+ ( GlobalTime->mr < 10 ? "0" : "" ) + to_string( std::floor( GlobalTime->mr ) );
|
||||
if( Global::iPause ) {
|
||||
OutText1 += " (paused)";
|
||||
}
|
||||
if( Controlled
|
||||
&& Controlled->Mechanik ) {
|
||||
OutText2 = Controlled->Mechanik->Relation();
|
||||
if( !OutText2.empty() ) {
|
||||
// jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania
|
||||
OutText3 = " -> " + Global::Bezogonkow( Controlled->Mechanik->NextStop(), true );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case( GLFW_KEY_F2 ) : {
|
||||
|
||||
TDynamicObject *tmp =
|
||||
( FreeFlyModeFlag ?
|
||||
Ground.DynamicNearest( Camera.Pos ) :
|
||||
Controlled ); // w trybie latania lokalizujemy wg mapy
|
||||
|
||||
if( tmp == nullptr ) { break; }
|
||||
|
||||
// jeśli domyślny ekran po pierwszym naciśnięciu
|
||||
OutText1 = "Vehicle name: " + tmp->MoverParameters->Name;
|
||||
|
||||
if( (tmp->Mechanik == nullptr) && (tmp->ctOwner) ) {
|
||||
// for cars other than leading unit indicate the leader
|
||||
OutText1 += ", owned by " + tmp->ctOwner->OwnerName();
|
||||
}
|
||||
// informacja o sprzęgach
|
||||
OutText1 +=
|
||||
" C0:" +
|
||||
( tmp->PrevConnected ?
|
||||
tmp->PrevConnected->GetName() + ":" + to_string( tmp->MoverParameters->Couplers[ 0 ].CouplingFlag ) :
|
||||
"none" );
|
||||
OutText1 +=
|
||||
" C1:" +
|
||||
( tmp->NextConnected ?
|
||||
tmp->NextConnected->GetName() + ":" + to_string( tmp->MoverParameters->Couplers[ 1 ].CouplingFlag ) :
|
||||
"none" );
|
||||
|
||||
OutText2 = "Damage status: " + tmp->MoverParameters->EngineDescription( 0 );
|
||||
|
||||
OutText2 += "; Brake delay: ";
|
||||
if( ( tmp->MoverParameters->BrakeDelayFlag & bdelay_G ) == bdelay_G )
|
||||
OutText2 += "G";
|
||||
if( ( tmp->MoverParameters->BrakeDelayFlag & bdelay_P ) == bdelay_P )
|
||||
OutText2 += "P";
|
||||
if( ( tmp->MoverParameters->BrakeDelayFlag & bdelay_R ) == bdelay_R )
|
||||
OutText2 += "R";
|
||||
if( ( tmp->MoverParameters->BrakeDelayFlag & bdelay_M ) == bdelay_M )
|
||||
OutText2 += "+Mg";
|
||||
|
||||
OutText2 += ", BTP:" + to_string( tmp->MoverParameters->LoadFlag, 0 );
|
||||
{
|
||||
OutText2 +=
|
||||
"; pant. "
|
||||
+ to_string( tmp->MoverParameters->PantPress, 2 )
|
||||
+ ( tmp->MoverParameters->bPantKurek3 ? "<ZG" : "|ZG" );
|
||||
}
|
||||
|
||||
OutText2 +=
|
||||
", MED:"
|
||||
+ to_string( tmp->MoverParameters->LocalBrakePosA, 2 )
|
||||
+ "+"
|
||||
+ to_string( tmp->MoverParameters->AnPos, 2 );
|
||||
|
||||
OutText2 +=
|
||||
", Ft:"
|
||||
+ to_string( tmp->MoverParameters->Ft * 0.001f, 0 );
|
||||
|
||||
OutText2 +=
|
||||
"; TC:"
|
||||
+ to_string( tmp->MoverParameters->TotalCurrent, 0 );
|
||||
OutText2 +=
|
||||
", HV0:"
|
||||
+ to_string( tmp->MoverParameters->HVCouplers[ 0 ][ 1 ], 0 )
|
||||
+ "@"
|
||||
+ to_string( tmp->MoverParameters->HVCouplers[ 0 ][ 0 ], 0 );
|
||||
OutText2 +=
|
||||
", HV1:"
|
||||
+ to_string( tmp->MoverParameters->HVCouplers[ 1 ][ 1 ], 0 )
|
||||
+ "@"
|
||||
+ to_string( tmp->MoverParameters->HVCouplers[ 1 ][ 0 ], 0 );
|
||||
|
||||
OutText3 =
|
||||
"BP: "
|
||||
+ to_string( tmp->MoverParameters->BrakePress, 2 )
|
||||
+ ", "
|
||||
+ to_string( tmp->MoverParameters->BrakeStatus, 0 )
|
||||
+ ", PP: "
|
||||
+ to_string( tmp->MoverParameters->PipePress, 2 )
|
||||
+ "/"
|
||||
+ to_string( tmp->MoverParameters->ScndPipePress, 2 )
|
||||
+ "/"
|
||||
+ to_string( tmp->MoverParameters->EqvtPipePress, 2 )
|
||||
+ ", BVP: "
|
||||
+ to_string( tmp->MoverParameters->Volume, 3 )
|
||||
+ ", "
|
||||
+ to_string( tmp->MoverParameters->CntrlPipePress, 3 )
|
||||
+ ", "
|
||||
+ to_string( tmp->MoverParameters->Hamulec->GetCRP(), 3 )
|
||||
+ ", "
|
||||
+ to_string( tmp->MoverParameters->BrakeStatus, 0 );
|
||||
|
||||
if( tmp->MoverParameters->ManualBrakePos > 0 ) {
|
||||
|
||||
OutText3 += ", manual brake on";
|
||||
}
|
||||
|
||||
if( tmp->MoverParameters->LocalBrakePos > 0 ) {
|
||||
|
||||
OutText3 += ", local brake on";
|
||||
}
|
||||
else {
|
||||
|
||||
OutText3 += ", local brake off";
|
||||
}
|
||||
|
||||
if( tmp->Mechanik ) {
|
||||
// o ile jest ktoś w środku
|
||||
std::string flags = "bwaccmlshhhoibsgvdp; "; // flagi AI (definicja w Driver.h)
|
||||
for( int i = 0, j = 1; i < 19; ++i, j <<= 1 )
|
||||
if( tmp->Mechanik->DrivigFlags() & j ) // jak bit ustawiony
|
||||
flags[ i + 1 ] = std::toupper( flags[ i + 1 ] ); // ^= 0x20; // to zmiana na wielką literę
|
||||
|
||||
OutText4 = flags;
|
||||
|
||||
OutText4 +=
|
||||
"Driver: Vd=" + to_string( tmp->Mechanik->VelDesired, 0 )
|
||||
+ " ad=" + to_string( tmp->Mechanik->AccDesired, 2 )
|
||||
+ " Pd=" + to_string( tmp->Mechanik->ActualProximityDist, 0 )
|
||||
+ " Vn=" + to_string( tmp->Mechanik->VelNext, 0 )
|
||||
+ " VSm=" + to_string( tmp->Mechanik->VelSignalLast, 0 )
|
||||
+ " VLm=" + to_string( tmp->Mechanik->VelLimitLast, 0 )
|
||||
+ " VRd=" + to_string( tmp->Mechanik->VelRoad, 0 );
|
||||
|
||||
if( ( tmp->Mechanik->VelNext == 0.0 )
|
||||
&& ( tmp->Mechanik->eSignNext ) ) {
|
||||
// jeśli ma zapamiętany event semafora, nazwa eventu semafora
|
||||
OutText4 +=
|
||||
" ("
|
||||
+ Global::Bezogonkow( tmp->Mechanik->eSignNext->asName )
|
||||
+ ")";
|
||||
}
|
||||
|
||||
// biezaca komenda dla AI
|
||||
OutText4 += ", command: " + tmp->Mechanik->OrderCurrent();
|
||||
}
|
||||
|
||||
if( Global::iScreenMode[ Global::iTextMode - GLFW_KEY_F1 ] != 0 ) {
|
||||
// f2 screen, track scan mode
|
||||
if( tmp->Mechanik == nullptr ) {
|
||||
//żeby była tabelka, musi być AI
|
||||
break;
|
||||
}
|
||||
|
||||
float4 linecolor( 225.0 / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f, 1.0f );
|
||||
int i = 0;
|
||||
do {
|
||||
std::string scanline = tmp->Mechanik->TableText( i );
|
||||
if( scanline.empty() ) { break; }
|
||||
UITable->text_lines.emplace_back( Global::Bezogonkow( scanline ), linecolor );
|
||||
++i;
|
||||
} while( i < 16 ); // TController:iSpeedTableSize TODO: change when the table gets recoded
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case( GLFW_KEY_F3 ) : {
|
||||
// timetable
|
||||
|
||||
TDynamicObject *tmp =
|
||||
( FreeFlyModeFlag ?
|
||||
Ground.DynamicNearest( Camera.Pos ) :
|
||||
Controlled ); // w trybie latania lokalizujemy wg mapy
|
||||
|
||||
if( tmp == nullptr ) { break; }
|
||||
if( tmp->Mechanik == nullptr ) { break; }
|
||||
|
||||
auto const table = tmp->Mechanik->Timetable();
|
||||
if( table == nullptr ) { break; }
|
||||
|
||||
OutText1 =
|
||||
"Time: "
|
||||
+ to_string( (int)GlobalTime->hh ) + ":"
|
||||
+ ( GlobalTime->mm < 10 ? "0" : "" ) + to_string( GlobalTime->mm ) + ":"
|
||||
+ ( GlobalTime->mr < 10 ? "0" : "" ) + to_string( std::floor( GlobalTime->mr ) );
|
||||
if( Global::iPause ) {
|
||||
OutText1 += " (paused)";
|
||||
}
|
||||
|
||||
OutText2 = tmp->Mechanik->Relation() + " (" + tmp->Mechanik->Timetable()->TrainName + ")";
|
||||
|
||||
float4 linecolor( 225.0 / 255.0f, 225.0f / 255.0f, 225.0f / 255.0f, 1.0f );
|
||||
|
||||
if( 0 == table->StationCount ) {
|
||||
// only bother if there's stations to list
|
||||
UITable->text_lines.emplace_back( "(no timetable)", linecolor );
|
||||
}
|
||||
else {
|
||||
// header
|
||||
UITable->text_lines.emplace_back( "+----------------------------+-------+-------+-----+", linecolor );
|
||||
|
||||
TMTableLine *tableline;
|
||||
for( int i = tmp->Mechanik->iStationStart; i <= std::min(15, table->StationCount); ++i ) {
|
||||
// wyświetlenie pozycji z rozkładu
|
||||
tableline = table->TimeTable + i; // linijka rozkładu
|
||||
|
||||
std::string station =
|
||||
( tableline->StationName + " " ).substr( 0, 26 );
|
||||
std::string arrival =
|
||||
( tableline->Ah >= 0 ?
|
||||
to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Am ) ).substr( 1, 2 ) :
|
||||
" " );
|
||||
std::string departure =
|
||||
( tableline->Dh >= 0 ?
|
||||
to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Dm ) ).substr( 1, 2 ) :
|
||||
" " );
|
||||
std::string vmax =
|
||||
" "
|
||||
+ to_string( tableline->vmax, 0 );
|
||||
vmax = vmax.substr( vmax.length() - 3, 3 ); // z wyrównaniem do prawej
|
||||
|
||||
UITable->text_lines.emplace_back(
|
||||
Global::Bezogonkow( "| " + station + " | " + arrival + " | " + departure + " | " + vmax + " | " + tableline->StationWare, true ),
|
||||
( ( tmp->Mechanik->iStationStart < table->StationIndex ) && ( i < table->StationIndex ) ?
|
||||
float4( 0.0f, 1.0f, 0.0f, 1.0f ) :// czas minął i odjazd był, to nazwa stacji będzie na zielono
|
||||
linecolor )
|
||||
);
|
||||
// divider/footer
|
||||
UITable->text_lines.emplace_back( "+----------------------------+-------+-------+-----+", linecolor );
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case( GLFW_KEY_F10 ) : {
|
||||
|
||||
OutText1 = ( "Press [Y] key to quit / Aby zakonczyc program, przycisnij klawisz [Y]." );
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
// uncovered cases, nothing to do here
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if( DebugModeFlag && !Global::iTextMode ) {
|
||||
OutText1 = "FPS: ";
|
||||
@@ -1368,7 +1625,6 @@ TWorld::Render_UI() {
|
||||
OutText1 += ( Timer::GetDeltaTime() >= 0.2 ) ? "!" : " ";
|
||||
}
|
||||
if( Global::iTextMode == GLFW_KEY_F8 ) {
|
||||
Global::iViewMode = GLFW_KEY_F8;
|
||||
OutText1 = "Draw range x " + to_string( Global::fDistanceFactor, 1 ) + "; FPS: " + to_string( Timer::GetFPS(), 2 );
|
||||
//OutText1 += sprintf();
|
||||
if( Global::iSlowMotion )
|
||||
@@ -1440,6 +1696,7 @@ TWorld::Render_UI() {
|
||||
glTranslatef( 0.0f, 0.0f, -0.50f );
|
||||
|
||||
if( Global::iTextMode == GLFW_KEY_F1 ) { // tekst pokazywany po wciśnięciu [F1]
|
||||
#ifdef EU07_OLD_UI_RENDERING
|
||||
// Global::iViewMode=VK_F1;
|
||||
glColor3f( 1.0f, 1.0f, 1.0f ); // a, damy białym
|
||||
OutText1 =
|
||||
@@ -1459,6 +1716,7 @@ TWorld::Render_UI() {
|
||||
true ); // dopisanie punktu zatrzymania
|
||||
}
|
||||
OutText3 = ""; // Pomoc w sterowaniu - [F9]";
|
||||
#endif
|
||||
}
|
||||
else if( Global::iTextMode == GLFW_KEY_F12 ) { // opcje włączenia i wyłączenia logowania
|
||||
OutText1 = "[0] Debugmode " + std::string( DebugModeFlag ? "(on)" : "(off)" );
|
||||
@@ -1466,6 +1724,7 @@ TWorld::Render_UI() {
|
||||
OutText3 = "[2] Console " + std::string( ( Global::iWriteLogEnabled & 2 ) ? "(on)" : "(off)" );
|
||||
}
|
||||
else if( Global::iTextMode == GLFW_KEY_F2 ) { // ABu: info dla najblizszego pojazdu!
|
||||
#ifdef EU07_OLD_UI_RENDERING
|
||||
TDynamicObject *tmp = FreeFlyModeFlag ? Ground.DynamicNearest( Camera.Pos ) :
|
||||
Controlled; // w trybie latania lokalizujemy wg mapy
|
||||
if( tmp ) {
|
||||
@@ -1589,7 +1848,6 @@ TWorld::Render_UI() {
|
||||
}
|
||||
} // koniec treści podstawowego ekranu FK_V2
|
||||
else { // ekran drugi, czyli tabelka skanowania AI
|
||||
/*
|
||||
if( tmp->Mechanik ) //żeby była tabelka, musi być AI
|
||||
{ // tabelka jest na użytek testujących scenerie, więc nie musi być "ładna"
|
||||
glColor3f( 1.0f, 1.0f, 1.0f ); // a, damy zielony. GF: jednak biały
|
||||
@@ -1637,7 +1895,6 @@ TWorld::Render_UI() {
|
||||
glRasterPos2f( -0.25f, 0.19f - 0.01f * i );
|
||||
glPrint( Global::Bezogonkow( OutText4 ).c_str() );
|
||||
}
|
||||
*/
|
||||
} // koniec ekanu skanowania
|
||||
} // koniec obsługi, gdy mamy wskaźnik do pojazdu
|
||||
else { // wyświetlenie współrzędnych w scenerii oraz kąta kamery, gdy nie mamy wskaźnika
|
||||
@@ -1654,6 +1911,7 @@ TWorld::Render_UI() {
|
||||
OutText2 = "Light level: " + to_string( Global::fLuminance, 3 );
|
||||
if( Global::FakeLight ) { OutText2 += "(*)"; }
|
||||
}
|
||||
#endif
|
||||
} // koniec treści podstawowego ekranu FK_V2
|
||||
else if( Global::iTextMode == GLFW_KEY_F5 ) { // przesiadka do innego pojazdu
|
||||
if( FreeFlyModeFlag ) // jeśli tryb latania
|
||||
@@ -1686,12 +1944,6 @@ TWorld::Render_UI() {
|
||||
Global::iTextMode = 0; // tryb neutralny
|
||||
}
|
||||
}
|
||||
else if( Global::iTextMode == GLFW_KEY_F10 ) { // tu mozna dodac dopisywanie do logu przebiegu lokomotywy
|
||||
// Global::iViewMode=VK_F10;
|
||||
// return false;
|
||||
OutText1 = ( "To quit press [Y] key." );
|
||||
OutText3 = ( "Aby zakonczyc program, przycisnij klawisz [Y]." );
|
||||
}
|
||||
else if( Controlled && DebugModeFlag && !Global::iTextMode ) {
|
||||
OutText1 += ( "; vel " ) + to_string( Controlled->GetVelocity(), 2 );
|
||||
OutText1 += ( "; pos " ) + to_string( Controlled->GetPosition().x, 2 );
|
||||
@@ -1881,92 +2133,6 @@ TWorld::Render_UI() {
|
||||
Global::Bezogonkow( ( (char *)gluErrorString( err ) ) );
|
||||
}
|
||||
}
|
||||
if( Global::iTextMode == GLFW_KEY_F3 ) { // wyświetlenie rozkładu jazdy, na razie jakkolwiek
|
||||
TDynamicObject *tmp = FreeFlyModeFlag ?
|
||||
Ground.DynamicNearest( Camera.Pos ) :
|
||||
Controlled; // w trybie latania lokalizujemy wg mapy
|
||||
Mtable::TTrainParameters *tt = NULL;
|
||||
/*
|
||||
if( tmp )
|
||||
if( tmp->Mechanik ) {
|
||||
tt = tmp->Mechanik->Timetable();
|
||||
if( tt ) // musi być rozkład
|
||||
{ // wyświetlanie rozkładu
|
||||
glColor3f( 1.0f, 1.0f, 1.0f ); // a, damy białym
|
||||
// glTranslatef(0.0f,0.0f,-0.50f);
|
||||
glRasterPos2f( -0.25f, 0.20f );
|
||||
OutText1 = tmp->Mechanik->Relation() + " (" +
|
||||
tmp->Mechanik->Timetable()->TrainName + ")";
|
||||
glPrint( Global::Bezogonkow( OutText1, true ).c_str() );
|
||||
glRasterPos2f( -0.25f, 0.19f );
|
||||
// glPrint("|============================|=======|=======|=====|");
|
||||
// glPrint("| Posterunek | Przyj.| Odjazd| Vmax|");
|
||||
// glPrint("|============================|=======|=======|=====|");
|
||||
glPrint( "|----------------------------|-------|-------|-----|" );
|
||||
TMTableLine *t;
|
||||
for( int i = tmp->Mechanik->iStationStart; i <= tt->StationCount; ++i ) { // wyświetlenie pozycji z rozkładu
|
||||
t = tt->TimeTable + i; // linijka rozkładu
|
||||
OutText1 = ( t->StationName +
|
||||
" " ).substr( 0, 26 );
|
||||
OutText2 = ( t->Ah >= 0 ) ?
|
||||
to_string( int( 100 + t->Ah ) ).substr( 1, 2 ) + ":" +
|
||||
to_string( int( 100 + t->Am ) ).substr( 1, 2 ) :
|
||||
std::string( " " );
|
||||
OutText3 = ( t->Dh >= 0 ) ?
|
||||
to_string( int( 100 + t->Dh ) ).substr( 1, 2 ) + ":" +
|
||||
to_string( int( 100 + t->Dm ) ).substr( 1, 2 ) :
|
||||
std::string( " " );
|
||||
OutText4 = " " + to_string( t->vmax, 0 );
|
||||
OutText4 = OutText4.substr( OutText4.length() - 3,
|
||||
3 ); // z wyrównaniem do prawej
|
||||
// if (AnsiString(t->StationWare).Pos("@"))
|
||||
OutText1 = "| " + OutText1 + " | " + OutText2 + " | " + OutText3 +
|
||||
" | " + OutText4 + " | " + t->StationWare;
|
||||
glRasterPos2f( -0.25f,
|
||||
0.18f - 0.02f * ( i - tmp->Mechanik->iStationStart ) );
|
||||
if( ( tmp->Mechanik->iStationStart < tt->StationIndex ) ?
|
||||
( i < tt->StationIndex ) :
|
||||
false ) { // czas minął i odjazd był, to nazwa stacji będzie na zielono
|
||||
glColor3f( 0.0f, 1.0f, 0.0f ); // zielone
|
||||
glRasterPos2f(
|
||||
-0.25f,
|
||||
0.18f - 0.02f * ( i - tmp->Mechanik->iStationStart ) );
|
||||
glPrint( Global::Bezogonkow( OutText1, true ).c_str() );
|
||||
glColor3f( 1.0f, 1.0f, 1.0f ); // a reszta białym
|
||||
}
|
||||
else // normalne wyświetlanie, bez zmiany kolorów
|
||||
glPrint( Global::Bezogonkow( OutText1, true ).c_str() );
|
||||
glRasterPos2f( -0.25f,
|
||||
0.17f - 0.02f * ( i - tmp->Mechanik->iStationStart ) );
|
||||
glPrint( "|----------------------------|-------|-------|-----|" );
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
/*
|
||||
else if( OutText1 != "" ) { // ABu: i od razu czyszczenie tego, co bylo napisane
|
||||
// glTranslatef(0.0f,0.0f,-0.50f);
|
||||
glRasterPos2f( -0.25f, 0.20f );
|
||||
glPrint( OutText1.c_str() );
|
||||
OutText1 = "";
|
||||
if( OutText2 != "" ) {
|
||||
glRasterPos2f( -0.25f, 0.19f );
|
||||
glPrint( OutText2.c_str() );
|
||||
OutText2 = "";
|
||||
}
|
||||
if( OutText3 != "" ) {
|
||||
glRasterPos2f( -0.25f, 0.18f );
|
||||
glPrint( OutText3.c_str() );
|
||||
OutText3 = "";
|
||||
if( OutText4 != "" ) {
|
||||
glRasterPos2f( -0.25f, 0.17f );
|
||||
glPrint( OutText4.c_str() );
|
||||
OutText4 = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// update the ui header texts
|
||||
auto &headerdata = UIHeader->text_lines;
|
||||
@@ -1991,9 +2157,6 @@ TWorld::Render_UI() {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
glEnable( GL_LIGHTING );
|
||||
*/
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
2
World.h
2
World.h
@@ -69,9 +69,9 @@ class TWorld
|
||||
std::string OutText4;
|
||||
void Update_Environment();
|
||||
void Update_Camera( const double Deltatime );
|
||||
void Update_UI();
|
||||
void ResourceSweep();
|
||||
void Render_Cab();
|
||||
void Render_UI();
|
||||
TCamera Camera;
|
||||
TGround Ground;
|
||||
world_environment Environment;
|
||||
|
||||
21
frustum.cpp
21
frustum.cpp
@@ -11,15 +11,30 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "frustum.h"
|
||||
|
||||
void
|
||||
cFrustum::calculate() {
|
||||
|
||||
cFrustum::calculate( glm::mat4 &Projection, glm::mat4 &Modelview ) {
|
||||
/*
|
||||
float proj[ 16 ];
|
||||
*/
|
||||
float modl[ 16 ];
|
||||
float clip[ 16 ];
|
||||
|
||||
float *proj = &Projection[ 0 ][ 0 ];
|
||||
/*
|
||||
float *modl = &Modelview[ 0 ][ 0 ];
|
||||
*/
|
||||
float clip[ 16 ];
|
||||
/*
|
||||
glGetFloatv( GL_PROJECTION_MATRIX, proj );
|
||||
*/
|
||||
glGetFloatv( GL_MODELVIEW_MATRIX, modl );
|
||||
|
||||
glm::mat4 modelview = glm::make_mat4( modl );
|
||||
for( int col = 0; col < 4; ++col )
|
||||
for( int row = 0; row < 4; ++row ) {
|
||||
|
||||
auto difference = modelview[ col ][ row ] - Modelview[ col ][ row ];
|
||||
// assert( difference <= 0.01f );
|
||||
}
|
||||
|
||||
// multiply the matrices to retrieve clipping planes
|
||||
clip[ 0 ] = modl[ 0 ] * proj[ 0 ] + modl[ 1 ] * proj[ 4 ] + modl[ 2 ] * proj[ 8 ] + modl[ 3 ] * proj[ 12 ];
|
||||
clip[ 1 ] = modl[ 0 ] * proj[ 1 ] + modl[ 1 ] * proj[ 5 ] + modl[ 2 ] * proj[ 9 ] + modl[ 3 ] * proj[ 13 ];
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
// methods:
|
||||
// update the frustum to match current view orientation
|
||||
void
|
||||
calculate();
|
||||
calculate(glm::mat4 &Projection, glm::mat4 &Modelview);
|
||||
// returns true if specified point is inside of the frustum
|
||||
inline
|
||||
bool
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)console;$(SolutionDir)mczapkie;$(SolutionDir)ref/glfw/include;$(SolutionDir)ref/glew/include;$(SolutionDir)ref/libpng/include;$(SolutionDir)ref/python/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)console;$(SolutionDir)mczapkie;$(SolutionDir)ref/glfw/include;$(SolutionDir)ref/glew/include;$(SolutionDir)ref/glm;$(SolutionDir)ref/libpng/include;$(SolutionDir)ref/python/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
@@ -70,7 +70,7 @@
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)console;$(SolutionDir)mczapkie;$(SolutionDir)ref/glfw/include;$(SolutionDir)ref/glew/include;$(SolutionDir)ref/libpng/include;$(SolutionDir)ref/python/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)console;$(SolutionDir)mczapkie;$(SolutionDir)ref/glfw/include;$(SolutionDir)ref/glew/include;$(SolutionDir)ref/glm;$(SolutionDir)ref/libpng/include;$(SolutionDir)ref/python/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
|
||||
29
renderer.cpp
29
renderer.cpp
@@ -8,6 +8,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "renderer.h"
|
||||
#include "globals.h"
|
||||
#include "world.h"
|
||||
@@ -123,26 +124,31 @@ opengl_renderer::Render() {
|
||||
|
||||
auto timestart = std::chrono::steady_clock::now();
|
||||
|
||||
// ::glColor3ub( 255, 255, 255 );
|
||||
::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
::glDepthFunc( GL_LEQUAL );
|
||||
|
||||
::glMatrixMode( GL_PROJECTION ); // select the Projection Matrix
|
||||
::glLoadIdentity(); // reset the Projection Matrix
|
||||
// calculate the aspect ratio of the window
|
||||
::gluPerspective(
|
||||
Global::FieldOfView / Global::ZoomFactor,
|
||||
(GLdouble)Global::ScreenWidth / std::max( (GLdouble)Global::ScreenHeight, 1.0 ),
|
||||
glm::mat4 projection = glm::perspective(
|
||||
Global::FieldOfView / Global::ZoomFactor * 0.0174532925f,
|
||||
(float)Global::ScreenWidth / std::max( (float)Global::ScreenHeight, 1.0f ),
|
||||
0.1f * Global::ZoomFactor,
|
||||
m_drawrange * Global::fDistanceFactor );
|
||||
::glLoadMatrixf( &projection[0][0] );
|
||||
|
||||
::glMatrixMode( GL_MODELVIEW ); // Select The Modelview Matrix
|
||||
glm::mat4 modelview( 1.0f );
|
||||
::glLoadIdentity();
|
||||
|
||||
if( World.InitPerformed() ) {
|
||||
|
||||
World.Camera.SetMatrix( modelview );
|
||||
World.Camera.SetMatrix(); // ustawienie macierzy kamery względem początku scenerii
|
||||
m_camera.update_frustum();
|
||||
/*
|
||||
// NOTE: something in the cab mode render interferes with straightforward opengl matrix setup here
|
||||
// until it's sorted out, we're relying on direct matrix configuration through setmatrix() variant
|
||||
::glLoadMatrixf( &modelview[ 0 ][ 0 ] );
|
||||
*/
|
||||
m_camera.update_frustum( projection, modelview );
|
||||
|
||||
if( !Global::bWireFrame ) {
|
||||
// bez nieba w trybie rysowania linii
|
||||
@@ -152,10 +158,9 @@ opengl_renderer::Render() {
|
||||
World.Ground.Render( World.Camera.Pos );
|
||||
|
||||
World.Render_Cab();
|
||||
World.Render_UI();
|
||||
|
||||
// accumulate last 20 frames worth of render time
|
||||
m_drawtime = 0.95f * m_drawtime + std::chrono::duration_cast<std::chrono::milliseconds>( ( std::chrono::steady_clock::now() - timestart ) ).count();
|
||||
// accumulate last 20 frames worth of render time (cap at 1000 fps to prevent calculations going awry)
|
||||
m_drawtime = std::max( 20.0f, 0.95f * m_drawtime + std::chrono::duration_cast<std::chrono::milliseconds>( ( std::chrono::steady_clock::now() - timestart ) ).count());
|
||||
}
|
||||
|
||||
UILayer.render();
|
||||
@@ -420,7 +425,7 @@ opengl_renderer::Update ( double const Deltatime ) {
|
||||
m_updateaccumulator = 0.0;
|
||||
|
||||
// adjust draw ranges etc, based on recent performance
|
||||
auto const framerate = 1000.0f / (m_drawtime * 0.05f);
|
||||
auto const framerate = 1000.0f / (m_drawtime / 20.0f);
|
||||
|
||||
// NOTE: until we have quadtree in place we have to rely on the legacy rendering
|
||||
// once this is resolved we should be able to simply adjust draw range
|
||||
@@ -552,5 +557,7 @@ opengl_renderer::Init_caps() {
|
||||
WriteLog( "Texture sizes capped at " + std::to_string( Global::iMaxTextureSize ) + " pixels" );
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
// methods:
|
||||
inline
|
||||
void
|
||||
update_frustum() { m_frustum.calculate(); }
|
||||
update_frustum(glm::mat4 &Projection, glm::mat4 &Modelview) { m_frustum.calculate(Projection, Modelview); }
|
||||
bool
|
||||
visible( bounding_area const &Area ) const;
|
||||
bool
|
||||
@@ -163,7 +163,7 @@ private:
|
||||
texture_manager m_textures;
|
||||
opengl_camera m_camera;
|
||||
float m_drawrange{ 2500.0f }; // current drawing range
|
||||
float m_drawtime{ 30.0f * 20.0f }; // start with presumed 'neutral' average of 30 fps
|
||||
float m_drawtime{ 1000.0f / 30.0f * 20.0f }; // start with presumed 'neutral' average of 30 fps
|
||||
double m_updateaccumulator{ 0.0 };
|
||||
GLFWwindow *m_window{ nullptr };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user