From ec1a625c1298de3da9a4dbaa8a0296859e2b3059 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Fri, 3 Aug 2018 16:07:50 +0200 Subject: [PATCH] minor camera refactoring, division by zero guards --- Driver.cpp | 12 +++++++++--- DynObj.cpp | 7 ++++--- Globals.cpp | 2 -- Globals.h | 17 ++++++++--------- Model3d.h | 7 ++----- Traction.cpp | 15 +++++++++++---- Train.cpp | 20 ++++++++++---------- audiorenderer.cpp | 6 +++--- drivermode.cpp | 32 ++++++++------------------------ driveruilayer.cpp | 18 +++++++++--------- editormode.cpp | 23 ++++++++++------------- editormode.h | 2 +- editoruilayer.cpp | 7 +++---- renderer.cpp | 34 +++++++++++++++++----------------- scene.cpp | 11 ++++++----- sceneeditor.cpp | 2 +- scenenode.h | 2 +- sound.cpp | 3 ++- uilayer.cpp | 4 ++++ uilayer.h | 2 +- 20 files changed, 110 insertions(+), 116 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 2e9baffd..9a6cf96b 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -1926,8 +1926,15 @@ double TController::ESMVelocity(bool Main) for (int i = 0; i < 5; i++) { MS = mvControlling->MomentumF(IF, IF, SCPN); - Fmax = MS * mvControlling->RList[MCPN].Bn*mvControlling->RList[MCPN].Mn * 2 / mvControlling->WheelDiameter * mvControlling->Transmision.Ratio; - IF = 0.5*IF*(1 + FrictionMax/Fmax); + Fmax = MS * mvControlling->RList[MCPN].Bn * mvControlling->RList[MCPN].Mn * 2 / mvControlling->WheelDiameter * mvControlling->Transmision.Ratio; + if( Fmax != 0.0 ) { + IF = 0.5 * IF * ( 1 + FrictionMax / Fmax ); + } + else { + // NOTE: gets trimmed to actual highest acceptable value after the loop + IF = std::numeric_limits::max(); + break; + } } IF = std::min(IF, mvControlling->Imax*fCurrentCoeff); double R = mvControlling->RList[MCPN].R + mvControlling->CircuitRes + mvControlling->RList[MCPN].Mn*mvControlling->WindingRes; @@ -1938,7 +1945,6 @@ double TController::ESMVelocity(bool Main) ESMVel = ns * mvControlling->WheelDiameter*M_PI*3.6/mvControlling->Transmision.Ratio; return ESMVel; } -; int TController::CheckDirection() { diff --git a/DynObj.cpp b/DynObj.cpp index f6b98ae2..654f881a 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/. #include "DynObj.h" #include "simulation.h" +#include "camera.h" #include "train.h" #include "driver.h" #include "Globals.h" @@ -1061,19 +1062,19 @@ TDynamicObject * TDynamicObject::ABuFindNearestObject(TTrack *Track, TDynamicObj if( CouplNr == -2 ) { // wektor [kamera-obiekt] - poszukiwanie obiektu - if( Math3D::LengthSquared3( Global.pCameraPosition - dynamic->vPosition ) < 100.0 ) { + if( Math3D::LengthSquared3( Global.pCamera.Pos - dynamic->vPosition ) < 100.0 ) { // 10 metrów return dynamic; } } else { // jeśli (CouplNr) inne niz -2, szukamy sprzęgu - if( Math3D::LengthSquared3( Global.pCameraPosition - dynamic->vCoulpler[ 0 ] ) < 25.0 ) { + if( Math3D::LengthSquared3( Global.pCamera.Pos - dynamic->vCoulpler[ 0 ] ) < 25.0 ) { // 5 metrów CouplNr = 0; return dynamic; } - if( Math3D::LengthSquared3( Global.pCameraPosition - dynamic->vCoulpler[ 1 ] ) < 25.0 ) { + if( Math3D::LengthSquared3( Global.pCamera.Pos - dynamic->vCoulpler[ 1 ] ) < 25.0 ) { // 5 metrów CouplNr = 1; return dynamic; diff --git a/Globals.cpp b/Globals.cpp index 10b63e7b..e55c7dc0 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -26,8 +26,6 @@ global_settings Global; void global_settings::LoadIniFile(std::string asFileName) { - FreeCameraInit.resize( 10 ); - FreeCameraInitAngle.resize( 10 ); cParser parser(asFileName, cParser::buffer_FILE); ConfigParse(parser); }; diff --git a/Globals.h b/Globals.h index f542aac1..c6c39279 100644 --- a/Globals.h +++ b/Globals.h @@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/. #pragma once #include "classes.h" +#include "camera.h" #include "dumb3d.h" #include "float3d.h" #include "light.h" @@ -25,12 +26,10 @@ struct global_settings { bool altState{ false }; std::mt19937 random_engine{ std::mt19937( static_cast( std::time( NULL ) ) ) }; TDynamicObject *changeDynObj{ nullptr };// info o zmianie pojazdu - TCamera *pCamera{ nullptr }; // parametry kamery - TCamera *pDebugCamera{ nullptr }; - Math3D::vector3 pCameraPosition; // pozycja kamery w świecie - Math3D::vector3 DebugCameraPosition; // pozycja kamery w świecie - std::vector FreeCameraInit; // pozycje kamery - std::vector FreeCameraInitAngle; + TCamera pCamera; // parametry kamery + TCamera pDebugCamera; + std::array FreeCameraInit; // pozycje kamery + std::array FreeCameraInitAngle; int iCameraLast{ -1 }; int iSlowMotion{ 0 }; // info o malym FPS: 0-OK, 1-wyłączyć multisampling, 3-promień 1.5km, 7-1km basic_light DayLight; @@ -46,15 +45,15 @@ struct global_settings { bool bActive{ true }; // czy jest aktywnym oknem int iPause{ 0 }; // globalna pauza ruchu: b0=start,b1=klawisz,b2=tło,b3=lagi,b4=wczytywanie float AirTemperature{ 15.f }; + std::string asCurrentSceneryPath{ "scenery/" }; + std::string asCurrentTexturePath{ szTexturePath }; + std::string asCurrentDynamicPath; // settings // filesystem bool bLoadTraction{ true }; std::string szTexturesTGA{ ".tga" }; // lista tekstur od TGA std::string szTexturesDDS{ ".dds" }; // lista tekstur od DDS std::string szDefaultExt{ szTexturesDDS }; - std::string asCurrentSceneryPath{ "scenery/" }; - std::string asCurrentTexturePath{ szTexturePath }; - std::string asCurrentDynamicPath; std::string SceneryFile{ "td.scn" }; std::string asHumanCtrlVehicle{ "EU07-424" }; int iConvertModels{ 0 }; // tworzenie plików binarnych diff --git a/Model3d.h b/Model3d.h index 6ae4b2f3..157bb992 100644 --- a/Model3d.h +++ b/Model3d.h @@ -179,11 +179,8 @@ public: void create_geometry( std::size_t &Dataoffset, gfx::geometrybank_handle const &Bank ); int FlagsCheck(); - void WillBeAnimated() - { - if (this) - iFlags |= 0x4000; - }; + void WillBeAnimated() { + iFlags |= 0x4000; }; void InitialRotate(bool doit); void BinInit(TSubModel *s, float4x4 *m, std::vector *t, std::vector *n, bool dynamic); static void ReplacableSet(material_handle const *r, int a) { diff --git a/Traction.cpp b/Traction.cpp index 71ec2aee..28ff95a7 100644 --- a/Traction.cpp +++ b/Traction.cpp @@ -477,10 +477,17 @@ double TTraction::VoltageGet(double u, double i) // 1. zasilacz psPower[0] z rezystancją fResistance[0] oraz jego wewnętrzną // 2. zasilacz psPower[1] z rezystancją fResistance[1] oraz jego wewnętrzną // 3. zasilacz psPowered z jego wewnętrzną rezystancją dla przęseł zasilanych bezpośrednio - double res = (i != 0.0) ? (u / i) : 10000.0; - if (psPowered) - return psPowered->CurrentGet(res) * - res; // yB: dla zasilanego nie baw się w gwiazdy, tylko bierz bezpośrednio + double res = ( + (i != 0.0) ? + (u / i) : + 10000.0 ); + if( psPowered != nullptr ) { + // yB: dla zasilanego nie baw się w gwiazdy, tylko bierz bezpośrednio + return ( + ( res != 0.0 ) ? + psPowered->CurrentGet( res ) * res : + 0.0 ); + } double r0t, r1t, r0g, r1g; double i0, i1; r0t = fResistance[0]; //średni pomysł, ale lepsze niż nic diff --git a/Train.cpp b/Train.cpp index 69ffef85..386ebefa 100644 --- a/Train.cpp +++ b/Train.cpp @@ -3360,14 +3360,14 @@ void TTrain::OnCommand_redmarkerstoggle( TTrain *Train, command_data const &Comm if( ( true == FreeFlyModeFlag ) && ( Command.action == GLFW_PRESS ) ) { - auto *vehicle { std::get( simulation::Region->find_vehicle( Global.pCameraPosition, 10, false, true ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) }; if( vehicle == nullptr ) { return; } int const CouplNr { clamp( vehicle->DirectionGet() - * ( LengthSquared3( vehicle->HeadPosition() - Global.pCameraPosition ) > LengthSquared3( vehicle->RearPosition() - Global.pCameraPosition ) ? + * ( LengthSquared3( vehicle->HeadPosition() - Global.pCamera.Pos ) > LengthSquared3( vehicle->RearPosition() - Global.pCamera.Pos ) ? 1 : -1 ), 0, 1 ) }; // z [-1,1] zrobić [0,1] @@ -3386,14 +3386,14 @@ void TTrain::OnCommand_endsignalstoggle( TTrain *Train, command_data const &Comm if( ( true == FreeFlyModeFlag ) && ( Command.action == GLFW_PRESS ) ) { - auto *vehicle { std::get( simulation::Region->find_vehicle( Global.pCameraPosition, 10, false, true ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) }; if( vehicle == nullptr ) { return; } int const CouplNr { clamp( vehicle->DirectionGet() - * ( LengthSquared3( vehicle->HeadPosition() - Global.pCameraPosition ) > LengthSquared3( vehicle->RearPosition() - Global.pCameraPosition ) ? + * ( LengthSquared3( vehicle->HeadPosition() - Global.pCamera.Pos ) > LengthSquared3( vehicle->RearPosition() - Global.pCamera.Pos ) ? 1 : -1 ), 0, 1 ) }; // z [-1,1] zrobić [0,1] @@ -4327,13 +4327,13 @@ bool TTrain::Update( double const Deltatime ) // update driver's position { - auto Vec = Global.pCamera->Velocity * -2.0;// -7.5 * Timer::GetDeltaRenderTime(); + auto Vec = Global.pCamera.Velocity * -2.0;// -7.5 * Timer::GetDeltaRenderTime(); Vec.y = -Vec.y; if( mvOccupied->ActiveCab < 0 ) { Vec *= -1.0f; Vec.y = -Vec.y; } - Vec.RotateY( Global.pCamera->Yaw ); + Vec.RotateY( Global.pCamera.Yaw ); vMechMovement = Vec; } @@ -5949,8 +5949,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) } // reset view angles pMechViewAngle = { 0.0, 0.0 }; - Global.pCamera->Pitch = pMechViewAngle.x; - Global.pCamera->Yaw = pMechViewAngle.y; + Global.pCamera.Pitch = pMechViewAngle.x; + Global.pCamera.Yaw = pMechViewAngle.y; pyScreens.reset(this); pyScreens.setLookupPath(DynamicObject->asBaseDir); @@ -6016,8 +6016,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) >> viewangle.y // yaw first, then pitch >> viewangle.x; pMechViewAngle = glm::radians( viewangle ); - Global.pCamera->Pitch = pMechViewAngle.x; - Global.pCamera->Yaw = pMechViewAngle.y; + Global.pCamera.Pitch = pMechViewAngle.x; + Global.pCamera.Yaw = pMechViewAngle.y; parser->getTokens(); *parser >> token; diff --git a/audiorenderer.cpp b/audiorenderer.cpp index 03184ee2..b29057a9 100644 --- a/audiorenderer.cpp +++ b/audiorenderer.cpp @@ -117,7 +117,7 @@ openal_source::sync_with( sound_properties const &State ) { ::alSourcefv( id, AL_VELOCITY, glm::value_ptr( sound_velocity ) ); // location properties.location = State.location; - sound_distance = properties.location - glm::dvec3 { Global.pCameraPosition }; + sound_distance = properties.location - glm::dvec3 { Global.pCamera.Pos }; if( sound_range > 0 ) { // range cutoff check auto const cutoffrange = ( @@ -312,7 +312,7 @@ openal_renderer::update( double const Deltatime ) { // update listener // orientation glm::dmat4 cameramatrix; - Global.pCamera->SetMatrix( cameramatrix ); + Global.pCamera.SetMatrix( cameramatrix ); auto rotationmatrix { glm::mat3{ cameramatrix } }; glm::vec3 const orientation[] = { glm::vec3{ 0, 0,-1 } * rotationmatrix , @@ -320,7 +320,7 @@ openal_renderer::update( double const Deltatime ) { ::alListenerfv( AL_ORIENTATION, reinterpret_cast( orientation ) ); // velocity if( Deltatime > 0 ) { - glm::dvec3 const listenerposition { Global.pCameraPosition }; + glm::dvec3 const listenerposition { Global.pCamera.Pos }; glm::dvec3 const listenermovement { listenerposition - m_listenerposition }; m_listenerposition = listenerposition; m_listenervelocity = ( diff --git a/drivermode.cpp b/drivermode.cpp index 72283022..3198e308 100644 --- a/drivermode.cpp +++ b/drivermode.cpp @@ -241,8 +241,8 @@ void driver_mode::enter() { Camera.Init(Global.FreeCameraInit[0], Global.FreeCameraInitAngle[0], ( FreeFlyModeFlag ? TCameraType::tp_Free : TCameraType::tp_Follow ) ); - Global.pCamera = &Camera; - Global.pDebugCamera = &DebugCamera; + Global.pCamera = Camera; + Global.pDebugCamera = DebugCamera; TDynamicObject *nPlayerTrain { ( ( Global.asHumanCtrlVehicle != "ghostview" ) ? @@ -281,7 +281,6 @@ driver_mode::enter() { FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie Camera.Type = TCameraType::tp_Free; DebugCamera = Camera; - Global.DebugCameraPosition = DebugCamera.Pos; } // if (!Global.bMultiplayer) //na razie włączone @@ -345,17 +344,7 @@ driver_mode::on_key( int const Key, int const Scancode, int const Action, int co } } - if( ( Key == GLFW_KEY_LEFT_SHIFT ) - || ( Key == GLFW_KEY_LEFT_CONTROL ) - || ( Key == GLFW_KEY_LEFT_ALT ) - || ( Key == GLFW_KEY_RIGHT_SHIFT ) - || ( Key == GLFW_KEY_RIGHT_CONTROL ) - || ( Key == GLFW_KEY_RIGHT_ALT ) ) { - // don't bother passing these - return; - } - - if( Action == GLFW_PRESS || Action == GLFW_REPEAT ) { + if( Action == GLFW_PRESS ) { OnKeyDown( Key ); @@ -414,9 +403,9 @@ driver_mode::update_camera( double const Deltatime ) { Camera.LookAt = controlled->GetPosition(); } else { - TDynamicObject *d = std::get( simulation::Region->find_vehicle( Global.pCameraPosition, 300, false, false ) ); + TDynamicObject *d = std::get( simulation::Region->find_vehicle( Global.pCamera.Pos, 300, false, false ) ); if( !d ) - d = std::get( simulation::Region->find_vehicle( Global.pCameraPosition, 1000, false, false ) ); // dalej szukanie, jesli bliżej nie ma + d = std::get( simulation::Region->find_vehicle( Global.pCamera.Pos, 1000, false, false ) ); // dalej szukanie, jesli bliżej nie ma if( d && pDynamicNearest ) { // jeśli jakiś jest znaleziony wcześniej @@ -530,8 +519,7 @@ driver_mode::update_camera( double const Deltatime ) { } } // all done, update camera position to the new value - Global.pCameraPosition = Camera.Pos; - Global.DebugCameraPosition = DebugCamera.Pos; + Global.pCamera = Camera; } void @@ -615,7 +603,7 @@ driver_mode::OnKeyDown(int cKey) { } else // również przeskakiwanie { // Ra: to z tą kamerą (Camera.Pos i Global.pCameraPosition) jest trochę bez sensu - Global.pCameraPosition = Global.FreeCameraInit[ i ]; // nowa pozycja dla generowania obiektów + Global.pCamera.Pos = Global.FreeCameraInit[ i ]; // nowa pozycja dla generowania obiektów Camera.Init( Global.FreeCameraInit[ i ], Global.FreeCameraInitAngle[ i ], TCameraType::tp_Free ); // przestawienie } } @@ -653,7 +641,7 @@ driver_mode::OnKeyDown(int cKey) { break; } - TDynamicObject *tmp = std::get( simulation::Region->find_vehicle( Global.pCameraPosition, 50, true, false ) ); + TDynamicObject *tmp = std::get( simulation::Region->find_vehicle( Global.pCamera.Pos, 50, true, false ) ); if( tmp != nullptr ) { @@ -879,9 +867,6 @@ driver_mode::FollowView(bool wycisz) { train->Dynamic()->ABuSetModelShake( {} ); DistantView(); // przestawienie kamery - //żeby nie bylo numerów z 'fruwajacym' lokiem - konsekwencja bujania pudła - // tu ustawić nową, bo od niej liczą się odległości - Global.pCameraPosition = Camera.Pos; } else { Camera.Pos = train->pMechPosition; @@ -987,7 +972,6 @@ driver_mode::InOutKey( bool const Near ) DistantView( Near ); } DebugCamera = Camera; - Global.DebugCameraPosition = DebugCamera.Pos; } else { // jazda w kabinie diff --git a/driveruilayer.cpp b/driveruilayer.cpp index e103ac42..08fb23b0 100644 --- a/driveruilayer.cpp +++ b/driveruilayer.cpp @@ -193,7 +193,7 @@ driver_ui::update() { auto const *train { simulation::Train }; auto const *controlled { ( train ? train->Dynamic() : nullptr ) }; - auto const *camera { Global.pCamera }; + auto const &camera { Global.pCamera }; if( ( train != nullptr ) && ( false == FreeFlyModeFlag ) ) { if( false == DebugModeFlag ) { @@ -292,7 +292,7 @@ driver_ui::update() { // timetable auto *vehicle { ( FreeFlyModeFlag ? - std::get( simulation::Region->find_vehicle( camera->Pos, 20, false, false ) ) : + std::get( simulation::Region->find_vehicle( camera.Pos, 20, false, false ) ) : controlled ) }; // w trybie latania lokalizujemy wg mapy if( vehicle == nullptr ) { break; } @@ -398,7 +398,7 @@ driver_ui::update() { auto const *vehicle { ( FreeFlyModeFlag ? - std::get( simulation::Region->find_vehicle( camera->Pos, 20, false, false ) ) : + std::get( simulation::Region->find_vehicle( camera.Pos, 20, false, false ) ) : controlled ) }; // w trybie latania lokalizujemy wg mapy if( vehicle != nullptr ) { @@ -579,14 +579,14 @@ driver_ui::update() { // wyświetlenie współrzędnych w scenerii oraz kąta kamery, gdy nie mamy wskaźnika uitextline1 = "Camera position: " - + to_string( camera->Pos.x, 2 ) + " " - + to_string( camera->Pos.y, 2 ) + " " - + to_string( camera->Pos.z, 2 ) + + to_string( camera.Pos.x, 2 ) + " " + + to_string( camera.Pos.y, 2 ) + " " + + to_string( camera.Pos.z, 2 ) + ", azimuth: " - + to_string( 180.0 - glm::degrees( camera->Yaw ), 0 ) // ma być azymut, czyli 0 na północy i rośnie na wschód + + to_string( 180.0 - glm::degrees( camera.Yaw ), 0 ) // ma być azymut, czyli 0 na północy i rośnie na wschód + " " + std::string( "S SEE NEN NWW SW" ) - .substr( 0 + 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 uitextline2 = "Light level: " + to_string( Global.fLuminance, 3 ); if( Global.FakeLight ) { uitextline2 += "(*)"; } @@ -683,7 +683,7 @@ driver_ui::update() { auto const *vehicle { ( FreeFlyModeFlag ? - std::get( simulation::Region->find_vehicle( camera->Pos, 20, false, false ) ) : + std::get( simulation::Region->find_vehicle( camera.Pos, 20, false, false ) ) : controlled ) }; // w trybie latania lokalizujemy wg mapy if( vehicle == nullptr ) { break; diff --git a/editormode.cpp b/editormode.cpp index 235dba27..19726fd8 100644 --- a/editormode.cpp +++ b/editormode.cpp @@ -43,7 +43,10 @@ editor_mode::editor_mode() { bool editor_mode::init() { - Camera.Init( {}, {}, TCameraType::tp_Free ); + Camera.Init( { 0, 15, 0 }, { glm::radians( -30.0 ), glm::radians( 180.0 ), 0 }, TCameraType::tp_Free ); + + m_userinterface->set_progress( "Scenario editor is active. Press F11 to return to driver mode" ); + m_userinterface->set_progress( 0, 100 ); return m_input.init(); } @@ -97,7 +100,7 @@ editor_mode::update_camera( double const Deltatime ) { // reset window state, it'll be set again if applicable in a check below Global.CabWindowOpen = false; // all done, update camera position to the new value - Global.pCameraPosition = Camera.Pos; + Global.pCamera = Camera; } // maintenance method, called when the mode is activated @@ -106,7 +109,7 @@ editor_mode::enter() { m_statebackup = { Global.pCamera, FreeFlyModeFlag, Global.ControlPicking }; - Global.pCamera = &Camera; + Global.pCamera = Camera; FreeFlyModeFlag = true; Global.ControlPicking = true; EditorModeFlag = true; @@ -127,6 +130,10 @@ editor_mode::exit() { ( Global.ControlPicking ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED ) ); + + if( false == Global.ControlPicking ) { + Application.set_cursor_pos( 0, 0 ); + } } void @@ -143,16 +150,6 @@ editor_mode::on_key( int const Key, int const Scancode, int const Action, int co if( Action == GLFW_RELEASE ) { return; } - if( ( Key == GLFW_KEY_LEFT_SHIFT ) - || ( Key == GLFW_KEY_LEFT_CONTROL ) - || ( Key == GLFW_KEY_LEFT_ALT ) - || ( Key == GLFW_KEY_RIGHT_SHIFT ) - || ( Key == GLFW_KEY_RIGHT_CONTROL ) - || ( Key == GLFW_KEY_RIGHT_ALT ) ) { - // don't bother passing these - return; - } - // legacy hardcoded keyboard commands // TODO: replace with current command system, move to input object(s) switch( Key ) { diff --git a/editormode.h b/editormode.h index 012752ff..99565f94 100644 --- a/editormode.h +++ b/editormode.h @@ -57,7 +57,7 @@ private: struct state_backup { - TCamera *camera; + TCamera camera; bool freefly; bool picking; }; diff --git a/editoruilayer.cpp b/editoruilayer.cpp index be96c79b..5b6df31f 100644 --- a/editoruilayer.cpp +++ b/editoruilayer.cpp @@ -48,7 +48,7 @@ editor_ui::update() { std::string uitextline1, uitextline2, uitextline3, uitextline4; set_tooltip( "" ); - auto const *camera { Global.pCamera }; + auto const &camera { Global.pCamera }; if( ( true == Global.ControlPicking ) && ( true == DebugModeFlag ) ) { @@ -60,12 +60,11 @@ editor_ui::update() { "" ) ); } - // scenario inspector auto const *node { m_node }; if( node == nullptr ) { - auto const mouseposition { Global.pCamera->Pos + GfxRenderer.Mouse_Position() }; + auto const mouseposition { camera.Pos + GfxRenderer.Mouse_Position() }; uitextline1 = "mouse location: [" + to_string( mouseposition.x, 2 ) + ", " + to_string( mouseposition.y, 2 ) + ", " + to_string( mouseposition.z, 2 ) + "]"; goto update; } @@ -73,7 +72,7 @@ editor_ui::update() { uitextline1 = "node name: " + node->name() + "; location: [" + to_string( node->location().x, 2 ) + ", " + to_string( node->location().y, 2 ) + ", " + to_string( node->location().z, 2 ) + "]" - + " (distance: " + to_string( glm::length( glm::dvec3{ node->location().x, 0.0, node->location().z } -glm::dvec3{ Global.pCameraPosition.x, 0.0, Global.pCameraPosition.z } ), 1 ) + " m)"; + + " (distance: " + to_string( glm::length( glm::dvec3{ node->location().x, 0.0, node->location().z } -glm::dvec3{ camera.Pos.x, 0.0, camera.Pos.z } ), 1 ) + " m)"; // subclass-specific data // TBD, TODO: specialized data dump method in each node subclass, or data imports in the panel for provided subclass pointer? if( typeid( *node ) == typeid( TAnimModel ) ) { diff --git a/renderer.cpp b/renderer.cpp index e39db423..eeab2f70 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -810,12 +810,12 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f case rendermode::color: { // modelview if( ( false == DebugCameraFlag ) || ( true == Ignoredebug ) ) { - camera.position() = Global.pCameraPosition; - Global.pCamera->SetMatrix( viewmatrix ); + camera.position() = Global.pCamera.Pos; + Global.pCamera.SetMatrix( viewmatrix ); } else { - camera.position() = Global.DebugCameraPosition; - Global.pDebugCamera->SetMatrix( viewmatrix ); + camera.position() = Global.pDebugCamera.Pos; + Global.pDebugCamera.SetMatrix( viewmatrix ); } // projection auto const zfar = Config.draw_range * Global.fDistanceFactor * Zfar; @@ -921,10 +921,10 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f m_sunlight.direction.x, std::min( m_sunlight.direction.y, -0.2f ), m_sunlight.direction.z } ); - camera.position() = Global.pCameraPosition - glm::dvec3 { lightvector }; + camera.position() = Global.pCamera.Pos - glm::dvec3 { lightvector }; viewmatrix *= glm::lookAt( camera.position(), - glm::dvec3 { Global.pCameraPosition }, + glm::dvec3 { Global.pCamera.Pos }, glm::dvec3 { 0.f, 1.f, 0.f } ); // projection auto const maphalfsize { Config.draw_range * 0.5f }; @@ -947,8 +947,8 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f // modelview camera.position() = ( ( ( true == DebugCameraFlag ) && ( false == Ignoredebug ) ) ? - Global.DebugCameraPosition : - Global.pCameraPosition ); + Global.pDebugCamera.Pos : + Global.pCamera.Pos ); glm::dvec3 const cubefacetargetvectors[ 6 ] = { { 1.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 0.0, 0.0, -1.0 } }; glm::dvec3 const cubefaceupvectors[ 6 ] = { { 0.0, -1.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 0.0, 0.0, -1.0 }, { 0.0, -1.0, 0.0 }, { 0.0, -1.0, 0.0 } }; auto const cubefaceindex = m_environmentcubetextureface - GL_TEXTURE_CUBE_MAP_POSITIVE_X; @@ -971,8 +971,8 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f case rendermode::pickscenery: { // TODO: scissor test for pick modes // modelview - camera.position() = Global.pCameraPosition; - Global.pCamera->SetMatrix( viewmatrix ); + camera.position() = Global.pCamera.Pos; + Global.pCamera.SetMatrix( viewmatrix ); // projection camera.projection() *= glm::perspective( @@ -1997,7 +1997,7 @@ opengl_renderer::Render( scene::shape_node const &Shape, bool const Ignorerange switch( m_renderpass.draw_mode ) { case rendermode::shadows: { // 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees - distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor; + distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor; break; } default: { @@ -2051,7 +2051,7 @@ opengl_renderer::Render( TAnimModel *Instance ) { switch( m_renderpass.draw_mode ) { case rendermode::shadows: { // 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees - distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor; + distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor; break; } default: { @@ -2105,7 +2105,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) { float squaredistance; switch( m_renderpass.draw_mode ) { case rendermode::shadows: { - squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCameraPosition } } / Global.ZoomFactor ) / Global.fDistanceFactor; + squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCamera.Pos } } / Global.ZoomFactor ) / Global.fDistanceFactor; break; } default: { @@ -2901,7 +2901,7 @@ opengl_renderer::Render_Alpha( TAnimModel *Instance ) { switch( m_renderpass.draw_mode ) { case rendermode::shadows: { // 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees - distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor; + distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor; break; } default: { @@ -2933,7 +2933,7 @@ opengl_renderer::Render_Alpha( TTraction *Traction ) { switch( m_renderpass.draw_mode ) { case rendermode::shadows: { // 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees - distancesquared = Math3D::SquareMagnitude( ( Traction->location() - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor; + distancesquared = Math3D::SquareMagnitude( ( Traction->location() - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor; break; } default: { @@ -2994,7 +2994,7 @@ opengl_renderer::Render_Alpha( scene::lines_node const &Lines ) { switch( m_renderpass.draw_mode ) { case rendermode::shadows: { // 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees - distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor; + distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor; break; } default: { @@ -3042,7 +3042,7 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) { float squaredistance; switch( m_renderpass.draw_mode ) { case rendermode::shadows: { - squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCameraPosition } } / Global.ZoomFactor ) / Global.fDistanceFactor; + squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCamera.Pos } } / Global.ZoomFactor ) / Global.fDistanceFactor; break; } default: { diff --git a/scene.cpp b/scene.cpp index f12054b8..738dbb1c 100644 --- a/scene.cpp +++ b/scene.cpp @@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/. #include "simulation.h" #include "globals.h" +#include "camera.h" #include "animmodel.h" #include "event.h" #include "evlaunch.h" @@ -122,7 +123,7 @@ basic_cell::update_events() { // event launchers for( auto *launcher : m_eventlaunchers ) { if( ( true == ( launcher->check_activation() && launcher->check_conditions() ) ) - && ( SquareMagnitude( launcher->location() - Global.pCameraPosition ) < launcher->dRadius ) ) { + && ( SquareMagnitude( launcher->location() - Global.pCamera.Pos ) < launcher->dRadius ) ) { launch_event( launcher ); } @@ -948,9 +949,9 @@ void basic_region::update_events() { // render events and sounds from sectors near enough to the viewer auto const range = EU07_SECTIONSIZE; // arbitrary range - auto const §ionlist = sections( Global.pCameraPosition, range ); + auto const §ionlist = sections( Global.pCamera.Pos, range ); for( auto *section : sectionlist ) { - section->update_events( Global.pCameraPosition, range ); + section->update_events( Global.pCamera.Pos, range ); } } @@ -959,9 +960,9 @@ void basic_region::update_sounds() { // render events and sounds from sectors near enough to the viewer auto const range = 2750.f; // audible range of 100 db sound - auto const §ionlist = sections( Global.pCameraPosition, range ); + auto const §ionlist = sections( Global.pCamera.Pos, range ); for( auto *section : sectionlist ) { - section->update_sounds( Global.pCameraPosition, range ); + section->update_sounds( Global.pCamera.Pos, range ); } } diff --git a/sceneeditor.cpp b/sceneeditor.cpp index c79d4bb0..78b87a6b 100644 --- a/sceneeditor.cpp +++ b/sceneeditor.cpp @@ -43,7 +43,7 @@ basic_editor::translate( scene::basic_node *Node, float const Offset ) { // NOTE: offset scaling is calculated early so the same multiplier can be applied to potential whole group auto location { Node->location() }; - auto const distance { glm::length( location - glm::dvec3{ Global.pCamera->Pos } ) }; + auto const distance { glm::length( location - glm::dvec3{ Global.pCamera.Pos } ) }; auto const offset { Offset * std::max( 1.0, distance * 0.01 ) }; auto *node { Node }; // placeholder for operations on multiple nodes diff --git a/scenenode.h b/scenenode.h index 915c60c7..feb14a5b 100644 --- a/scenenode.h +++ b/scenenode.h @@ -299,7 +299,7 @@ private: // base interface for nodes which can be actvated in scenario editor -struct basic_node { +class basic_node { public: // constructor diff --git a/sound.cpp b/sound.cpp index 10a95dbb..416cfdb9 100644 --- a/sound.cpp +++ b/sound.cpp @@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/. #include "sound.h" #include "parser.h" #include "globals.h" +#include "camera.h" #include "train.h" #include "dynobj.h" #include "simulation.h" @@ -357,7 +358,7 @@ sound_source::play( int const Flags ) { if( m_range > 0 ) { auto const cutoffrange { m_range * 5 }; - if( glm::length2( location() - glm::dvec3 { Global.pCameraPosition } ) > std::min( 2750.f * 2750.f, cutoffrange * cutoffrange ) ) { + if( glm::length2( location() - glm::dvec3 { Global.pCamera.Pos } ) > std::min( 2750.f * 2750.f, cutoffrange * cutoffrange ) ) { // while we drop sounds from beyond sensible and/or audible range // we act as if it was activated normally, meaning no need to include the opening bookend in subsequent calls m_playbeginning = false; diff --git a/uilayer.cpp b/uilayer.cpp index cefc1988..cf8f6925 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -149,10 +149,14 @@ ui_layer::set_background( std::string const &Filename ) { else { m_background = null_handle; } + if( m_background != null_handle ) { auto const &texture = GfxRenderer.Texture( m_background ); m_progressbottom = ( texture.width() != texture.height() ); } + else { + m_progressbottom = true; + } } void diff --git a/uilayer.h b/uilayer.h index 1cb72ec3..d95dba3f 100644 --- a/uilayer.h +++ b/uilayer.h @@ -116,7 +116,7 @@ private: float m_progress { 0.0f }; // percentage of filled progres bar, to indicate lengthy operations. float m_subtaskprogress{ 0.0f }; // percentage of filled progres bar, to indicate lengthy operations. std::string m_progresstext; // label placed over the progress bar - bool m_progressbottom { false }; // location of the progress bar + bool m_progressbottom { true }; // location of the progress bar texture_handle m_background { null_handle }; // path to texture used as the background. size depends on mAspect. GLuint m_texture { 0 };