Skip to content

Commit

Permalink
for issue #80
Browse files Browse the repository at this point in the history
  • Loading branch information
NevilClavain committed Jul 28, 2023
1 parent 4455748 commit 3ae7ad5
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 98 deletions.
6 changes: 5 additions & 1 deletion drawspacecore_project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ ${CMAKE_SOURCE_DIR}/src/ds_types.h
${CMAKE_SOURCE_DIR}/src/exceptions.h
${CMAKE_SOURCE_DIR}/src/primitives.h
${CMAKE_SOURCE_DIR}/src/singleton.h
${CMAKE_SOURCE_DIR}/src/maths.h
)

source_group(maths FILES
${CMAKE_SOURCE_DIR}/src/maths.h
)

source_group(aspect FILES
Expand Down Expand Up @@ -212,7 +217,6 @@ ${CMAKE_SOURCE_DIR}/src/filesystem.cpp
${CMAKE_SOURCE_DIR}/src/filesystem.h
${CMAKE_SOURCE_DIR}/src/jsonparser.cpp
${CMAKE_SOURCE_DIR}/src/jsonparser.h
${CMAKE_SOURCE_DIR}/src/maths.h
${CMAKE_SOURCE_DIR}/src/matrix.cpp
${CMAKE_SOURCE_DIR}/src/matrix.h
${CMAKE_SOURCE_DIR}/src/md5.h
Expand Down
2 changes: 1 addition & 1 deletion lua_extensions/planets_luaext/src/lod_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Commons::Maths::Clamp(0.0, 1.0, (3.0 - m_relative_alt) / 3.0) };
const auto alignment_factor_limit { 0.25 * DrawSpace::Maths::Clamp(0.0, 1.0, (3.0 - m_relative_alt) / 3.0) };
if( m_enable_cdlod )
{
for( long i = 0; i < 6; i++ )
Expand Down
185 changes: 90 additions & 95 deletions src/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,115 +30,110 @@

namespace DrawSpace
{
namespace Commons
using namespace Utils;

namespace Maths
{
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 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 constexpr dsreal pi{ 3.1415927 };

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 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;
}

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 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 ); };
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 SphericaltoCartesian( const Vector& p_in, Vector& p_out )
if( 0 == p_orientation ) // front
{
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] ) );
p_out[0] = p_in[0];
p_out[1] = p_in[1];
p_out[2] = p_in[2];
}

static void CartesiantoSpherical( Vector& p_in, Vector& p_out )
else if( 1 == p_orientation ) // rear
{
// 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[0];
p_out[1] = p_in[1];
p_out[2] = -p_in[2];
}

static void CubeToSphere( Vector& p_in, Vector& p_out )
else if( 2 == p_orientation ) // left
{
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] = -p_in[2];
p_out[1] = p_in[1];
p_out[2] = p_in[0];
}

static void VectorPlanetOrientation( int p_orientation, Vector& p_in, Vector& p_out )
else if( 3 == p_orientation ) // right
{
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];
}
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];
}
};
}
}
}
1 change: 0 additions & 1 deletion src/quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace DrawSpace
{
namespace Utils
{
using namespace DrawSpace::Commons;
class Quaternion
{
protected:
Expand Down

0 comments on commit 3ae7ad5

Please sign in to comment.