From 44557485be85783b7ecb48ca03431813eebcbddc Mon Sep 17 00:00:00 2001 From: NevilClavain Date: Fri, 28 Jul 2023 20:05:12 +0200 Subject: [PATCH] for issue #80 --- lua_core/src/luaclass_globals.cpp | 6 +- .../src/luaclass_freemvttransform.cpp | 1 + .../src/orbittransformaspectimpl.cpp | 1 + .../planets_luaext/src/lod_body.cpp | 2 +- .../planets_luaext/src/lod_drawing.cpp | 5 +- .../planets_luaext/src/lod_face.cpp | 1 + .../planets_luaext/src/lod_layer.cpp | 1 + .../planets_luaext/src/lod_patch.cpp | 5 +- .../src/planetsrenderingaspectimpl.cpp | 4 +- .../src/revolutiontransformaspectimpl.cpp | 1 + src/maths.h | 198 +++++++++--------- src/quaternion.h | 7 +- 12 files changed, 122 insertions(+), 110 deletions(-) diff --git a/lua_core/src/luaclass_globals.cpp b/lua_core/src/luaclass_globals.cpp index 935bd778..e0f17bfd 100644 --- a/lua_core/src/luaclass_globals.cpp +++ b/lua_core/src/luaclass_globals.cpp @@ -41,6 +41,8 @@ using namespace DrawSpace; +using namespace DrawSpace::Commons; + using namespace DrawSpace::Core; using namespace DrawSpace::Utils; @@ -663,7 +665,7 @@ int LuaClass_Globals::LUA_ctos(lua_State* p_L) Vector c(x, y, z, 1.0); Vector s; - Utils::Maths::CartesiantoSpherical(c, s); + Maths::CartesiantoSpherical(c, s); dsreal longit{ Maths::RadToDeg(s[1]) }; dsreal latit{ Maths::RadToDeg(s[2]) }; @@ -688,7 +690,7 @@ int LuaClass_Globals::LUA_stoc(lua_State* p_L) Vector s(r, t, p, 1.0); Vector c; - Utils::Maths::SphericaltoCartesian(s, c); + Maths::SphericaltoCartesian(s, c); lua_pushnumber(p_L, c[0]); lua_pushnumber(p_L, c[1]); diff --git a/lua_extensions/freemvt_luaext/src/luaclass_freemvttransform.cpp b/lua_extensions/freemvt_luaext/src/luaclass_freemvttransform.cpp index da7b8d32..33e0f12b 100644 --- a/lua_extensions/freemvt_luaext/src/luaclass_freemvttransform.cpp +++ b/lua_extensions/freemvt_luaext/src/luaclass_freemvttransform.cpp @@ -30,6 +30,7 @@ #include "quaternion.h" using namespace DrawSpace; +using namespace DrawSpace::Commons; using namespace DrawSpace::Core; using namespace DrawSpace::Utils; using namespace DrawSpace::Aspect; diff --git a/lua_extensions/orbit_luaext/src/orbittransformaspectimpl.cpp b/lua_extensions/orbit_luaext/src/orbittransformaspectimpl.cpp index 31a4765b..6a6db69d 100644 --- a/lua_extensions/orbit_luaext/src/orbittransformaspectimpl.cpp +++ b/lua_extensions/orbit_luaext/src/orbittransformaspectimpl.cpp @@ -29,6 +29,7 @@ #include "maths.h" using namespace DrawSpace; +using namespace DrawSpace::Commons; using namespace DrawSpace::Core; using namespace DrawSpace::Aspect; using namespace DrawSpace::Utils; diff --git a/lua_extensions/planets_luaext/src/lod_body.cpp b/lua_extensions/planets_luaext/src/lod_body.cpp index 0b40ba7b..867af9dd 100644 --- a/lua_extensions/planets_luaext/src/lod_body.cpp +++ b/lua_extensions/planets_luaext/src/lod_body.cpp @@ -98,7 +98,7 @@ void Body::Compute( void ) ///////////////////////////////////////// // alignment_factor_limit augmente au fur et a mesure qu'on approche l'altitude zero - const auto alignment_factor_limit { 0.25 * DrawSpace::Utils::Maths::Clamp(0.0, 1.0, (3.0 - m_relative_alt) / 3.0) }; + const auto alignment_factor_limit { 0.25 * DrawSpace::Commons::Maths::Clamp(0.0, 1.0, (3.0 - m_relative_alt) / 3.0) }; if( m_enable_cdlod ) { for( long i = 0; i < 6; i++ ) diff --git a/lua_extensions/planets_luaext/src/lod_drawing.cpp b/lua_extensions/planets_luaext/src/lod_drawing.cpp index 2b5428d9..4a9d1bb1 100644 --- a/lua_extensions/planets_luaext/src/lod_drawing.cpp +++ b/lua_extensions/planets_luaext/src/lod_drawing.cpp @@ -46,6 +46,7 @@ using namespace DrawSpace; +using namespace DrawSpace::Commons; using namespace DrawSpace::Core; using namespace DrawSpace::Utils; using namespace DrawSpace::Aspect; @@ -298,7 +299,7 @@ void FaceDrawingNode::draw_single_patch( Patch* p_patch, dsreal p_ray, dsreal p_ Vector landplace_normale( 0.0, 0.0, 1.0, 1.0 ); Vector landplace_normale_orient; - Utils::Maths::VectorPlanetOrientation( p_patch->GetOrientation(), landplace_normale, landplace_normale_orient ); + Maths::VectorPlanetOrientation( p_patch->GetOrientation(), landplace_normale, landplace_normale_orient ); Vector landplace_normale_t; @@ -1242,7 +1243,7 @@ void Drawing::create_landplace_meshe( long p_patch_resol, int p_orientation, Dra Vector v( xcurr, ycurr, 0.0, 1.0 ); - Utils::Maths::VectorPlanetOrientation( p_orientation, v, v_orient ); + Maths::VectorPlanetOrientation( p_orientation, v, v_orient ); vertex.x = v_orient[0]; diff --git a/lua_extensions/planets_luaext/src/lod_face.cpp b/lua_extensions/planets_luaext/src/lod_face.cpp index 3aaf9b39..b28a52f2 100644 --- a/lua_extensions/planets_luaext/src/lod_face.cpp +++ b/lua_extensions/planets_luaext/src/lod_face.cpp @@ -29,6 +29,7 @@ #include "exceptions.h" using namespace DrawSpace; +using namespace DrawSpace::Commons; using namespace DrawSpace::Core; using namespace DrawSpace::Utils; using namespace LOD; diff --git a/lua_extensions/planets_luaext/src/lod_layer.cpp b/lua_extensions/planets_luaext/src/lod_layer.cpp index 9205fe68..3704be05 100644 --- a/lua_extensions/planets_luaext/src/lod_layer.cpp +++ b/lua_extensions/planets_luaext/src/lod_layer.cpp @@ -33,6 +33,7 @@ #include "maths.h" using namespace DrawSpace; +using namespace DrawSpace::Commons; using namespace DrawSpace::Core; using namespace DrawSpace::Utils; using namespace DrawSpace::Aspect; diff --git a/lua_extensions/planets_luaext/src/lod_patch.cpp b/lua_extensions/planets_luaext/src/lod_patch.cpp index 40c88b61..1bc82dd5 100644 --- a/lua_extensions/planets_luaext/src/lod_patch.cpp +++ b/lua_extensions/planets_luaext/src/lod_patch.cpp @@ -38,6 +38,7 @@ using namespace DrawSpace; +using namespace DrawSpace::Commons; using namespace DrawSpace::Core; using namespace DrawSpace::Utils; using namespace LOD; @@ -191,11 +192,11 @@ m_layer_index( p_layer_index ) const auto xpole_center{ poles_coords_rand_source(rand_engine) }; const auto ypole_center{ poles_coords_rand_source(rand_engine) }; - std::uniform_real_distribution theta_rand_source(0.0, Utils::Maths::pi / 2.0); + std::uniform_real_distribution theta_rand_source(0.0, Maths::pi / 2.0); std::uniform_real_distribution r_rand_source(min_pole_ray, max_pole_ray); std::uniform_int_distribution xy_signs_rand_source(1, 2); - std::uniform_real_distribution orientation_source(0.0, Utils::Maths::pi); + std::uniform_real_distribution orientation_source(0.0, Maths::pi); diff --git a/lua_extensions/planets_luaext/src/planetsrenderingaspectimpl.cpp b/lua_extensions/planets_luaext/src/planetsrenderingaspectimpl.cpp index 2f4c9e47..30622e58 100644 --- a/lua_extensions/planets_luaext/src/planetsrenderingaspectimpl.cpp +++ b/lua_extensions/planets_luaext/src/planetsrenderingaspectimpl.cpp @@ -1892,8 +1892,8 @@ void PlanetsRenderingAspectImpl::manage_camerapoints(void) Maths::CartesiantoSpherical(locale_camera_pos_from_planet, spherical); camera.second.locale_camera_long_lat[0] = spherical[0]; - camera.second.locale_camera_long_lat[1] = Utils::Maths::RadToDeg( spherical[1] ); - camera.second.locale_camera_long_lat[2] = Utils::Maths::RadToDeg( spherical[2] ); + camera.second.locale_camera_long_lat[1] = Maths::RadToDeg( spherical[1] ); + camera.second.locale_camera_long_lat[2] = Maths::RadToDeg( spherical[2] ); camera.second.global_camera_pos_from_planet = camera_pos_from_planet; diff --git a/lua_extensions/revolution_luaext/src/revolutiontransformaspectimpl.cpp b/lua_extensions/revolution_luaext/src/revolutiontransformaspectimpl.cpp index be3968d7..83428a65 100644 --- a/lua_extensions/revolution_luaext/src/revolutiontransformaspectimpl.cpp +++ b/lua_extensions/revolution_luaext/src/revolutiontransformaspectimpl.cpp @@ -28,6 +28,7 @@ #include "transformaspect.h" using namespace DrawSpace; +using namespace DrawSpace::Commons; using namespace DrawSpace::Core; using namespace DrawSpace::Aspect; using namespace DrawSpace::Utils; diff --git a/src/maths.h b/src/maths.h index cad80132..eaca4363 100644 --- a/src/maths.h +++ b/src/maths.h @@ -30,113 +30,115 @@ namespace DrawSpace { -namespace Utils -{ -class Maths -{ -public: + namespace Commons + { + using namespace Utils; - static constexpr dsreal pi{ 3.1415927 }; + class Maths + { + public: - static double Square( dsreal a ) { return a * a; }; - static int Floor( dsreal a ) { return ((int)a - (a < 0 && a != (int)a)); }; - static int Ceiling( dsreal a ) { return ((int)a + (a > 0 && a != (int)a)); }; + static constexpr dsreal pi{ 3.1415927 }; - static double Min( dsreal a, dsreal b ) { return (a < b ? a : b); }; - static double Max( dsreal a, dsreal b ) { return (a > b ? a : b); }; - static double Abs( dsreal a ) { return (a < 0 ? -a : a); }; - static double Clamp( dsreal a, dsreal b, dsreal x ) { return (x < a ? a : (x > b ? b : x)); }; - static double Lerp( dsreal a, dsreal b, dsreal x ) { return a + x * (b - a); }; - static double Cubic( dsreal a ) { return a * a * (3 - 2*a); }; - static double Pulse( dsreal a, dsreal b, dsreal x ) { return (double)((x >= a) - (x >= b)); }; - static double Gamma( dsreal a, dsreal g ) { return pow(a, 1/g); }; - static double Expose( dsreal l, dsreal k ) { return (1 - exp(-l * k)); }; - static double DegToRad( dsreal ang ) { return ( ( ang * pi ) / 180.0 ); }; - static double RadToDeg( dsreal ang ) { return ( ( ang * 180.0 ) / pi ); }; + static double Square( dsreal a ) { return a * a; }; + static int Floor( dsreal a ) { return ((int)a - (a < 0 && a != (int)a)); }; + static int Ceiling( dsreal a ) { return ((int)a + (a > 0 && a != (int)a)); }; + static double Min( dsreal a, dsreal b ) { return (a < b ? a : b); }; + static double Max( dsreal a, dsreal b ) { return (a > b ? a : b); }; + static double Abs( dsreal a ) { return (a < 0 ? -a : a); }; + static double Clamp( dsreal a, dsreal b, dsreal x ) { return (x < a ? a : (x > b ? b : x)); }; + static double Lerp( dsreal a, dsreal b, dsreal x ) { return a + x * (b - a); }; + static double Cubic( dsreal a ) { return a * a * (3 - 2*a); }; + static double Pulse( dsreal a, dsreal b, dsreal x ) { return (double)((x >= a) - (x >= b)); }; + static double Gamma( dsreal a, dsreal g ) { return pow(a, 1/g); }; + static double Expose( dsreal l, dsreal k ) { return (1 - exp(-l * k)); }; + static double DegToRad( dsreal ang ) { return ( ( ang * pi ) / 180.0 ); }; + static double RadToDeg( dsreal ang ) { return ( ( ang * 180.0 ) / pi ); }; - static void SphericaltoCartesian( const Vector& p_in, Vector& p_out ) - { - p_out[2] = ( p_in[0] * cos( p_in[2] ) * cos( p_in[1] ) ); - p_out[0] = ( p_in[0] * cos( p_in[2] ) * sin( p_in[1] ) ); - p_out[1] = ( p_in[0] * sin( p_in[2] ) ); - } + + static void SphericaltoCartesian( const Vector& p_in, Vector& p_out ) + { + p_out[2] = ( p_in[0] * cos( p_in[2] ) * cos( p_in[1] ) ); + p_out[0] = ( p_in[0] * cos( p_in[2] ) * sin( p_in[1] ) ); + p_out[1] = ( p_in[0] * sin( p_in[2] ) ); + } - static void CartesiantoSpherical( Vector& p_in, Vector& p_out ) - { - // cas particulier - if( p_in[1] > 0.0 && 0.0 == p_in[0] && 0.0 == p_in[2] ) - { - p_out[0] = p_in[1]; - p_out[2] = pi / 2.0; - p_out[1] = 0.0; - return; - } - else if( p_in[1] < 0.0 && 0.0 == p_in[0] && 0.0 == p_in[2] ) - { - p_out[0] = -p_in[1]; - p_out[2] = -pi / 2.0; - p_out[1] = 0.0; - return; - } + static void CartesiantoSpherical( Vector& p_in, Vector& p_out ) + { + // cas particulier + if( p_in[1] > 0.0 && 0.0 == p_in[0] && 0.0 == p_in[2] ) + { + p_out[0] = p_in[1]; + p_out[2] = pi / 2.0; + p_out[1] = 0.0; + return; + } + else if( p_in[1] < 0.0 && 0.0 == p_in[0] && 0.0 == p_in[2] ) + { + p_out[0] = -p_in[1]; + p_out[2] = -pi / 2.0; + p_out[1] = 0.0; + return; + } - p_out[0] = p_in.Length(); - p_out[2] = asin( p_in[1] / p_out[0] ); - p_out[1] = atan2( p_in[0], p_in[2] ); - } + p_out[0] = p_in.Length(); + p_out[2] = asin( p_in[1] / p_out[0] ); + p_out[1] = atan2( p_in[0], p_in[2] ); + } - static void CubeToSphere( Vector& p_in, Vector& p_out ) - { - float xtemp = p_in[0]; - float ytemp = p_in[1]; - float ztemp = p_in[2]; + static void CubeToSphere( Vector& p_in, Vector& p_out ) + { + float xtemp = p_in[0]; + float ytemp = p_in[1]; + float ztemp = p_in[2]; - p_out[0] = xtemp * sqrt( 1.0 - ytemp * ytemp * 0.5 - ztemp * ztemp * 0.5 + ytemp * ytemp * ztemp * ztemp / 3.0 ); - p_out[1] = ytemp * sqrt( 1.0 - ztemp * ztemp * 0.5 - xtemp * xtemp * 0.5 + xtemp * xtemp * ztemp * ztemp / 3.0 ); - p_out[2] = ztemp * sqrt( 1.0 - xtemp * xtemp * 0.5 - ytemp * ytemp * 0.5 + xtemp * xtemp * ytemp * ytemp / 3.0 ); - } + p_out[0] = xtemp * sqrt( 1.0 - ytemp * ytemp * 0.5 - ztemp * ztemp * 0.5 + ytemp * ytemp * ztemp * ztemp / 3.0 ); + p_out[1] = ytemp * sqrt( 1.0 - ztemp * ztemp * 0.5 - xtemp * xtemp * 0.5 + xtemp * xtemp * ztemp * ztemp / 3.0 ); + p_out[2] = ztemp * sqrt( 1.0 - xtemp * xtemp * 0.5 - ytemp * ytemp * 0.5 + xtemp * xtemp * ytemp * ytemp / 3.0 ); + } - static void VectorPlanetOrientation( int p_orientation, Vector& p_in, Vector& p_out ) - { - Vector res; + static void VectorPlanetOrientation( int p_orientation, Vector& p_in, Vector& p_out ) + { + Vector res; - if( 0 == p_orientation ) // front - { - p_out[0] = p_in[0]; - p_out[1] = p_in[1]; - p_out[2] = p_in[2]; - } - else if( 1 == p_orientation ) // rear - { - p_out[0] = -p_in[0]; - p_out[1] = p_in[1]; - p_out[2] = -p_in[2]; - } - else if( 2 == p_orientation ) // left - { - p_out[0] = -p_in[2]; - p_out[1] = p_in[1]; - p_out[2] = p_in[0]; - } - else if( 3 == p_orientation ) // right - { - p_out[0] = p_in[2]; - p_out[1] = p_in[1]; - p_out[2] = -p_in[0]; - } - else if( 4 == p_orientation ) // top - { - p_out[0] = p_in[0]; - p_out[1] = p_in[2]; - p_out[2] = -p_in[1]; - } - else //if( 5 == p_orientation ) // bottom - { - p_out[0] = p_in[0]; - p_out[1] = -p_in[2]; - p_out[2] = p_in[1]; - } - } -}; -} + if( 0 == p_orientation ) // front + { + p_out[0] = p_in[0]; + p_out[1] = p_in[1]; + p_out[2] = p_in[2]; + } + else if( 1 == p_orientation ) // rear + { + p_out[0] = -p_in[0]; + p_out[1] = p_in[1]; + p_out[2] = -p_in[2]; + } + else if( 2 == p_orientation ) // left + { + p_out[0] = -p_in[2]; + p_out[1] = p_in[1]; + p_out[2] = p_in[0]; + } + else if( 3 == p_orientation ) // right + { + p_out[0] = p_in[2]; + p_out[1] = p_in[1]; + p_out[2] = -p_in[0]; + } + else if( 4 == p_orientation ) // top + { + p_out[0] = p_in[0]; + p_out[1] = p_in[2]; + p_out[2] = -p_in[1]; + } + else //if( 5 == p_orientation ) // bottom + { + p_out[0] = p_in[0]; + p_out[1] = -p_in[2]; + p_out[2] = p_in[1]; + } + } + }; + } } diff --git a/src/quaternion.h b/src/quaternion.h index a062db2b..29a9eda8 100644 --- a/src/quaternion.h +++ b/src/quaternion.h @@ -32,6 +32,7 @@ namespace DrawSpace { namespace Utils { +using namespace DrawSpace::Commons; class Quaternion { protected: @@ -81,14 +82,14 @@ class Quaternion dsreal dot{ forward * forwardVector }; - if (Utils::Maths::Abs(dot - (-1.0)) < 0.000001) + if (Maths::Abs(dot - (-1.0)) < 0.000001) { m_quat[0] = 0.0; m_quat[1] = 1.0; m_quat[2] = 0.0; - m_quat[3] = Utils::Maths::pi; + m_quat[3] = Maths::pi; } - else if (Utils::Maths::Abs(dot - (1.0)) < 0.000001) + else if (Maths::Abs(dot - (1.0)) < 0.000001) { Identity(); }