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

feature: camera zoom

This commit is contained in:
tmj-fstate
2017-02-19 16:24:10 +01:00
parent 7e0aeb1bfa
commit 8ae135375e
7 changed files with 68 additions and 33 deletions

View File

@@ -3710,7 +3710,7 @@ void TDynamicObject::Render()
// zmienne // zmienne
renderme = false; renderme = false;
// przeklejka // przeklejka
double ObjSqrDist = SquareMagnitude(Global::pCameraPosition - vPosition); double ObjSqrDist = SquareMagnitude(Global::pCameraPosition - vPosition) / Global::ZoomFactor;
// koniec przeklejki // koniec przeklejki
if (ObjSqrDist < 500) // jak jest blisko - do 70m if (ObjSqrDist < 500) // jak jest blisko - do 70m
modelrotate = 0.01; // mały kąt, żeby nie znikało 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 TSubModel::iInstance = (int)this; //żeby nie robić cudzych animacji
// AnsiString asLoadName=""; // 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 ABuLittleUpdate(ObjSqrDist); // ustawianie zmiennych submodeli dla wspólnego modelu
// Cone(vCoulpler[0],modelRot.z,0); // Cone(vCoulpler[0],modelRot.z,0);

View File

@@ -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 GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // resize and initialize the GL Window
{ {
WindowWidth = width; Global::ScreenWidth = WindowWidth = width;
WindowHeight = height; Global::ScreenHeight = WindowHeight = height;
if (height == 0) // prevent a divide by zero by if (height == 0) // prevent a divide by zero by
height = 1; // making height equal one height = 1; // making height equal one
glViewport(0, 0, width, height); // Reset The Current Viewport glViewport(0, 0, width, height); // Reset The Current Viewport
/*
glMatrixMode(GL_PROJECTION); // select the Projection Matrix glMatrixMode(GL_PROJECTION); // select the Projection Matrix
glLoadIdentity(); // reset the Projection Matrix glLoadIdentity(); // reset the Projection Matrix
// calculate the aspect ratio of the window // calculate the aspect ratio of the window
gluPerspective(45.0f, (GLdouble)width / (GLdouble)height, 0.2f, 2500.0f); gluPerspective(45.0f, (GLdouble)width / (GLdouble)height, 0.2f, 2500.0f);
glMatrixMode(GL_MODELVIEW); // select the Modelview Matrix glMatrixMode(GL_MODELVIEW); // select the Modelview Matrix
glLoadIdentity(); // reset the Modelview Matrix glLoadIdentity(); // reset the Modelview Matrix
*/
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -175,14 +175,16 @@ void TGauge::Update()
*/ std::string n( "000000000" + std::to_string( static_cast<int>( std::floor( fValue ) ) ) ); */ std::string n( "000000000" + std::to_string( static_cast<int>( std::floor( fValue ) ) ) );
if( n.length() > 10 ) { n.erase( 0, n.length() - 10 ); } // also dumb but should work for now if( n.length() > 10 ) { n.erase( 0, n.length() - 10 ); } // also dumb but should work for now
do do
{ // pętla po submodelach potomnych i obracanie ich o kąt zależy od { // pętla po submodelach potomnych i obracanie ich o kąt zależy od cyfry w (fValue)
// cyfry w (fValue) if( sm->pName ) {
if (sm->pName) // musi mieć niepustą nazwę
{ // musi mieć niepustą nazwę if( ( sm->pName[ 0 ] >= '0' )
if (sm->pName[0] >= '0') && ( sm->pName[ 0 ] <= '9' ) ) {
if (sm->pName[0] <= '9')
sm->SetRotate(float3(0, 1, 0), sm->SetRotate(
-36.0 * (n['0' + 10 - sm->pName[0]] - '0')); float3( 0, 1, 0 ),
-36.0 * ( n[ '0' + 9 - sm->pName[ 0 ] ] - '0' ) );
}
} }
sm = sm->NextGet(); sm = sm->NextGet();
} while (sm); } while (sm);

View File

@@ -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 double Global::fLuminance = 1.0; // jasność światła do automatycznego zapalania
int Global::iReCompile = 0; // zwiększany, gdy trzeba odświeżyć siatki int Global::iReCompile = 0; // zwiększany, gdy trzeba odświeżyć siatki
HWND Global::hWnd = NULL; // uchwyt okna HWND Global::hWnd = NULL; // uchwyt okna
int Global::ScreenWidth = 1;
int Global::ScreenHeight = 1;
float Global::ZoomFactor = 1.0f;
int Global::iCameraLast = -1; int Global::iCameraLast = -1;
std::string Global::asRelease = "16.0.1172.482"; std::string Global::asRelease = "16.0.1172.482";
std::string Global::asVersion = std::string Global::asVersion =

View File

@@ -253,6 +253,9 @@ class Global
static double fLuminance; // jasność światła do automatycznego zapalania static double fLuminance; // jasność światła do automatycznego zapalania
static int iMultiplayer; // blokada działania niektórych eventów na rzecz kominikacji static int iMultiplayer; // blokada działania niektórych eventów na rzecz kominikacji
static HWND hWnd; // uchwyt okna 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 int iCameraLast;
static std::string asRelease; // numer static std::string asRelease; // numer
static std::string asVersion; // z opisem static std::string asVersion; // z opisem

View File

@@ -555,7 +555,7 @@ void TGroundNode::RenderDL()
return smTerrain->RenderDL(); return smTerrain->RenderDL();
} }
// if (pTriGroup) if (pTriGroup!=this) return; //wyświetla go inny obiekt // 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 if ((mgn > fSquareRadius) || (mgn < fSquareMinRadius)) // McZapkie-070602: nie rysuj odleglych
// obiektow ale sprawdzaj wyzwalacz // obiektow ale sprawdzaj wyzwalacz
// zdarzen // zdarzen
@@ -615,7 +615,7 @@ void TGroundNode::RenderAlphaDL()
// i jezeli tak to odpowiedni GL_GREATER w przeciwnym wypadku standardowy 0.04 // i jezeli tak to odpowiedni GL_GREATER w przeciwnym wypadku standardowy 0.04
// if (pTriGroup) if (pTriGroup!=this) return; //wyświetla go inny obiekt // 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; float r, g, b;
if (mgn < fSquareMinRadius) if (mgn < fSquareMinRadius)
return; return;

View File

@@ -485,21 +485,21 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
glBegin(GL_QUADS); // Drawing using triangles glBegin(GL_QUADS); // Drawing using triangles
glTexCoord2f(0.0f, 0.0f); 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); 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); 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); 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(); glEnd();
//~logo; Ra: to jest bez sensu zapis //~logo; Ra: to jest bez sensu zapis
glColor3f(0.0f, 0.0f, 100.0f); glColor3f(0.0f, 0.0f, 100.0f);
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.09f); glRasterPos2f(-0.85f, -0.25f);
glPrint("Uruchamianie / Initializing..."); glPrint("Uruchamianie / Initializing...");
glRasterPos2f(-0.25f, -0.10f); glRasterPos2f(-0.85f, -0.30f);
glPrint("Dzwiek / Sound..."); glPrint("Dzwiek / Sound...");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -512,7 +512,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Sound Init OK"); WriteLog("Sound Init OK");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.11f); glRasterPos2f(-0.25f, -0.30f);
glPrint("OK."); glPrint("OK.");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -523,7 +523,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Textures init"); WriteLog("Textures init");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.12f); glRasterPos2f(-0.85f, -0.35f);
glPrint("Tekstury / Textures..."); glPrint("Tekstury / Textures...");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -533,7 +533,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Textures init OK"); WriteLog("Textures init OK");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.13f); glRasterPos2f(-0.25f, -0.35f);
glPrint("OK."); glPrint("OK.");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -541,7 +541,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Models init"); WriteLog("Models init");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.14f); glRasterPos2f(-0.85f, -0.40f);
glPrint("Modele / Models..."); glPrint("Modele / Models...");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -551,7 +551,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Models init OK"); WriteLog("Models init OK");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.15f); glRasterPos2f(-0.25f, -0.40f);
glPrint("OK."); glPrint("OK.");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -559,7 +559,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Ground init"); WriteLog("Ground init");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.16f); glRasterPos2f(-0.85f, -0.45f);
glPrint("Sceneria / Scenery (please wait)..."); glPrint("Sceneria / Scenery (please wait)...");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -570,7 +570,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Ground init OK"); WriteLog("Ground init OK");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.17f); glRasterPos2f(-0.25f, -0.45f);
glPrint("OK."); glPrint("OK.");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -587,7 +587,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
char buff[255] = "Player train init: "; char buff[255] = "Player train init: ";
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.18f); glRasterPos2f(-0.85f, -0.50f);
glPrint("Przygotowanie kabiny do sterowania..."); glPrint("Przygotowanie kabiny do sterowania...");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -608,7 +608,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
WriteLog("Player train init OK"); WriteLog("Player train init OK");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.19f); glRasterPos2f(-0.25f, -0.50f);
glPrint("OK."); glPrint("OK.");
} }
FollowView(); FollowView();
@@ -620,7 +620,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.20f); glRasterPos2f(-0.85f, -0.50f);
glPrint("Blad inicjalizacji sterowanego pojazdu!"); glPrint("Blad inicjalizacji sterowanego pojazdu!");
} }
SwapBuffers(hDC); // Swap Buffers (Double Buffering) SwapBuffers(hDC); // Swap Buffers (Double Buffering)
@@ -636,7 +636,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
Error("Player train not exist!"); Error("Player train not exist!");
if (Global::detonatoryOK) if (Global::detonatoryOK)
{ {
glRasterPos2f(-0.25f, -0.20f); glRasterPos2f(-0.85f, -0.55f);
glPrint("Wybrany pojazd nie istnieje w scenerii!"); glPrint("Wybrany pojazd nie istnieje w scenerii!");
} }
} }
@@ -984,7 +984,7 @@ void TWorld::OnKeyUp(int cKey)
void TWorld::OnMouseMove(double x, double y) void TWorld::OnMouseMove(double x, double y)
{ // McZapkie:060503-definicja obracania myszy { // 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() void TWorld::InOutKey()
@@ -1299,8 +1299,19 @@ TWorld::Update_Camera( double const Deltatime ) {
if( FreeFlyModeFlag ) if( FreeFlyModeFlag )
Camera.RaLook(); // jednorazowe przestawienie kamery 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 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<float>(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<float>( Deltatime ) );
}
/* /*
else if( Global::iTextMode == -1 ) { // tu mozna dodac dopisywanie do logu przebiegu lokomotywy else if( Global::iTextMode == -1 ) { // tu mozna dodac dopisywanie do logu przebiegu lokomotywy
WriteLog( "Number of textures used: " + std::to_string( Global::iTextures ) ); WriteLog( "Number of textures used: " + std::to_string( Global::iTextures ) );
@@ -1502,6 +1513,12 @@ bool TWorld::Render()
// 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 ); 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 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
@@ -1794,6 +1811,14 @@ TWorld::Render_Cab() {
void void
TWorld::Render_UI() { 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 ) { if( DebugModeFlag && !Global::iTextMode ) {
OutText1 = " FPS: "; OutText1 = " FPS: ";
OutText1 += to_string( Timer::GetFPS(), 2 ); OutText1 += to_string( Timer::GetFPS(), 2 );