From 2b1657ac3a04a605aa6926b4ceacc15eaa8e80d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 20 Nov 2017 11:36:30 +0100 Subject: [PATCH] Overrides - Camera angles problem fixed Because of fucking numerical instability, updating the UI's input values every frame caused problems. Fixed this by making sure it's set only if the override is disabled or at the first frame after it is enabled. --- syncoverrides.cc | 37 ++++++++++++++++++++----------------- syncoverrides.hh | 2 ++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/syncoverrides.cc b/syncoverrides.cc index 81435f5..47fa7a1 100644 --- a/syncoverrides.cc +++ b/syncoverrides.cc @@ -1125,26 +1125,29 @@ void T_CamOverride::makeEditWidgets( T_StringBuilder& sb ) noexcept { auto& sinp( Globals::Sync( ).inputs( ) ); - - // Set field of view / near plane auto const& fc( *fovConfig_ ); - if ( fc.mode == FM_FOV ) { - camera_.fieldOfView( sinp[ inputPos_[ fc.inputIndex ] ] ); - } else { - camera_.nearPlane( sinp[ inputPos_[ fc.inputIndex ] ] ); - } - // Set camera parameters - const glm::vec3 lookAt{ vectorFromInputs( *target_ ) }; - if ( camMode_ == CM_ANGLES ) { - const glm::vec3 angles{ vectorFromInputs( *angles_ ) }; - const float distance{ sinp[ inputPos_[ *distance_ ] ] }; - camera_.camera( lookAt , angles , distance ); - } else { - const glm::vec3 position{ vectorFromInputs( *position_ ) }; - const glm::vec3 up{ vectorFromInputs( *upVector_ ) }; - camera_.camera( lookAt , position , up ); + if ( !enabled( ) || !prevEnabled_ ) { + // Set field of view / near plane + if ( fc.mode == FM_FOV ) { + camera_.fieldOfView( sinp[ inputPos_[ fc.inputIndex ] ] ); + } else { + camera_.nearPlane( sinp[ inputPos_[ fc.inputIndex ] ] ); + } + + // Set camera parameters + const glm::vec3 lookAt{ vectorFromInputs( *target_ ) }; + if ( camMode_ == CM_ANGLES ) { + const glm::vec3 angles{ vectorFromInputs( *angles_ ) }; + const float distance{ sinp[ inputPos_[ *distance_ ] ] }; + camera_.camera( lookAt , angles , distance ); + } else { + const glm::vec3 position{ vectorFromInputs( *position_ ) }; + const glm::vec3 up{ vectorFromInputs( *upVector_ ) }; + camera_.camera( lookAt , position , up ); + } } + prevEnabled_ = enabled( ); // Draw UI char const* const name( buildLabel( counter , sb ) ); diff --git a/syncoverrides.hh b/syncoverrides.hh index 8c7f234..0674cad 100644 --- a/syncoverrides.hh +++ b/syncoverrides.hh @@ -267,6 +267,8 @@ class T_CamOverride : public A_SyncOverride E_CamMode_ camMode_; T_Camera camera_; + bool prevEnabled_{ false }; + public: T_CamOverride( T_String const& title ) noexcept;