Remove Math_FastTan

Despite the name, it's not even fast at all. And it's only used from one place where replacing with a simple sin(x) / cos(x) will do anyways.
This commit is contained in:
UnknownShadow200 2019-10-07 18:07:57 +11:00
parent 0053d2245d
commit b62a78765d
3 changed files with 2 additions and 14 deletions

View File

@ -72,18 +72,6 @@ bool Math_IsPowOf2(int value) {
return value != 0 && (value & (value - 1)) == 0; return value != 0 && (value & (value - 1)) == 0;
} }
/* Not the most precise Tan(x), but within 10^-15 of answer, so good enough for here */
double Math_FastTan(double angle) {
double cosA = Math_Cos(angle), sinA = Math_Sin(angle);
int sign;
if (cosA < -0.00000001 || cosA > 0.00000001) return sinA / cosA;
/* tan line is parallel to y axis, infinite gradient */
sign = Math_Sign(sinA);
if (cosA) sign *= Math_Sign(cosA);
return sign * MATH_POS_INF;
}
double Math_FastLog(double x) { double Math_FastLog(double x) {
/* x = 2^exp * mantissa */ /* x = 2^exp * mantissa */
/* so log(x) = log(2^exp) + log(mantissa) */ /* so log(x) = log(2^exp) + log(mantissa) */

View File

@ -31,7 +31,6 @@ double Math_Log(double x);
/* Computes e^x. Can also be used to approximate y^x. */ /* Computes e^x. Can also be used to approximate y^x. */
/* e.g. for 3^x, use: Math_Exp(log(3)*x) */ /* e.g. for 3^x, use: Math_Exp(log(3)*x) */
double Math_Exp(double x); double Math_Exp(double x);
double Math_FastTan(double x);
int Math_Floor(float value); int Math_Floor(float value);
int Math_Ceil(float value); int Math_Ceil(float value);

View File

@ -183,8 +183,9 @@ void Matrix_OrthographicOffCenter(struct Matrix* result, float left, float right
result->Row3.Z = -(zFar + zNear) / (zFar - zNear); result->Row3.Z = -(zFar + zNear) / (zFar - zNear);
} }
static double Tan_Simple(double x) { return Math_Sin(x) / Math_Cos(x); }
void Matrix_PerspectiveFieldOfView(struct Matrix* result, float fovy, float aspect, float zNear, float zFar) { void Matrix_PerspectiveFieldOfView(struct Matrix* result, float fovy, float aspect, float zNear, float zFar) {
float c = zNear * (float)Math_FastTan(0.5f * fovy); float c = zNear * (float)Tan_Simple(0.5f * fovy);
Matrix_PerspectiveOffCenter(result, -c * aspect, c * aspect, -c, c, zNear, zFar); Matrix_PerspectiveOffCenter(result, -c * aspect, c * aspect, -c, c, zNear, zFar);
} }