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.
This commit is contained in:
Emmanuel BENOîT 2017-11-20 11:36:30 +01:00
parent 75af2c15c7
commit 2b1657ac3a
2 changed files with 22 additions and 17 deletions

View file

@ -1125,26 +1125,29 @@ void T_CamOverride::makeEditWidgets(
T_StringBuilder& sb ) noexcept T_StringBuilder& sb ) noexcept
{ {
auto& sinp( Globals::Sync( ).inputs( ) ); auto& sinp( Globals::Sync( ).inputs( ) );
// Set field of view / near plane
auto const& fc( *fovConfig_ ); 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 if ( !enabled( ) || !prevEnabled_ ) {
const glm::vec3 lookAt{ vectorFromInputs( *target_ ) }; // Set field of view / near plane
if ( camMode_ == CM_ANGLES ) { if ( fc.mode == FM_FOV ) {
const glm::vec3 angles{ vectorFromInputs( *angles_ ) }; camera_.fieldOfView( sinp[ inputPos_[ fc.inputIndex ] ] );
const float distance{ sinp[ inputPos_[ *distance_ ] ] }; } else {
camera_.camera( lookAt , angles , distance ); camera_.nearPlane( sinp[ inputPos_[ fc.inputIndex ] ] );
} else { }
const glm::vec3 position{ vectorFromInputs( *position_ ) };
const glm::vec3 up{ vectorFromInputs( *upVector_ ) }; // Set camera parameters
camera_.camera( lookAt , position , up ); 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 // Draw UI
char const* const name( buildLabel( counter , sb ) ); char const* const name( buildLabel( counter , sb ) );

View file

@ -267,6 +267,8 @@ class T_CamOverride : public A_SyncOverride
E_CamMode_ camMode_; E_CamMode_ camMode_;
T_Camera camera_; T_Camera camera_;
bool prevEnabled_{ false };
public: public:
T_CamOverride( T_String const& title ) noexcept; T_CamOverride( T_String const& title ) noexcept;