#include "externals.hh" #include "utilities.hh" void disableButton( ) { ImGui::PushStyleColor( ImGuiCol_Button , ImVec4( .3 , .3 , .3 , 1 ) ); ImGui::PushStyleColor( ImGuiCol_ButtonHovered , ImVec4( .3 , .3 , .3 , 1 ) ); ImGui::PushStyleColor( ImGuiCol_ButtonActive , ImVec4( .3 , .3 , .3 , 1 ) ); } /*----------------------------------------------------------------------------*/ void updateAngle( float& initial , const float delta ) { initial = fmod( initial + delta + 540 , 360 ) - 180; } void anglesToMatrix( float const* angles , float* matrix ) { float c[3] , s[3]; for ( int i = 0 ; i < 3 ; i ++ ) { const float a = M_PI * angles[ i ] / 180; c[i] = cos( a ); s[i] = sin( a ); } matrix[0] = c[1]*c[2]; matrix[1] = s[0]*s[1]*c[2] - c[0]*s[2]; matrix[2] = s[0]*s[2] + c[0]*s[1]*c[2]; matrix[3] = c[1]*s[2]; matrix[4] = c[0]*c[2] + s[0]*s[1]*s[2]; matrix[5] = c[0]*s[1]*s[2] - s[0]*c[2]; matrix[6] = -s[1]; matrix[7] = s[0]*c[1]; matrix[8] = c[0]*c[1]; } /*----------------------------------------------------------------------------*/ T_String GetAbsolutePath( T_String const& path ) { char* const rp( realpath( (char*) path.toOSString( ).data( ) , nullptr ) ); if ( !rp ) { return {}; } const T_String rv( rp ); free( rp ); return rv; } T_String GetParentPath( T_String const& path ) { auto buffer( path.toOSString( ) ); char* const rp( realpath( dirname( (char*) buffer.data( ) ) , nullptr ) ); if ( !rp ) { return {}; } const T_String rv( rp ); free( rp ); return rv; } /*= JSON =====================================================================*/ template void jsonAdd< double >( T_JSONObject& object , std::string const& key , double const& v ); template void jsonAdd< T_JSONObject >( T_JSONObject& object , std::string const& key , T_JSONObject const& v ); template void jsonAdd< T_JSONArray >( T_JSONObject& object , std::string const& key , T_JSONArray const& v ); template void jsonAdd< std::string >( T_JSONObject& object , std::string const& key , std::string const& v ); template< > void jsonAdd< picojson::value >( T_JSONObject& object , std::string const& key , picojson::value const& v ) { using T_Entry = std::pair< std::string , picojson::value >; object.insert( T_Entry( key , v ) ); } template< > void jsonAdd< int >( T_JSONObject& object , std::string const& key , int const& v ) { using T_Entry = std::pair< std::string , picojson::value >; object.insert( T_Entry( key , picojson::value( double( v ) ) ) ); } template< > void jsonAdd< unsigned >( T_JSONObject& object , std::string const& key , unsigned const& v ) { using T_Entry = std::pair< std::string , picojson::value >; object.insert( T_Entry( key , picojson::value( double( v ) ) ) ); } /*----------------------------------------------------------------------------*/ picojson::value jsonVector( float const* vector , const int nComponents ) { using namespace picojson; value::array a; for ( auto i = 0 ; i < nComponents ; i ++ ) { a.push_back( value( vector[ i ] ) ); } return value( a ); } /*----------------------------------------------------------------------------*/ void jsonGetVectorOpt( float* vector , const size_t size , T_JSONObject const& object , char const* key ) { using namespace picojson; auto const* ptr( jsonGetOpt< array >( object , key ) ); if ( !ptr ) { return; } auto const& a( *ptr ); if ( a.size( ) != size ) { throw X_JsonGetFailed( ); } int i = 0; for ( auto const& av : a ) { if ( !av.is< double >( ) ) { throw X_JsonGetFailed( ); } vector[ i ++ ] = float( av.get< double >( ) ); } }