Browse Source

base: roll our own constants because it’s always a pain in the ass

to get M_PI from the platform headers and cast it to float.
legacy
Sam Hocevar sam 11 years ago
parent
commit
6faf4ee067
16 changed files with 91 additions and 155 deletions
  1. +1
    -0
      src/Makefile.am
  2. +0
    -13
      src/easymesh/csgbsp.cpp
  3. +9
    -22
      src/easymesh/easymesh.cpp
  4. +0
    -13
      src/gpu/lolfx.cpp
  5. +6
    -8
      src/image/color/cie1931.cpp
  6. +1
    -0
      src/lol/math/all.h
  7. +46
    -0
      src/lol/math/constants.h
  8. +1
    -0
      src/lolcore.vcxproj
  9. +6
    -0
      src/lolcore.vcxproj.filters
  10. +0
    -13
      src/math/geometry.cpp
  11. +1
    -14
      src/math/real.cpp
  12. +6
    -8
      src/math/trig.cpp
  13. +7
    -20
      src/math/vector.cpp
  14. +1
    -10
      test/benchmark/trig.cpp
  15. +2
    -17
      test/btphystest.cpp
  16. +4
    -17
      tutorial/12_voronoi.cpp

+ 1
- 0
src/Makefile.am View File

@@ -38,6 +38,7 @@ liblolcore_headers = \
lol/math/all.h \ lol/math/all.h \
lol/math/functions.h lol/math/vector.h lol/math/half.h lol/math/real.h \ lol/math/functions.h lol/math/vector.h lol/math/half.h lol/math/real.h \
lol/math/remez.h lol/math/geometry.h lol/math/interp.h lol/math/rand.h \ lol/math/remez.h lol/math/geometry.h lol/math/interp.h lol/math/rand.h \
lol/math/constants.h \
\ \
lol/sys/all.h \ lol/sys/all.h \
lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/atomic.h \ lol/sys/init.h lol/sys/file.h lol/sys/thread.h lol/sys/atomic.h \


+ 0
- 13
src/easymesh/csgbsp.cpp View File

@@ -18,19 +18,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include "core.h" #include "core.h"


namespace lol namespace lol


+ 9
- 22
src/easymesh/easymesh.cpp View File

@@ -19,19 +19,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include "core.h" #include "core.h"
#include "easymesh/easymesh-compiler.h" #include "easymesh/easymesh-compiler.h"


@@ -1460,7 +1447,7 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d)
/* Fill in the icosahedron vertices, rotating them so that there /* Fill in the icosahedron vertices, rotating them so that there
* is a vertex at [0 1 0] and [0 -1 0] after normalisation. */ * is a vertex at [0 1 0] and [0 -1 0] after normalisation. */
float phi = 0.5f + 0.5f * sqrt(5.f); float phi = 0.5f + 0.5f * sqrt(5.f);
mat3 mat = mat3::rotate(asin(1.f / sqrt(2.f + phi)) * (180.f / (float)M_PI),
mat3 mat = mat3::rotate(asin(1.f / sqrt(2.f + phi)) * (180.f / F_PI),
vec3(0.f, 0.f, 1.f)); vec3(0.f, 0.f, 1.f));
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
@@ -1508,10 +1495,10 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d)
//keep normalized until the end of the UV calculations //keep normalized until the end of the UV calculations
p[k] = normalize(p[k]); p[k] = normalize(p[k]);


uv[k].x = (lol::atan2(p[k].z, p[k].x) + (float)M_PI) / ((float)M_PI * 2.f);
uv[k].x = (lol::atan2(p[k].z, p[k].x) + F_PI) / (F_PI * 2.f);
if (abs(p[k].y) >= 1.0f) if (abs(p[k].y) >= 1.0f)
uv[k].x = -1.f; uv[k].x = -1.f;
uv[k].y = lol::atan2(p[k].y, dot(p[k], normalize(p[k] * vec3(1.f,0.f,1.f)))) / (float)M_PI + 0.5f;
uv[k].y = lol::atan2(p[k].y, dot(p[k], normalize(p[k] * vec3(1.f,0.f,1.f)))) / F_PI + 0.5f;
if (h) if (h)
{ {
if (uv[k].y > .5f) if (uv[k].y > .5f)
@@ -1602,13 +1589,13 @@ void EasyMesh::AppendTorus(int ndivisions, float d1, float d2)
int j2 = (j + dj) % njdiv; int j2 = (j + dj) % njdiv;


//Location on the donut //Location on the donut
float x = 0.5f * (r2 - r1) * (float)lol::cos(2.0 * M_PI * i2 / nidiv) + 0.5f * (r1 + r2);
float y = 0.5f * (r2 - r1) * (float)lol::sin(2.0 * M_PI * i2 / nidiv);
float x = 0.5f * (r2 - r1) * (float)lol::cos(2.f * F_PI * i2 / nidiv) + 0.5f * (r1 + r2);
float y = 0.5f * (r2 - r1) * (float)lol::sin(2.f * F_PI * i2 / nidiv);
float z = 0.0f; float z = 0.0f;


//Center circle //Center circle
float ca = (float)lol::cos(2.0 * M_PI * j2 / njdiv);
float sa = (float)lol::sin(2.0 * M_PI * j2 / njdiv);
float ca = (float)lol::cos(2.f * F_PI * j2 / njdiv);
float sa = (float)lol::sin(2.f * F_PI * j2 / njdiv);


//Actual location //Actual location
float x2 = x * ca - z * sa; float x2 = x * ca - z * sa;
@@ -2382,8 +2369,8 @@ void EasyMesh::SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per


//Calculate new master vertex //Calculate new master vertex
float n = (float)connected_vert.Count(); float n = (float)connected_vert.Count();
//b(n) = 5/4 - pow(3 + 2 * cos(2 * M_PI / n), 2) / 32
float beta = 3.f + 2.f * cos(2.f * (float)M_PI / n);
//b(n) = 5/4 - pow(3 + 2 * cos(2.f * F_PI / n), 2) / 32
float beta = 3.f + 2.f * cos(2.f * F_PI / n);
beta = 5.f / 4.f - beta * beta / 32.f; beta = 5.f / 4.f - beta * beta / 32.f;
//a(n) = n * (1 - b(n)) / b(n) //a(n) = n * (1 - b(n)) / b(n)
float alpha = (n * (1 - beta)) / beta; float alpha = (n * (1 - beta)) / beta;


+ 0
- 13
src/gpu/lolfx.cpp View File

@@ -17,19 +17,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include "core.h" #include "core.h"
#include "gpu/lolfx-compiler.h" #include "gpu/lolfx-compiler.h"




+ 6
- 8
src/image/color/cie1931.cpp View File

@@ -26,8 +26,6 @@ namespace lol


float Color::DistanceCIEDE2000(vec3 lab1, vec3 lab2) float Color::DistanceCIEDE2000(vec3 lab1, vec3 lab2)
{ {
float const pi = 3.141592653589793f;

float C1 = length(lab1.yz); float C1 = length(lab1.yz);
float C2 = length(lab2.yz); float C2 = length(lab2.yz);
float C_ = 0.5f * (C1 + C2); float C_ = 0.5f * (C1 + C2);
@@ -48,20 +46,20 @@ float Color::DistanceCIEDE2000(vec3 lab1, vec3 lab2)


float hp1 = atan2(lab1.z, ap1); float hp1 = atan2(lab1.z, ap1);
float hp2 = atan2(lab2.z, ap2); float hp2 = atan2(lab2.z, ap2);
float dhp = fmod(hp2 - hp1 + 3.f * pi, 2.f * pi) - pi; /* -pi .. pi */
float dhp = fmod(hp2 - hp1 + 3.f * F_PI, 2.f * F_PI) - F_PI; /* -pi .. pi */
float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(0.5f * dhp); float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(0.5f * dhp);
float Hp_ = Cp1 * Cp2 ? fmod(hp1 + 0.5f * dhp + 2.f * pi, 2.f * pi) : hp1 + hp2; /* 0 .. 2pi */
float Hp_ = Cp1 * Cp2 ? fmod(hp1 + 0.5f * dhp + 2.f * F_PI, 2.f * F_PI) : hp1 + hp2; /* 0 .. 2pi */


float T = 1.f - 0.17f * cos(Hp_ - pi / 6.f)
float T = 1.f - 0.17f * cos(Hp_ - F_PI / 6.f)
+ 0.24f * cos(2.f * Hp_) + 0.24f * cos(2.f * Hp_)
+ 0.32f * cos(3.f * Hp_ + pi / 30.f)
- 0.20f * cos(4.f * Hp_ - 0.35f * pi);
+ 0.32f * cos(3.f * Hp_ + F_PI / 30.f)
- 0.20f * cos(4.f * Hp_ - 0.35f * F_PI);
float SL = 1.f + 0.015f * (L_ - 50) * (L_ - 50) float SL = 1.f + 0.015f * (L_ - 50) * (L_ - 50)
/ sqrt(20.f + (L_ - 50) * (L_ - 50)); / sqrt(20.f + (L_ - 50) * (L_ - 50));
float SC = 1.f + 0.045f * Cp_; float SC = 1.f + 0.045f * Cp_;
float SH = 1.f + 0.015f * Cp_ * T; float SH = 1.f + 0.015f * Cp_ * T;
float RT = -2.f * sqrt(pow(Cp_, 7.f) / (pow(Cp_, 7.f) + pow(25.f, 7.f))) float RT = -2.f * sqrt(pow(Cp_, 7.f) / (pow(Cp_, 7.f) + pow(25.f, 7.f)))
* sin(pi / 3.f * exp(-pow((Hp_ * 180.f / pi - 275.f) / 25.f, 2.f)));
* sin(F_PI / 3.f * exp(-pow((Hp_ * 180.f / F_PI - 275.f) / 25.f, 2.f)));


dLp /= SL; dLp /= SL;
dCp /= SC; dCp /= SC;


+ 1
- 0
src/lol/math/all.h View File

@@ -11,6 +11,7 @@
#if !defined __LOL_MATH_ALL_H__ #if !defined __LOL_MATH_ALL_H__
#define __LOL_MATH_ALL_H__ #define __LOL_MATH_ALL_H__


#include <lol/math/constants.h>
#include <lol/math/functions.h> #include <lol/math/functions.h>
#include <lol/math/half.h> #include <lol/math/half.h>
#include <lol/math/real.h> #include <lol/math/real.h>


+ 46
- 0
src/lol/math/constants.h View File

@@ -0,0 +1,46 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

//
// Various maths constants
// -----------------------
//

#if !defined __LOL_MATH_CONSTANTS_H__
#define __LOL_MATH_CONSTANTS_H__

namespace lol
{

#define LOL_MATH_CONSTANT(name, value) \
static ldouble const LD_##name = value; \
static double const D_##name = (double)LD_##name; \
static float const F_##name = (float)LD_##name;

/* These values are truncated, not rounded, because I don’t care. */

LOL_MATH_CONSTANT(PI, 3.14159265358979323846264338327950288419716939937L)
LOL_MATH_CONSTANT(PI_2, 1.57079632679489661923132169163975144209858469968L)
LOL_MATH_CONSTANT(PI_3, 1.04719755119659774615421446109316762806572313312L)
LOL_MATH_CONSTANT(PI_4, 0.78539816339744830961566084581987572104929234984L)

LOL_MATH_CONSTANT(1_PI, 0.31830988618379067153776752674502872406891929148L)
LOL_MATH_CONSTANT(2_PI, 0.63661977236758134307553505349005744813783858296L)

LOL_MATH_CONSTANT(SQRT_2, 1.41421356237309504880168872420969807856967187537L)
LOL_MATH_CONSTANT(SQRT_3, 1.73205080756887729352744634150587236694280525381L)
LOL_MATH_CONSTANT(SQRT_1_2, 0.70710678118654752440084436210484903928483593768L)

#undef LOL_MATH_CONSTANT

} /* namespace lol */

#endif // __LOL_MATH_CONSTANTS_H__


+ 1
- 0
src/lolcore.vcxproj View File

@@ -216,6 +216,7 @@
<ClInclude Include="lol\image\color.h" /> <ClInclude Include="lol\image\color.h" />
<ClInclude Include="lol\image\image.h" /> <ClInclude Include="lol\image\image.h" />
<ClInclude Include="lol\math\all.h" /> <ClInclude Include="lol\math\all.h" />
<ClInclude Include="lol\math\constants.h" />
<ClInclude Include="lol\math\functions.h" /> <ClInclude Include="lol\math\functions.h" />
<ClInclude Include="lol\math\geometry.h" /> <ClInclude Include="lol\math\geometry.h" />
<ClInclude Include="lol\math\half.h" /> <ClInclude Include="lol\math\half.h" />


+ 6
- 0
src/lolcore.vcxproj.filters View File

@@ -530,6 +530,12 @@
<ClInclude Include="lol\sys\atomic.h"> <ClInclude Include="lol\sys\atomic.h">
<Filter>lol\sys</Filter> <Filter>lol\sys</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="lol\math\constants.h">
<Filter>lol\math</Filter>
</ClInclude>
<ClInclude Include="lol\math\functions.h">
<Filter>lol\math</Filter>
</ClInclude>
<ClInclude Include="lol\math\functions.h"> <ClInclude Include="lol\math\functions.h">
<Filter>lol\math</Filter> <Filter>lol\math</Filter>
</ClInclude> </ClInclude>


+ 0
- 13
src/math/geometry.cpp View File

@@ -13,19 +13,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include <cstdlib> /* free() */ #include <cstdlib> /* free() */
#include <cstring> /* strdup() */ #include <cstring> /* strdup() */




+ 1
- 14
src/math/real.cpp View File

@@ -12,19 +12,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include <new> #include <new>
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
@@ -796,7 +783,7 @@ template<> real gamma(real const &x)
* precision values in order to attain the desired accuracy. It might * precision values in order to attain the desired accuracy. It might
* also be useful to sort the ck values by decreasing absolute value * also be useful to sort the ck values by decreasing absolute value
* and do the addition in this order. */ * and do the addition in this order. */
int a = ceilf(logf(2) / logf(2 * M_PI) * real::BIGITS * real::BIGIT_BITS);
int a = ceilf(logf(2) / logf(2 * F_PI) * real::BIGITS * real::BIGIT_BITS);


real ret = sqrt(real::R_PI() * 2); real ret = sqrt(real::R_PI() * 2);
real fact_k_1 = real::R_1(); real fact_k_1 = real::R_1();


+ 6
- 8
src/math/trig.cpp View File

@@ -23,8 +23,6 @@ using namespace std;
namespace lol namespace lol
{ {


static const double PI = 3.14159265358979323846264;
static const double NEG_PI = -3.14159265358979323846264;
static const double PI_2 = 1.57079632679489661923132; static const double PI_2 = 1.57079632679489661923132;
static const double PI_4 = 0.785398163397448309615661; static const double PI_4 = 0.785398163397448309615661;
static const double INV_PI = 0.318309886183790671537768; static const double INV_PI = 0.318309886183790671537768;
@@ -255,7 +253,7 @@ double lol_sin(double x)
* cycles required. If odd, we'll need to change the sign of the * cycles required. If odd, we'll need to change the sign of the
* result. */ * result. */
#if defined __CELLOS_LV2__ #if defined __CELLOS_LV2__
double sign = lol_fsel(x, PI, NEG_PI);
double sign = lol_fsel(x, D_PI, -D_PI);
double num_cycles = lol_round(absx); double num_cycles = lol_round(absx);
double is_even = lol_trunc(num_cycles * HALF) - (num_cycles * HALF); double is_even = lol_trunc(num_cycles * HALF) - (num_cycles * HALF);
sign = lol_fsel(is_even, sign, -sign); sign = lol_fsel(is_even, sign, -sign);
@@ -291,7 +289,7 @@ double lol_sin(double x)
#endif #endif


#if !defined __CELLOS_LV2__ #if !defined __CELLOS_LV2__
sign *= (x >= 0.0) ? PI : NEG_PI;
sign *= (x >= 0.0) ? D_PI : -D_PI;
#endif #endif


/* Compute a Tailor series for sin() and combine sign information. */ /* Compute a Tailor series for sin() and combine sign information. */
@@ -352,7 +350,7 @@ double lol_cos(double x)
double sub2 = (SC[4] * x4 + SC[2]) * x4 + SC[0]; double sub2 = (SC[4] * x4 + SC[2]) * x4 + SC[0];
double taylor = sub2 * x2 + sub1; double taylor = sub2 * x2 + sub1;


return x1 * taylor * sign * PI;
return x1 * taylor * sign * D_PI;
} }
#endif #endif


@@ -401,7 +399,7 @@ void lol_sincos(double x, double *sinx, double *cosx)
double num_cycles = lol_round(absx); double num_cycles = lol_round(absx);
double is_even = lol_trunc(num_cycles * HALF) - (num_cycles * HALF); double is_even = lol_trunc(num_cycles * HALF) - (num_cycles * HALF);


double sin_sign = lol_fsel(x, PI, NEG_PI);
double sin_sign = lol_fsel(x, D_PI, -D_PI);
sin_sign = lol_fsel(is_even, sin_sign, -sin_sign); sin_sign = lol_fsel(is_even, sin_sign, -sin_sign);
double cos_sign = lol_fsel(is_even, ONE, NEG_ONE); double cos_sign = lol_fsel(is_even, ONE, NEG_ONE);
#else #else
@@ -436,14 +434,14 @@ void lol_sincos(double x, double *sinx, double *cosx)
double subc1 = ((SC[5] * x4 + SC[3]) * x4 + SC[1]) * x4 + ONE; double subc1 = ((SC[5] * x4 + SC[3]) * x4 + SC[1]) * x4 + ONE;
double subc2 = (SC[4] * x4 + SC[2]) * x4 + SC[0]; double subc2 = (SC[4] * x4 + SC[2]) * x4 + SC[0];
double taylorc = subc2 * x2 + subc1; double taylorc = subc2 * x2 + subc1;
*cosx = x1 * taylorc * cos_sign * PI;
*cosx = x1 * taylorc * cos_sign * D_PI;


return; return;
} }
#endif #endif


#if !defined __CELLOS_LV2__ #if !defined __CELLOS_LV2__
sin_sign *= (x >= 0.0) ? PI : NEG_PI;
sin_sign *= (x >= 0.0) ? D_PI : -D_PI;
#endif #endif


double x2 = absx * absx; double x2 = absx * absx;


+ 7
- 20
src/math/vector.cpp View File

@@ -12,19 +12,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include <cstdlib> /* free() */ #include <cstdlib> /* free() */
#include <cstring> /* strdup() */ #include <cstring> /* strdup() */


@@ -348,7 +335,7 @@ template<> mat4 mat4::translate(vec3 v)


template<> mat2 mat2::rotate(float degrees) template<> mat2 mat2::rotate(float degrees)
{ {
degrees *= (M_PI / 180.0f);
degrees *= (F_PI / 180.0f);


float st = sin(degrees); float st = sin(degrees);
float ct = cos(degrees); float ct = cos(degrees);
@@ -366,7 +353,7 @@ template<> mat2 mat2::rotate(float degrees)


template<> mat3 mat3::rotate(float degrees, float x, float y, float z) template<> mat3 mat3::rotate(float degrees, float x, float y, float z)
{ {
degrees *= (M_PI / 180.0f);
degrees *= (F_PI / 180.0f);


float st = sin(degrees); float st = sin(degrees);
float ct = cos(degrees); float ct = cos(degrees);
@@ -485,7 +472,7 @@ template<> quat::Quat(mat4 const &m)


template<> quat quat::rotate(float degrees, vec3 const &v) template<> quat quat::rotate(float degrees, vec3 const &v)
{ {
degrees *= (M_PI / 360.0f);
degrees *= (F_PI / 360.0f);


vec3 tmp = normalize(v) * sin(degrees); vec3 tmp = normalize(v) * sin(degrees);


@@ -531,14 +518,14 @@ template<> vec3 vec3::toeuler(quat const &q)
atan2(2.f * (q.w * q.z + q.y * q.x), atan2(2.f * (q.w * q.z + q.y * q.x),
1.f - 2.f * (q.z * q.z + q.y * q.y))); 1.f - 2.f * (q.z * q.z + q.y * q.y)));


return (float)(180.0f / M_PI / n) * ret;
return (180.0f / F_PI / n) * ret;
} }


static inline mat3 mat3_fromeuler_generic(vec3 const &v, int i, int j, int k) static inline mat3 mat3_fromeuler_generic(vec3 const &v, int i, int j, int k)
{ {
mat3 ret; mat3 ret;


vec3 radians = (float)(M_PI / 180.0f) * v;
vec3 radians = (F_PI / 180.0f) * v;
float s0 = sin(radians[0]), c0 = cos(radians[0]); float s0 = sin(radians[0]), c0 = cos(radians[0]);
float s1 = sin(radians[1]), c1 = cos(radians[1]); float s1 = sin(radians[1]), c1 = cos(radians[1]);
float s2 = sin(radians[2]), c2 = cos(radians[2]); float s2 = sin(radians[2]), c2 = cos(radians[2]);
@@ -604,7 +591,7 @@ static inline mat3 mat3_fromeuler_generic(vec3 const &v, int i, int j, int k)


static inline quat quat_fromeuler_generic(vec3 const &v, int i, int j, int k) static inline quat quat_fromeuler_generic(vec3 const &v, int i, int j, int k)
{ {
vec3 half_angles = (float)(M_PI / 360.0f) * v;
vec3 half_angles = (F_PI / 360.0f) * v;
float s0 = sin(half_angles[0]), c0 = cos(half_angles[0]); float s0 = sin(half_angles[0]), c0 = cos(half_angles[0]);
float s1 = sin(half_angles[1]), c1 = cos(half_angles[1]); float s1 = sin(half_angles[1]), c1 = cos(half_angles[1]);
float s2 = sin(half_angles[2]), c2 = cos(half_angles[2]); float s2 = sin(half_angles[2]), c2 = cos(half_angles[2]);
@@ -754,7 +741,7 @@ template<> mat4 mat4::frustum(float left, float right, float bottom,
template<> mat4 mat4::perspective(float fov_y, float width, template<> mat4 mat4::perspective(float fov_y, float width,
float height, float near, float far) float height, float near, float far)
{ {
fov_y *= (M_PI / 180.0f);
fov_y *= (F_PI / 180.0f);


float t2 = tanf(fov_y * 0.5f); float t2 = tanf(fov_y * 0.5f);
float t1 = t2 * width / height; float t1 = t2 * width / height;


+ 1
- 10
test/benchmark/trig.cpp View File

@@ -12,15 +12,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif

#include <cstdio> #include <cstdio>


#if defined HAVE_FASTMATH_H #if defined HAVE_FASTMATH_H
@@ -55,7 +46,7 @@ void bench_trig(int mode)
break; break;
case 2: case 2:
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
pf[i] = rand(-M_PI, M_PI);
pf[i] = rand(-F_PI, F_PI);
break; break;
case 3: case 3:
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)


+ 2
- 17
test/btphystest.cpp View File

@@ -9,21 +9,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#else
# include <cmath>
#endif

#include "core.h" #include "core.h"
#include "loldebug.h" #include "loldebug.h"


@@ -277,8 +262,8 @@ void BtPhysTest::TickGame(float seconds)
Ticker::Shutdown(); Ticker::Shutdown();


m_loop_value += seconds; m_loop_value += seconds;
if (m_loop_value > M_PI * 2.0f)
m_loop_value -= M_PI * 2.0f;
if (m_loop_value > F_PI * 2.0f)
m_loop_value -= F_PI * 2.0f;


vec3 GroundBarycenter = vec3(.0f); vec3 GroundBarycenter = vec3(.0f);
vec3 PhysObjBarycenter = vec3(.0f); vec3 PhysObjBarycenter = vec3(.0f);


+ 4
- 17
tutorial/12_voronoi.cpp View File

@@ -12,19 +12,6 @@
# include "config.h" # include "config.h"
#endif #endif


#if defined _XBOX
# define _USE_MATH_DEFINES /* for M_PI */
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include "core.h" #include "core.h"
#include "loldebug.h" #include "loldebug.h"


@@ -188,10 +175,10 @@ public:
int maxi = 6; int maxi = 6;
for (int i = 0; i < maxi; ++i) for (int i = 0; i < maxi; ++i)
{ {
voronoi_points.Push(vec3(256.f) + 196.f * vec3((float)lol::cos(m_time + (double)i * 2.0 * M_PI / (double)maxi), (float)lol::sin(m_time + (double)i * 2.0 * M_PI / (double)maxi), .0f), vec2(.0f));
voronoi_points.Push(vec3(256.f) + 128.f * vec3((float)lol::cos(-m_time + (double)i * 2.0 * M_PI / (double)maxi), (float)lol::sin(-m_time + (double)i * 2.0 * M_PI / (double)maxi), .0f), vec2(.0f));
voronoi_points.Push(vec3(256.f) + 64.f * vec3((float)lol::cos(m_time + (double)i * 2.0 * M_PI / (double)maxi), (float)lol::sin(m_time + (double)i * 2.0 * M_PI / (double)maxi), .0f), vec2(.0f));
voronoi_points.Push(vec3(256.f) + 32.f * vec3((float)lol::cos(-m_time + (double)i * 2.0 * M_PI / (double)maxi), (float)lol::sin(-m_time + (double)i * 2.0 * M_PI / (double)maxi), .0f), vec2(.0f));
voronoi_points.Push(vec3(256.f) + 196.f * vec3(lol::cos(m_time + i * 2.f * F_PI / maxi), lol::sin(m_time + i * 2.f * F_PI / maxi), .0f), vec2(.0f));
voronoi_points.Push(vec3(256.f) + 128.f * vec3(lol::cos(-m_time + i * 2.f * F_PI / maxi), lol::sin(-m_time + i * 2.f * F_PI / maxi), .0f), vec2(.0f));
voronoi_points.Push(vec3(256.f) + 64.f * vec3(lol::cos(m_time + i * 2.f * F_PI / maxi), lol::sin(m_time + i * 2.f * F_PI / maxi), .0f), vec2(.0f));
voronoi_points.Push(vec3(256.f) + 32.f * vec3(lol::cos(-m_time + i * 2.f * F_PI / maxi), lol::sin(-m_time + i * 2.f * F_PI / maxi), .0f), vec2(.0f));
} }
voronoi_points.Push(vec3(256.f), vec2(.0f)); voronoi_points.Push(vec3(256.f), vec2(.0f));
} }


Loading…
Cancel
Save