mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 20:12:50 +02:00
remove trig tables, they are unused and alternatives are faster
This commit is contained in:
5550
data/TrigTables.h
5550
data/TrigTables.h
File diff suppressed because it is too large
Load Diff
@@ -1,95 +0,0 @@
|
|||||||
#include <cmath>
|
|
||||||
#include "tpt-math.h"
|
|
||||||
#include "TrigTables.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fast trig functions, using lookup table
|
|
||||||
* Only use for things that require no accuracy, like cyclone tool
|
|
||||||
* Do not use for any core simulation stuff
|
|
||||||
*/
|
|
||||||
|
|
||||||
float orig_atan(float val)
|
|
||||||
{
|
|
||||||
return atan(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace tpt
|
|
||||||
{
|
|
||||||
|
|
||||||
float sin(float angle)
|
|
||||||
{
|
|
||||||
angle *= 81.4873;
|
|
||||||
int i = (int)angle % 512;
|
|
||||||
|
|
||||||
if (i < 0)
|
|
||||||
{
|
|
||||||
i += 512;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sineLookupTable[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float cos(float angle)
|
|
||||||
{
|
|
||||||
angle *= 81.4873;
|
|
||||||
int i = (int)angle % 512;
|
|
||||||
|
|
||||||
if (i < 0)
|
|
||||||
{
|
|
||||||
i += 512;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cosineLookupTable[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
float tan(float angle)
|
|
||||||
{
|
|
||||||
angle *= 81.4873;
|
|
||||||
int i = (int)angle % 512;
|
|
||||||
if (i < 0)
|
|
||||||
{
|
|
||||||
i += 512;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tanLookupTable[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
float atan(float ratio)
|
|
||||||
{
|
|
||||||
if (ratio > 20)
|
|
||||||
{
|
|
||||||
return orig_atan(ratio);
|
|
||||||
}
|
|
||||||
if (ratio < -20)
|
|
||||||
{
|
|
||||||
return orig_atan(ratio);
|
|
||||||
}
|
|
||||||
return atanLookupTable[(int)(ratio * 100) + 2000];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float atan2(float y, float x)
|
|
||||||
{
|
|
||||||
if (x > 0)
|
|
||||||
{
|
|
||||||
return tpt::atan(y / x);
|
|
||||||
}
|
|
||||||
else if (x < 0)
|
|
||||||
{
|
|
||||||
if (y >= 0)
|
|
||||||
{
|
|
||||||
return tpt::atan(y / x) + M_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tpt::atan(y / x) - M_PI;
|
|
||||||
}
|
|
||||||
else if (y > 0)
|
|
||||||
return M_PI_2;
|
|
||||||
else if (y < 0)
|
|
||||||
return M_PI_2;
|
|
||||||
else
|
|
||||||
return 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
#ifndef TPT_MATH_
|
|
||||||
#define TPT_MATH_
|
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.14159265f
|
|
||||||
#endif
|
|
||||||
#ifndef M_PI_2
|
|
||||||
#define M_PI_2 1.57079633f
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace tpt
|
|
||||||
{
|
|
||||||
float sin(float angle);
|
|
||||||
|
|
||||||
float cos(float angle);
|
|
||||||
|
|
||||||
float tan(float angle);
|
|
||||||
|
|
||||||
float asin(float angle);
|
|
||||||
|
|
||||||
float acos(float angle);
|
|
||||||
|
|
||||||
float atan(float ratio);
|
|
||||||
|
|
||||||
float atan2(float y, float x);
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif /* TPT_MATH_ */
|
|
Reference in New Issue
Block a user