diff --git a/DynObj.cpp b/DynObj.cpp index 0bdfc85b..ed0de3ae 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -3710,7 +3710,7 @@ void TDynamicObject::Render() // zmienne renderme = false; // przeklejka - double ObjSqrDist = SquareMagnitude(Global::pCameraPosition - vPosition); + double ObjSqrDist = SquareMagnitude(Global::pCameraPosition - vPosition) / Global::ZoomFactor; // koniec przeklejki if (ObjSqrDist < 500) // jak jest blisko - do 70m modelrotate = 0.01; // mały kąt, żeby nie znikało @@ -3737,7 +3737,7 @@ void TDynamicObject::Render() { TSubModel::iInstance = (int)this; //żeby nie robić cudzych animacji // AnsiString asLoadName=""; - double ObjSqrDist = SquareMagnitude(Global::pCameraPosition - vPosition); + double ObjSqrDist = SquareMagnitude(Global::pCameraPosition - vPosition) / Global::ZoomFactor; ABuLittleUpdate(ObjSqrDist); // ustawianie zmiennych submodeli dla wspólnego modelu // Cone(vCoulpler[0],modelRot.z,0); diff --git a/EU07.cpp b/EU07.cpp index 3a071cd3..b02ef876 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -85,17 +85,19 @@ int InitGL(GLvoid) // All Setup For OpenGL Goes Here GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // resize and initialize the GL Window { - WindowWidth = width; - WindowHeight = height; + Global::ScreenWidth = WindowWidth = width; + Global::ScreenHeight = WindowHeight = height; if (height == 0) // prevent a divide by zero by height = 1; // making height equal one glViewport(0, 0, width, height); // Reset The Current Viewport +/* glMatrixMode(GL_PROJECTION); // select the Projection Matrix glLoadIdentity(); // reset the Projection Matrix // calculate the aspect ratio of the window gluPerspective(45.0f, (GLdouble)width / (GLdouble)height, 0.2f, 2500.0f); glMatrixMode(GL_MODELVIEW); // select the Modelview Matrix glLoadIdentity(); // reset the Modelview Matrix +*/ } //--------------------------------------------------------------------------- diff --git a/Gauge.cpp b/Gauge.cpp index 04091419..b9870eab 100644 --- a/Gauge.cpp +++ b/Gauge.cpp @@ -175,14 +175,16 @@ void TGauge::Update() */ std::string n( "000000000" + std::to_string( static_cast( std::floor( fValue ) ) ) ); if( n.length() > 10 ) { n.erase( 0, n.length() - 10 ); } // also dumb but should work for now do - { // pętla po submodelach potomnych i obracanie ich o kąt zależy od - // cyfry w (fValue) - if (sm->pName) - { // musi mieć niepustą nazwę - if (sm->pName[0] >= '0') - if (sm->pName[0] <= '9') - sm->SetRotate(float3(0, 1, 0), - -36.0 * (n['0' + 10 - sm->pName[0]] - '0')); + { // pętla po submodelach potomnych i obracanie ich o kąt zależy od cyfry w (fValue) + if( sm->pName ) { + // musi mieć niepustą nazwę + if( ( sm->pName[ 0 ] >= '0' ) + && ( sm->pName[ 0 ] <= '9' ) ) { + + sm->SetRotate( + float3( 0, 1, 0 ), + -36.0 * ( n[ '0' + 9 - sm->pName[ 0 ] ] - '0' ) ); + } } sm = sm->NextGet(); } while (sm); diff --git a/Globals.cpp b/Globals.cpp index c5e613fc..3e0c0f9b 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -49,6 +49,9 @@ bool Global::bOpenGL_1_5 = false; // czy są dostępne funkcje OpenGL 1.5 double Global::fLuminance = 1.0; // jasność światła do automatycznego zapalania int Global::iReCompile = 0; // zwiększany, gdy trzeba odświeżyć siatki HWND Global::hWnd = NULL; // uchwyt okna +int Global::ScreenWidth = 1; +int Global::ScreenHeight = 1; +float Global::ZoomFactor = 1.0f; int Global::iCameraLast = -1; std::string Global::asRelease = "16.0.1172.482"; std::string Global::asVersion = diff --git a/Globals.h b/Globals.h index d63af985..c4970efe 100644 --- a/Globals.h +++ b/Globals.h @@ -253,6 +253,9 @@ class Global static double fLuminance; // jasność światła do automatycznego zapalania static int iMultiplayer; // blokada działania niektórych eventów na rzecz kominikacji static HWND hWnd; // uchwyt okna + static int ScreenWidth; // current window dimensions. TODO: move it to renderer + static int ScreenHeight; + static float ZoomFactor; // determines current camera zoom level. TODO: move it to the renderer static int iCameraLast; static std::string asRelease; // numer static std::string asVersion; // z opisem diff --git a/Ground.cpp b/Ground.cpp index b1d55d3c..bfd4a344 100644 --- a/Ground.cpp +++ b/Ground.cpp @@ -555,7 +555,7 @@ void TGroundNode::RenderDL() return smTerrain->RenderDL(); } // if (pTriGroup) if (pTriGroup!=this) return; //wyświetla go inny obiekt - double mgn = SquareMagnitude(pCenter - Global::pCameraPosition); + double mgn = SquareMagnitude(pCenter - Global::pCameraPosition) / Global::ZoomFactor; if ((mgn > fSquareRadius) || (mgn < fSquareMinRadius)) // McZapkie-070602: nie rysuj odleglych // obiektow ale sprawdzaj wyzwalacz // zdarzen @@ -615,7 +615,7 @@ void TGroundNode::RenderAlphaDL() // i jezeli tak to odpowiedni GL_GREATER w przeciwnym wypadku standardowy 0.04 // if (pTriGroup) if (pTriGroup!=this) return; //wyświetla go inny obiekt - double mgn = SquareMagnitude(pCenter - Global::pCameraPosition); + double mgn = SquareMagnitude(pCenter - Global::pCameraPosition) / Global::ZoomFactor; float r, g, b; if (mgn < fSquareMinRadius) return; diff --git a/World.cpp b/World.cpp index df7d559b..5e47971c 100644 --- a/World.cpp +++ b/World.cpp @@ -485,21 +485,21 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) glBegin(GL_QUADS); // Drawing using triangles glTexCoord2f(0.0f, 0.0f); - glVertex3f(-0.28f, -0.22f, 0.0f); // bottom left of the texture and quad + glVertex3f(-1.0f, -1.0f, 0.0f); // bottom left of the texture and quad glTexCoord2f(1.0f, 0.0f); - glVertex3f(0.28f, -0.22f, 0.0f); // bottom right of the texture and quad + glVertex3f(1.0f, -1.0f, 0.0f); // bottom right of the texture and quad glTexCoord2f(1.0f, 1.0f); - glVertex3f(0.28f, 0.22f, 0.0f); // top right of the texture and quad + glVertex3f(1.0f, 1.0f, 0.0f); // top right of the texture and quad glTexCoord2f(0.0f, 1.0f); - glVertex3f(-0.28f, 0.22f, 0.0f); // top left of the texture and quad + glVertex3f(-1.0f, 1.0f, 0.0f); // top left of the texture and quad glEnd(); //~logo; Ra: to jest bez sensu zapis glColor3f(0.0f, 0.0f, 100.0f); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.09f); + glRasterPos2f(-0.85f, -0.25f); glPrint("Uruchamianie / Initializing..."); - glRasterPos2f(-0.25f, -0.10f); + glRasterPos2f(-0.85f, -0.30f); glPrint("Dzwiek / Sound..."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -512,7 +512,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Sound Init OK"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.11f); + glRasterPos2f(-0.25f, -0.30f); glPrint("OK."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -523,7 +523,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Textures init"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.12f); + glRasterPos2f(-0.85f, -0.35f); glPrint("Tekstury / Textures..."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -533,7 +533,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Textures init OK"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.13f); + glRasterPos2f(-0.25f, -0.35f); glPrint("OK."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -541,7 +541,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Models init"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.14f); + glRasterPos2f(-0.85f, -0.40f); glPrint("Modele / Models..."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -551,7 +551,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Models init OK"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.15f); + glRasterPos2f(-0.25f, -0.40f); glPrint("OK."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -559,7 +559,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Ground init"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.16f); + glRasterPos2f(-0.85f, -0.45f); glPrint("Sceneria / Scenery (please wait)..."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -570,7 +570,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Ground init OK"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.17f); + glRasterPos2f(-0.25f, -0.45f); glPrint("OK."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -587,7 +587,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) char buff[255] = "Player train init: "; if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.18f); + glRasterPos2f(-0.85f, -0.50f); glPrint("Przygotowanie kabiny do sterowania..."); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -608,7 +608,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) WriteLog("Player train init OK"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.19f); + glRasterPos2f(-0.25f, -0.50f); glPrint("OK."); } FollowView(); @@ -620,7 +620,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.20f); + glRasterPos2f(-0.85f, -0.50f); glPrint("Blad inicjalizacji sterowanego pojazdu!"); } SwapBuffers(hDC); // Swap Buffers (Double Buffering) @@ -636,7 +636,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC) Error("Player train not exist!"); if (Global::detonatoryOK) { - glRasterPos2f(-0.25f, -0.20f); + glRasterPos2f(-0.85f, -0.55f); glPrint("Wybrany pojazd nie istnieje w scenerii!"); } } @@ -984,7 +984,7 @@ void TWorld::OnKeyUp(int cKey) void TWorld::OnMouseMove(double x, double y) { // McZapkie:060503-definicja obracania myszy - Camera.OnCursorMove(x * Global::fMouseXScale, -y * Global::fMouseYScale); + Camera.OnCursorMove(x * Global::fMouseXScale / Global::ZoomFactor, -y * Global::fMouseYScale / Global::ZoomFactor); } void TWorld::InOutKey() @@ -1299,8 +1299,19 @@ TWorld::Update_Camera( double const Deltatime ) { if( FreeFlyModeFlag ) Camera.RaLook(); // jednorazowe przestawienie kamery } - else if( Console::Pressed( VK_RBUTTON ) ) //||Console::Pressed(VK_F4)) + else if( Console::Pressed( VK_RBUTTON ) ) { //||Console::Pressed(VK_F4)) FollowView( false ); // bez wyciszania dźwięków + } + else if( true == Console::Pressed( VK_MBUTTON ) ) { + // middle mouse button controls zoom. + Global::ZoomFactor = std::min( 4.5f, Global::ZoomFactor + 15.0f * static_cast(Deltatime) ); + } + else if( false == Console::Pressed( VK_MBUTTON ) ) { + // reset zoom level if the button is no longer held down. + // NOTE: yes, this is terrible way to go about it. it'll do for now. + Global::ZoomFactor = std::max( 1.0f, Global::ZoomFactor - 15.0f * static_cast( Deltatime ) ); + } + /* else if( Global::iTextMode == -1 ) { // tu mozna dodac dopisywanie do logu przebiegu lokomotywy WriteLog( "Number of textures used: " + std::to_string( Global::iTextures ) ); @@ -1502,6 +1513,12 @@ bool TWorld::Render() // glColor3b(255, 0, 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( 45.0f / Global::ZoomFactor, (GLdouble)Global::ScreenWidth / (GLdouble)Global::ScreenHeight, 0.1f * Global::ZoomFactor, 2500.0f * Global::ZoomFactor ); + glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); Camera.SetMatrix(); // ustawienie macierzy kamery względem początku scenerii @@ -1794,6 +1811,14 @@ 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 / (GLdouble)Global::ScreenHeight, 0.2f, 2500.0f ); + glMatrixMode( GL_MODELVIEW ); // Select The Modelview Matrix + glLoadIdentity(); + if( DebugModeFlag && !Global::iTextMode ) { OutText1 = " FPS: "; OutText1 += to_string( Timer::GetFPS(), 2 );