medfall

A super great game engine
Log | Files | Refs

commit 74e01d98b2d4a59d7f2921fbca99e3002f20b2f9
parent 3f0d18197081a08935b98649e7d3893b89d5e740
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat, 21 Oct 2017 10:22:48 +0300

Define PI and TAU

Diffstat:
audio.cc | 2+-
immediate.cc | 8++++----
intrinsics.h | 3+++
linear_algebra.h | 4++--
pp.cc | 2+-
scripts/gen_makefile.lua | 4++--
skybox.cc | 6+++---
7 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/audio.cc b/audio.cc @@ -20,7 +20,7 @@ static SoundData make_sin_wave( u32 sample_rate, u32 frequency ) { for( u32 i = 0; i < num_samples; i++ ) { const float t = ( float ) i / num_samples; - sound.samples[ i ] = S16_MAX * sinf( t * 2.0f * M_PI ); + sound.samples[ i ] = S16_MAX * sinf( t * 2.0f * PI ); } return sound; diff --git a/immediate.cc b/immediate.cc @@ -41,8 +41,8 @@ void immediate_sphere( ImmediateContext * ctx, v3 centre, float radius, v4 colour, u32 subdivisions ) { - const float azimuth_max = 2.0f * float( M_PI ); - const float pitch_max = float( M_PI ); + const float azimuth_max = TAU; + const float pitch_max = PI; const float dsa = sinf( 0.5f * azimuth_max / ( subdivisions - 1 ) ); const float dca = cosf( 0.5f * azimuth_max / ( subdivisions - 1 ) ); @@ -162,8 +162,8 @@ void immediate_arrow( // TODO: do the fast sin/cos thing // TODO: make a helper function to do it that fills in an array of floats for( size_t i = 0; i < ARRAY_COUNT( cone ); i++ ) { - float s = sinf( float( i ) / float( ARRAY_COUNT( cone ) ) * 2.0f * float( M_PI ) ); - float c = cosf( float( i ) / float( ARRAY_COUNT( cone ) ) * 2.0f * float( M_PI ) ); + float s = sinf( float( i ) / float( ARRAY_COUNT( cone ) ) * TAU ); + float c = cosf( float( i ) / float( ARRAY_COUNT( cone ) ) * TAU ); cone[ i ] = v3( 0.2f * c, 0.2f * s, 0.6f ); } diff --git a/intrinsics.h b/intrinsics.h @@ -36,6 +36,9 @@ typedef uintptr_t uptr; #define U32_MAX u32( UINT32_MAX ) #define U64_MAX u64( UINT64_MAX ) +#define PI 3.14159265359f +#define TAU 6.28318530717958647692f + #define STRINGIFY_HELPER( x ) #x #define STRINGIFY( x ) STRINGIFY_HELPER( x ) diff --git a/linear_algebra.h b/linear_algebra.h @@ -280,11 +280,11 @@ struct quat { */ forceinline float deg_to_rad( float x ) { - return x * float( M_PI ) / 180.0f; + return x * PI / 180.0f; } forceinline float rad_to_deg( float x ) { - return x * 180.0f / float( M_PI ); + return x * 180.0f / PI; } forceinline v3 deg_to_rad( const v3 & v ) { diff --git a/pp.cc b/pp.cc @@ -375,7 +375,7 @@ int main( int argc, char ** argv ) { for( size_t y = 0; y < tile.h; y++ ) { for( size_t x = 0; x < tile.w; x++ ) { - float theta01 = atanf( tile( x, y ) ) * 2.0f / float( M_PI ); + float theta01 = atanf( tile( x, y ) ) * 2.0f / PI; u8 q = checked_cast< u8 >( quantize01( theta01, 8 ) ); png( x, y ) = q; } diff --git a/scripts/gen_makefile.lua b/scripts/gen_makefile.lua @@ -14,7 +14,7 @@ local configs = { toolchain = "msvc", - cxxflags = "/I . /c /Oi /Gm- /GR- /EHa- /EHsc /nologo /DNOMINMAX /D_USE_MATH_DEFINES /DWIN32_LEAN_AND_MEAN", + cxxflags = "/I . /c /Oi /Gm- /GR- /EHa- /EHsc /nologo /DNOMINMAX /DWIN32_LEAN_AND_MEAN", ldflags = "user32.lib shell32.lib advapi32.lib dbghelp.lib /nologo", warnings = "/W4 /wd4100 /wd4201 /wd4189 /wd4351 /wd4505 /wd4127 /wd4530 /wd4702 /D_CRT_SECURE_NO_WARNINGS", }, @@ -38,7 +38,7 @@ local configs = { toolchain = "gcc", cxx = "g++", - cxxflags = "-I . -c -x c++ -std=c++11 -msse2 -ffast-math -fno-exceptions -fno-rtti -fno-strict-aliasing -fno-strict-overflow -fdiagnostics-color -D_USE_MATH_DEFINES", + cxxflags = "-I . -c -x c++ -std=c++11 -msse2 -ffast-math -fno-exceptions -fno-rtti -fno-strict-aliasing -fno-strict-overflow -fdiagnostics-color", ldflags = "-lm -lpthread -ldl", warnings = "-Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wshadow -Wcast-align -Wstrict-overflow -Wvla", -- -Wconversion }, diff --git a/skybox.cc b/skybox.cc @@ -23,7 +23,7 @@ static double evaluate_spline( const double * spline, size_t stride, double valu static double evaluate( const double * dataset, size_t stride, float turbidity, float albedo, float sun_theta ) { // splines are functions of elevation^1/3 - double elevationK = pow( max( 0.0f, 1 - sun_theta / ( float( M_PI ) / 2 ) ), 1 / 3.0 ); + double elevationK = pow( max( 0.0f, 1.0f - sun_theta / ( PI / 2.0f ) ), 1 / 3.0 ); // table has values for turbidity 1..10 int turbidity0 = clamp( int( turbidity ), 1, 10 ); @@ -53,7 +53,7 @@ static v3 perez_ext(float cos_theta, float gamma, float cos_gamma, v3 A, v3 B, v } static Hosek compute_hosek( float sun_theta, float turbidity, float normalized_sun_y ) { - sun_theta = clamp( sun_theta, 0.0f, float( M_PI ) / 2 ); + sun_theta = clamp( sun_theta, 0.0f, PI / 2.0f ); v3 A, B, C, D, E, F, G, H, I; v3 Z; @@ -129,7 +129,7 @@ void skybox_render( const Skybox * skybox, const m4 & Vsky, const m4 & P, float // the model only works in [0, pi / 2] and elevation == 0 when the sun // is directly above - float hosek_elevation = fabsf( ( M_PI / 2.0f ) - sun_angle ); + float hosek_elevation = fabsf( ( PI / 2.0f ) - sun_angle ); Hosek hosek = compute_hosek( hosek_elevation, turbidity, normalized_sun_y ); RenderState render_state;