16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-23 15:39:19 +02:00

minor camera refactoring, division by zero guards

This commit is contained in:
tmj-fstate
2018-08-03 16:07:50 +02:00
parent ff6bed67a9
commit ec1a625c12
20 changed files with 110 additions and 116 deletions

View File

@@ -1926,8 +1926,15 @@ double TController::ESMVelocity(bool Main)
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
MS = mvControlling->MomentumF(IF, IF, SCPN); MS = mvControlling->MomentumF(IF, IF, SCPN);
Fmax = MS * mvControlling->RList[MCPN].Bn*mvControlling->RList[MCPN].Mn * 2 / mvControlling->WheelDiameter * mvControlling->Transmision.Ratio; Fmax = MS * mvControlling->RList[MCPN].Bn * mvControlling->RList[MCPN].Mn * 2 / mvControlling->WheelDiameter * mvControlling->Transmision.Ratio;
IF = 0.5*IF*(1 + FrictionMax/Fmax); 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<double>::max();
break;
}
} }
IF = std::min(IF, mvControlling->Imax*fCurrentCoeff); IF = std::min(IF, mvControlling->Imax*fCurrentCoeff);
double R = mvControlling->RList[MCPN].R + mvControlling->CircuitRes + mvControlling->RList[MCPN].Mn*mvControlling->WindingRes; 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; ESMVel = ns * mvControlling->WheelDiameter*M_PI*3.6/mvControlling->Transmision.Ratio;
return ESMVel; return ESMVel;
} }
;
int TController::CheckDirection() { int TController::CheckDirection() {

View File

@@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/.
#include "DynObj.h" #include "DynObj.h"
#include "simulation.h" #include "simulation.h"
#include "camera.h"
#include "train.h" #include "train.h"
#include "driver.h" #include "driver.h"
#include "Globals.h" #include "Globals.h"
@@ -1061,19 +1062,19 @@ TDynamicObject * TDynamicObject::ABuFindNearestObject(TTrack *Track, TDynamicObj
if( CouplNr == -2 ) { if( CouplNr == -2 ) {
// wektor [kamera-obiekt] - poszukiwanie obiektu // 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 // 10 metrów
return dynamic; return dynamic;
} }
} }
else { else {
// jeśli (CouplNr) inne niz -2, szukamy sprzęgu // 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 // 5 metrów
CouplNr = 0; CouplNr = 0;
return dynamic; 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 // 5 metrów
CouplNr = 1; CouplNr = 1;
return dynamic; return dynamic;

View File

@@ -26,8 +26,6 @@ global_settings Global;
void void
global_settings::LoadIniFile(std::string asFileName) { global_settings::LoadIniFile(std::string asFileName) {
FreeCameraInit.resize( 10 );
FreeCameraInitAngle.resize( 10 );
cParser parser(asFileName, cParser::buffer_FILE); cParser parser(asFileName, cParser::buffer_FILE);
ConfigParse(parser); ConfigParse(parser);
}; };

View File

@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once #pragma once
#include "classes.h" #include "classes.h"
#include "camera.h"
#include "dumb3d.h" #include "dumb3d.h"
#include "float3d.h" #include "float3d.h"
#include "light.h" #include "light.h"
@@ -25,12 +26,10 @@ struct global_settings {
bool altState{ false }; bool altState{ false };
std::mt19937 random_engine{ std::mt19937( static_cast<unsigned int>( std::time( NULL ) ) ) }; std::mt19937 random_engine{ std::mt19937( static_cast<unsigned int>( std::time( NULL ) ) ) };
TDynamicObject *changeDynObj{ nullptr };// info o zmianie pojazdu TDynamicObject *changeDynObj{ nullptr };// info o zmianie pojazdu
TCamera *pCamera{ nullptr }; // parametry kamery TCamera pCamera; // parametry kamery
TCamera *pDebugCamera{ nullptr }; TCamera pDebugCamera;
Math3D::vector3 pCameraPosition; // pozycja kamery w świecie std::array<Math3D::vector3, 10> FreeCameraInit; // pozycje kamery
Math3D::vector3 DebugCameraPosition; // pozycja kamery w świecie std::array<Math3D::vector3, 10> FreeCameraInitAngle;
std::vector<Math3D::vector3> FreeCameraInit; // pozycje kamery
std::vector<Math3D::vector3> FreeCameraInitAngle;
int iCameraLast{ -1 }; int iCameraLast{ -1 };
int iSlowMotion{ 0 }; // info o malym FPS: 0-OK, 1-wyłączyć multisampling, 3-promień 1.5km, 7-1km int iSlowMotion{ 0 }; // info o malym FPS: 0-OK, 1-wyłączyć multisampling, 3-promień 1.5km, 7-1km
basic_light DayLight; basic_light DayLight;
@@ -46,15 +45,15 @@ struct global_settings {
bool bActive{ true }; // czy jest aktywnym oknem bool bActive{ true }; // czy jest aktywnym oknem
int iPause{ 0 }; // globalna pauza ruchu: b0=start,b1=klawisz,b2=tło,b3=lagi,b4=wczytywanie int iPause{ 0 }; // globalna pauza ruchu: b0=start,b1=klawisz,b2=tło,b3=lagi,b4=wczytywanie
float AirTemperature{ 15.f }; float AirTemperature{ 15.f };
std::string asCurrentSceneryPath{ "scenery/" };
std::string asCurrentTexturePath{ szTexturePath };
std::string asCurrentDynamicPath;
// settings // settings
// filesystem // filesystem
bool bLoadTraction{ true }; bool bLoadTraction{ true };
std::string szTexturesTGA{ ".tga" }; // lista tekstur od TGA std::string szTexturesTGA{ ".tga" }; // lista tekstur od TGA
std::string szTexturesDDS{ ".dds" }; // lista tekstur od DDS std::string szTexturesDDS{ ".dds" }; // lista tekstur od DDS
std::string szDefaultExt{ szTexturesDDS }; std::string szDefaultExt{ szTexturesDDS };
std::string asCurrentSceneryPath{ "scenery/" };
std::string asCurrentTexturePath{ szTexturePath };
std::string asCurrentDynamicPath;
std::string SceneryFile{ "td.scn" }; std::string SceneryFile{ "td.scn" };
std::string asHumanCtrlVehicle{ "EU07-424" }; std::string asHumanCtrlVehicle{ "EU07-424" };
int iConvertModels{ 0 }; // tworzenie plików binarnych int iConvertModels{ 0 }; // tworzenie plików binarnych

View File

@@ -179,11 +179,8 @@ public:
void create_geometry( std::size_t &Dataoffset, gfx::geometrybank_handle const &Bank ); void create_geometry( std::size_t &Dataoffset, gfx::geometrybank_handle const &Bank );
int FlagsCheck(); int FlagsCheck();
void WillBeAnimated() void WillBeAnimated() {
{ iFlags |= 0x4000; };
if (this)
iFlags |= 0x4000;
};
void InitialRotate(bool doit); void InitialRotate(bool doit);
void BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t, std::vector<std::string> *n, bool dynamic); void BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t, std::vector<std::string> *n, bool dynamic);
static void ReplacableSet(material_handle const *r, int a) { static void ReplacableSet(material_handle const *r, int a) {

View File

@@ -477,10 +477,17 @@ double TTraction::VoltageGet(double u, double i)
// 1. zasilacz psPower[0] z rezystancją fResistance[0] oraz jego wewnętrzną // 1. zasilacz psPower[0] z rezystancją fResistance[0] oraz jego wewnętrzną
// 2. zasilacz psPower[1] z rezystancją fResistance[1] 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 // 3. zasilacz psPowered z jego wewnętrzną rezystancją dla przęseł zasilanych bezpośrednio
double res = (i != 0.0) ? (u / i) : 10000.0; double res = (
if (psPowered) (i != 0.0) ?
return psPowered->CurrentGet(res) * (u / i) :
res; // yB: dla zasilanego nie baw się w gwiazdy, tylko bierz bezpośrednio 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 r0t, r1t, r0g, r1g;
double i0, i1; double i0, i1;
r0t = fResistance[0]; //średni pomysł, ale lepsze niż nic r0t = fResistance[0]; //średni pomysł, ale lepsze niż nic

View File

@@ -3360,14 +3360,14 @@ void TTrain::OnCommand_redmarkerstoggle( TTrain *Train, command_data const &Comm
if( ( true == FreeFlyModeFlag ) if( ( true == FreeFlyModeFlag )
&& ( Command.action == GLFW_PRESS ) ) { && ( Command.action == GLFW_PRESS ) ) {
auto *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCameraPosition, 10, false, true ) ) }; auto *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) };
if( vehicle == nullptr ) { return; } if( vehicle == nullptr ) { return; }
int const CouplNr { int const CouplNr {
clamp( clamp(
vehicle->DirectionGet() 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 :
-1 ), -1 ),
0, 1 ) }; // z [-1,1] zrobić [0,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 ) if( ( true == FreeFlyModeFlag )
&& ( Command.action == GLFW_PRESS ) ) { && ( Command.action == GLFW_PRESS ) ) {
auto *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCameraPosition, 10, false, true ) ) }; auto *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) };
if( vehicle == nullptr ) { return; } if( vehicle == nullptr ) { return; }
int const CouplNr { int const CouplNr {
clamp( clamp(
vehicle->DirectionGet() 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 :
-1 ), -1 ),
0, 1 ) }; // z [-1,1] zrobić [0,1] 0, 1 ) }; // z [-1,1] zrobić [0,1]
@@ -4327,13 +4327,13 @@ bool TTrain::Update( double const Deltatime )
// update driver's position // 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; Vec.y = -Vec.y;
if( mvOccupied->ActiveCab < 0 ) { if( mvOccupied->ActiveCab < 0 ) {
Vec *= -1.0f; Vec *= -1.0f;
Vec.y = -Vec.y; Vec.y = -Vec.y;
} }
Vec.RotateY( Global.pCamera->Yaw ); Vec.RotateY( Global.pCamera.Yaw );
vMechMovement = Vec; vMechMovement = Vec;
} }
@@ -5949,8 +5949,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
} }
// reset view angles // reset view angles
pMechViewAngle = { 0.0, 0.0 }; pMechViewAngle = { 0.0, 0.0 };
Global.pCamera->Pitch = pMechViewAngle.x; Global.pCamera.Pitch = pMechViewAngle.x;
Global.pCamera->Yaw = pMechViewAngle.y; Global.pCamera.Yaw = pMechViewAngle.y;
pyScreens.reset(this); pyScreens.reset(this);
pyScreens.setLookupPath(DynamicObject->asBaseDir); pyScreens.setLookupPath(DynamicObject->asBaseDir);
@@ -6016,8 +6016,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
>> viewangle.y // yaw first, then pitch >> viewangle.y // yaw first, then pitch
>> viewangle.x; >> viewangle.x;
pMechViewAngle = glm::radians( viewangle ); pMechViewAngle = glm::radians( viewangle );
Global.pCamera->Pitch = pMechViewAngle.x; Global.pCamera.Pitch = pMechViewAngle.x;
Global.pCamera->Yaw = pMechViewAngle.y; Global.pCamera.Yaw = pMechViewAngle.y;
parser->getTokens(); parser->getTokens();
*parser >> token; *parser >> token;

View File

@@ -117,7 +117,7 @@ openal_source::sync_with( sound_properties const &State ) {
::alSourcefv( id, AL_VELOCITY, glm::value_ptr( sound_velocity ) ); ::alSourcefv( id, AL_VELOCITY, glm::value_ptr( sound_velocity ) );
// location // location
properties.location = State.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 ) { if( sound_range > 0 ) {
// range cutoff check // range cutoff check
auto const cutoffrange = ( auto const cutoffrange = (
@@ -312,7 +312,7 @@ openal_renderer::update( double const Deltatime ) {
// update listener // update listener
// orientation // orientation
glm::dmat4 cameramatrix; glm::dmat4 cameramatrix;
Global.pCamera->SetMatrix( cameramatrix ); Global.pCamera.SetMatrix( cameramatrix );
auto rotationmatrix { glm::mat3{ cameramatrix } }; auto rotationmatrix { glm::mat3{ cameramatrix } };
glm::vec3 const orientation[] = { glm::vec3 const orientation[] = {
glm::vec3{ 0, 0,-1 } * rotationmatrix , glm::vec3{ 0, 0,-1 } * rotationmatrix ,
@@ -320,7 +320,7 @@ openal_renderer::update( double const Deltatime ) {
::alListenerfv( AL_ORIENTATION, reinterpret_cast<ALfloat const *>( orientation ) ); ::alListenerfv( AL_ORIENTATION, reinterpret_cast<ALfloat const *>( orientation ) );
// velocity // velocity
if( Deltatime > 0 ) { if( Deltatime > 0 ) {
glm::dvec3 const listenerposition { Global.pCameraPosition }; glm::dvec3 const listenerposition { Global.pCamera.Pos };
glm::dvec3 const listenermovement { listenerposition - m_listenerposition }; glm::dvec3 const listenermovement { listenerposition - m_listenerposition };
m_listenerposition = listenerposition; m_listenerposition = listenerposition;
m_listenervelocity = ( m_listenervelocity = (

View File

@@ -241,8 +241,8 @@ void
driver_mode::enter() { driver_mode::enter() {
Camera.Init(Global.FreeCameraInit[0], Global.FreeCameraInitAngle[0], ( FreeFlyModeFlag ? TCameraType::tp_Free : TCameraType::tp_Follow ) ); Camera.Init(Global.FreeCameraInit[0], Global.FreeCameraInitAngle[0], ( FreeFlyModeFlag ? TCameraType::tp_Free : TCameraType::tp_Follow ) );
Global.pCamera = &Camera; Global.pCamera = Camera;
Global.pDebugCamera = &DebugCamera; Global.pDebugCamera = DebugCamera;
TDynamicObject *nPlayerTrain { ( TDynamicObject *nPlayerTrain { (
( Global.asHumanCtrlVehicle != "ghostview" ) ? ( Global.asHumanCtrlVehicle != "ghostview" ) ?
@@ -281,7 +281,6 @@ driver_mode::enter() {
FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie FreeFlyModeFlag = true; // Ra: automatycznie włączone latanie
Camera.Type = TCameraType::tp_Free; Camera.Type = TCameraType::tp_Free;
DebugCamera = Camera; DebugCamera = Camera;
Global.DebugCameraPosition = DebugCamera.Pos;
} }
// if (!Global.bMultiplayer) //na razie włączone // 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 ) if( Action == GLFW_PRESS ) {
|| ( 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 ) {
OnKeyDown( Key ); OnKeyDown( Key );
@@ -414,9 +403,9 @@ driver_mode::update_camera( double const Deltatime ) {
Camera.LookAt = controlled->GetPosition(); Camera.LookAt = controlled->GetPosition();
} }
else { else {
TDynamicObject *d = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCameraPosition, 300, false, false ) ); TDynamicObject *d = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 300, false, false ) );
if( !d ) if( !d )
d = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCameraPosition, 1000, false, false ) ); // dalej szukanie, jesli bliżej nie ma d = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 1000, false, false ) ); // dalej szukanie, jesli bliżej nie ma
if( d && pDynamicNearest ) { if( d && pDynamicNearest ) {
// jeśli jakiś jest znaleziony wcześniej // 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 // all done, update camera position to the new value
Global.pCameraPosition = Camera.Pos; Global.pCamera = Camera;
Global.DebugCameraPosition = DebugCamera.Pos;
} }
void void
@@ -615,7 +603,7 @@ driver_mode::OnKeyDown(int cKey) {
} }
else // również przeskakiwanie else // również przeskakiwanie
{ // Ra: to z tą kamerą (Camera.Pos i Global.pCameraPosition) jest trochę bez sensu { // 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 Camera.Init( Global.FreeCameraInit[ i ], Global.FreeCameraInitAngle[ i ], TCameraType::tp_Free ); // przestawienie
} }
} }
@@ -653,7 +641,7 @@ driver_mode::OnKeyDown(int cKey) {
break; break;
} }
TDynamicObject *tmp = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCameraPosition, 50, true, false ) ); TDynamicObject *tmp = std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 50, true, false ) );
if( tmp != nullptr ) { if( tmp != nullptr ) {
@@ -879,9 +867,6 @@ driver_mode::FollowView(bool wycisz) {
train->Dynamic()->ABuSetModelShake( {} ); train->Dynamic()->ABuSetModelShake( {} );
DistantView(); // przestawienie kamery 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 { else {
Camera.Pos = train->pMechPosition; Camera.Pos = train->pMechPosition;
@@ -987,7 +972,6 @@ driver_mode::InOutKey( bool const Near )
DistantView( Near ); DistantView( Near );
} }
DebugCamera = Camera; DebugCamera = Camera;
Global.DebugCameraPosition = DebugCamera.Pos;
} }
else else
{ // jazda w kabinie { // jazda w kabinie

View File

@@ -193,7 +193,7 @@ driver_ui::update() {
auto const *train { simulation::Train }; auto const *train { simulation::Train };
auto const *controlled { ( train ? train->Dynamic() : nullptr ) }; auto const *controlled { ( train ? train->Dynamic() : nullptr ) };
auto const *camera { Global.pCamera }; auto const &camera { Global.pCamera };
if( ( train != nullptr ) && ( false == FreeFlyModeFlag ) ) { if( ( train != nullptr ) && ( false == FreeFlyModeFlag ) ) {
if( false == DebugModeFlag ) { if( false == DebugModeFlag ) {
@@ -292,7 +292,7 @@ driver_ui::update() {
// timetable // timetable
auto *vehicle { auto *vehicle {
( FreeFlyModeFlag ? ( FreeFlyModeFlag ?
std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera->Pos, 20, false, false ) ) : std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera.Pos, 20, false, false ) ) :
controlled ) }; // w trybie latania lokalizujemy wg mapy controlled ) }; // w trybie latania lokalizujemy wg mapy
if( vehicle == nullptr ) { break; } if( vehicle == nullptr ) { break; }
@@ -398,7 +398,7 @@ driver_ui::update() {
auto const *vehicle { auto const *vehicle {
( FreeFlyModeFlag ? ( FreeFlyModeFlag ?
std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera->Pos, 20, false, false ) ) : std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera.Pos, 20, false, false ) ) :
controlled ) }; // w trybie latania lokalizujemy wg mapy controlled ) }; // w trybie latania lokalizujemy wg mapy
if( vehicle != nullptr ) { 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 // wyświetlenie współrzędnych w scenerii oraz kąta kamery, gdy nie mamy wskaźnika
uitextline1 = uitextline1 =
"Camera position: " "Camera position: "
+ to_string( camera->Pos.x, 2 ) + " " + to_string( camera.Pos.x, 2 ) + " "
+ to_string( camera->Pos.y, 2 ) + " " + to_string( camera.Pos.y, 2 ) + " "
+ to_string( camera->Pos.z, 2 ) + to_string( camera.Pos.z, 2 )
+ ", azimuth: " + ", 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" ) + 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 // current luminance level
uitextline2 = "Light level: " + to_string( Global.fLuminance, 3 ); uitextline2 = "Light level: " + to_string( Global.fLuminance, 3 );
if( Global.FakeLight ) { uitextline2 += "(*)"; } if( Global.FakeLight ) { uitextline2 += "(*)"; }
@@ -683,7 +683,7 @@ driver_ui::update() {
auto const *vehicle { auto const *vehicle {
( FreeFlyModeFlag ? ( FreeFlyModeFlag ?
std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera->Pos, 20, false, false ) ) : std::get<TDynamicObject *>( simulation::Region->find_vehicle( camera.Pos, 20, false, false ) ) :
controlled ) }; // w trybie latania lokalizujemy wg mapy controlled ) }; // w trybie latania lokalizujemy wg mapy
if( vehicle == nullptr ) { if( vehicle == nullptr ) {
break; break;

View File

@@ -43,7 +43,10 @@ editor_mode::editor_mode() {
bool bool
editor_mode::init() { 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(); 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 // reset window state, it'll be set again if applicable in a check below
Global.CabWindowOpen = false; Global.CabWindowOpen = false;
// all done, update camera position to the new value // all done, update camera position to the new value
Global.pCameraPosition = Camera.Pos; Global.pCamera = Camera;
} }
// maintenance method, called when the mode is activated // maintenance method, called when the mode is activated
@@ -106,7 +109,7 @@ editor_mode::enter() {
m_statebackup = { Global.pCamera, FreeFlyModeFlag, Global.ControlPicking }; m_statebackup = { Global.pCamera, FreeFlyModeFlag, Global.ControlPicking };
Global.pCamera = &Camera; Global.pCamera = Camera;
FreeFlyModeFlag = true; FreeFlyModeFlag = true;
Global.ControlPicking = true; Global.ControlPicking = true;
EditorModeFlag = true; EditorModeFlag = true;
@@ -127,6 +130,10 @@ editor_mode::exit() {
( Global.ControlPicking ? ( Global.ControlPicking ?
GLFW_CURSOR_NORMAL : GLFW_CURSOR_NORMAL :
GLFW_CURSOR_DISABLED ) ); GLFW_CURSOR_DISABLED ) );
if( false == Global.ControlPicking ) {
Application.set_cursor_pos( 0, 0 );
}
} }
void 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( 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 // legacy hardcoded keyboard commands
// TODO: replace with current command system, move to input object(s) // TODO: replace with current command system, move to input object(s)
switch( Key ) { switch( Key ) {

View File

@@ -57,7 +57,7 @@ private:
struct state_backup { struct state_backup {
TCamera *camera; TCamera camera;
bool freefly; bool freefly;
bool picking; bool picking;
}; };

View File

@@ -48,7 +48,7 @@ editor_ui::update() {
std::string uitextline1, uitextline2, uitextline3, uitextline4; std::string uitextline1, uitextline2, uitextline3, uitextline4;
set_tooltip( "" ); set_tooltip( "" );
auto const *camera { Global.pCamera }; auto const &camera { Global.pCamera };
if( ( true == Global.ControlPicking ) if( ( true == Global.ControlPicking )
&& ( true == DebugModeFlag ) ) { && ( true == DebugModeFlag ) ) {
@@ -60,12 +60,11 @@ editor_ui::update() {
"" ) ); "" ) );
} }
// scenario inspector // scenario inspector
auto const *node { m_node }; auto const *node { m_node };
if( node == nullptr ) { 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 ) + "]"; uitextline1 = "mouse location: [" + to_string( mouseposition.x, 2 ) + ", " + to_string( mouseposition.y, 2 ) + ", " + to_string( mouseposition.z, 2 ) + "]";
goto update; goto update;
} }
@@ -73,7 +72,7 @@ editor_ui::update() {
uitextline1 = uitextline1 =
"node name: " + node->name() "node name: " + node->name()
+ "; location: [" + to_string( node->location().x, 2 ) + ", " + to_string( node->location().y, 2 ) + ", " + to_string( node->location().z, 2 ) + "]" + "; 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 // subclass-specific data
// TBD, TODO: specialized data dump method in each node subclass, or data imports in the panel for provided subclass pointer? // 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 ) ) { if( typeid( *node ) == typeid( TAnimModel ) ) {

View File

@@ -810,12 +810,12 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
case rendermode::color: { case rendermode::color: {
// modelview // modelview
if( ( false == DebugCameraFlag ) || ( true == Ignoredebug ) ) { if( ( false == DebugCameraFlag ) || ( true == Ignoredebug ) ) {
camera.position() = Global.pCameraPosition; camera.position() = Global.pCamera.Pos;
Global.pCamera->SetMatrix( viewmatrix ); Global.pCamera.SetMatrix( viewmatrix );
} }
else { else {
camera.position() = Global.DebugCameraPosition; camera.position() = Global.pDebugCamera.Pos;
Global.pDebugCamera->SetMatrix( viewmatrix ); Global.pDebugCamera.SetMatrix( viewmatrix );
} }
// projection // projection
auto const zfar = Config.draw_range * Global.fDistanceFactor * Zfar; 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, m_sunlight.direction.x,
std::min( m_sunlight.direction.y, -0.2f ), std::min( m_sunlight.direction.y, -0.2f ),
m_sunlight.direction.z } ); m_sunlight.direction.z } );
camera.position() = Global.pCameraPosition - glm::dvec3 { lightvector }; camera.position() = Global.pCamera.Pos - glm::dvec3 { lightvector };
viewmatrix *= glm::lookAt( viewmatrix *= glm::lookAt(
camera.position(), camera.position(),
glm::dvec3 { Global.pCameraPosition }, glm::dvec3 { Global.pCamera.Pos },
glm::dvec3 { 0.f, 1.f, 0.f } ); glm::dvec3 { 0.f, 1.f, 0.f } );
// projection // projection
auto const maphalfsize { Config.draw_range * 0.5f }; auto const maphalfsize { Config.draw_range * 0.5f };
@@ -947,8 +947,8 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
// modelview // modelview
camera.position() = ( camera.position() = (
( ( true == DebugCameraFlag ) && ( false == Ignoredebug ) ) ? ( ( true == DebugCameraFlag ) && ( false == Ignoredebug ) ) ?
Global.DebugCameraPosition : Global.pDebugCamera.Pos :
Global.pCameraPosition ); 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 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 } }; 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; 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: { case rendermode::pickscenery: {
// TODO: scissor test for pick modes // TODO: scissor test for pick modes
// modelview // modelview
camera.position() = Global.pCameraPosition; camera.position() = Global.pCamera.Pos;
Global.pCamera->SetMatrix( viewmatrix ); Global.pCamera.SetMatrix( viewmatrix );
// projection // projection
camera.projection() *= camera.projection() *=
glm::perspective( glm::perspective(
@@ -1997,7 +1997,7 @@ opengl_renderer::Render( scene::shape_node const &Shape, bool const Ignorerange
switch( m_renderpass.draw_mode ) { switch( m_renderpass.draw_mode ) {
case rendermode::shadows: { case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees // '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; break;
} }
default: { default: {
@@ -2051,7 +2051,7 @@ opengl_renderer::Render( TAnimModel *Instance ) {
switch( m_renderpass.draw_mode ) { switch( m_renderpass.draw_mode ) {
case rendermode::shadows: { case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees // '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; break;
} }
default: { default: {
@@ -2105,7 +2105,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
float squaredistance; float squaredistance;
switch( m_renderpass.draw_mode ) { switch( m_renderpass.draw_mode ) {
case rendermode::shadows: { 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; break;
} }
default: { default: {
@@ -2901,7 +2901,7 @@ opengl_renderer::Render_Alpha( TAnimModel *Instance ) {
switch( m_renderpass.draw_mode ) { switch( m_renderpass.draw_mode ) {
case rendermode::shadows: { case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees // '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; break;
} }
default: { default: {
@@ -2933,7 +2933,7 @@ opengl_renderer::Render_Alpha( TTraction *Traction ) {
switch( m_renderpass.draw_mode ) { switch( m_renderpass.draw_mode ) {
case rendermode::shadows: { case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees // '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; break;
} }
default: { default: {
@@ -2994,7 +2994,7 @@ opengl_renderer::Render_Alpha( scene::lines_node const &Lines ) {
switch( m_renderpass.draw_mode ) { switch( m_renderpass.draw_mode ) {
case rendermode::shadows: { case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees // '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; break;
} }
default: { default: {
@@ -3042,7 +3042,7 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
float squaredistance; float squaredistance;
switch( m_renderpass.draw_mode ) { switch( m_renderpass.draw_mode ) {
case rendermode::shadows: { 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; break;
} }
default: { default: {

View File

@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
#include "simulation.h" #include "simulation.h"
#include "globals.h" #include "globals.h"
#include "camera.h"
#include "animmodel.h" #include "animmodel.h"
#include "event.h" #include "event.h"
#include "evlaunch.h" #include "evlaunch.h"
@@ -122,7 +123,7 @@ basic_cell::update_events() {
// event launchers // event launchers
for( auto *launcher : m_eventlaunchers ) { for( auto *launcher : m_eventlaunchers ) {
if( ( true == ( launcher->check_activation() && launcher->check_conditions() ) ) 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 ); launch_event( launcher );
} }
@@ -948,9 +949,9 @@ void
basic_region::update_events() { basic_region::update_events() {
// render events and sounds from sectors near enough to the viewer // render events and sounds from sectors near enough to the viewer
auto const range = EU07_SECTIONSIZE; // arbitrary range auto const range = EU07_SECTIONSIZE; // arbitrary range
auto const &sectionlist = sections( Global.pCameraPosition, range ); auto const &sectionlist = sections( Global.pCamera.Pos, range );
for( auto *section : sectionlist ) { 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() { basic_region::update_sounds() {
// render events and sounds from sectors near enough to the viewer // render events and sounds from sectors near enough to the viewer
auto const range = 2750.f; // audible range of 100 db sound auto const range = 2750.f; // audible range of 100 db sound
auto const &sectionlist = sections( Global.pCameraPosition, range ); auto const &sectionlist = sections( Global.pCamera.Pos, range );
for( auto *section : sectionlist ) { for( auto *section : sectionlist ) {
section->update_sounds( Global.pCameraPosition, range ); section->update_sounds( Global.pCamera.Pos, range );
} }
} }

View File

@@ -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 // NOTE: offset scaling is calculated early so the same multiplier can be applied to potential whole group
auto location { Node->location() }; 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 const offset { Offset * std::max( 1.0, distance * 0.01 ) };
auto *node { Node }; // placeholder for operations on multiple nodes auto *node { Node }; // placeholder for operations on multiple nodes

View File

@@ -299,7 +299,7 @@ private:
// base interface for nodes which can be actvated in scenario editor // base interface for nodes which can be actvated in scenario editor
struct basic_node { class basic_node {
public: public:
// constructor // constructor

View File

@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
#include "sound.h" #include "sound.h"
#include "parser.h" #include "parser.h"
#include "globals.h" #include "globals.h"
#include "camera.h"
#include "train.h" #include "train.h"
#include "dynobj.h" #include "dynobj.h"
#include "simulation.h" #include "simulation.h"
@@ -357,7 +358,7 @@ sound_source::play( int const Flags ) {
if( m_range > 0 ) { if( m_range > 0 ) {
auto const cutoffrange { m_range * 5 }; 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 // 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 // we act as if it was activated normally, meaning no need to include the opening bookend in subsequent calls
m_playbeginning = false; m_playbeginning = false;

View File

@@ -149,10 +149,14 @@ ui_layer::set_background( std::string const &Filename ) {
else { else {
m_background = null_handle; m_background = null_handle;
} }
if( m_background != null_handle ) { if( m_background != null_handle ) {
auto const &texture = GfxRenderer.Texture( m_background ); auto const &texture = GfxRenderer.Texture( m_background );
m_progressbottom = ( texture.width() != texture.height() ); m_progressbottom = ( texture.width() != texture.height() );
} }
else {
m_progressbottom = true;
}
} }
void void

View File

@@ -116,7 +116,7 @@ private:
float m_progress { 0.0f }; // percentage of filled progres bar, to indicate lengthy operations. 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. float m_subtaskprogress{ 0.0f }; // percentage of filled progres bar, to indicate lengthy operations.
std::string m_progresstext; // label placed over the progress bar 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. texture_handle m_background { null_handle }; // path to texture used as the background. size depends on mAspect.
GLuint m_texture { 0 }; GLuint m_texture { 0 };