Skip to content
Permalink
Browse files

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.
  • Loading branch information...
UnknownShadow200 committed Oct 7, 2019
1 parent 0053d22 commit b62a78765dbc5b6cb1342c3660982bc5b6387b84
Showing with 2 additions and 14 deletions.
  1. +0 −12 src/ExtMath.c
  2. +0 −1 src/ExtMath.h
  3. +2 −1 src/Vectors.c
@@ -72,18 +72,6 @@ bool Math_IsPowOf2(int value) {
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) {
/* x = 2^exp * mantissa */
/* so log(x) = log(2^exp) + log(mantissa) */
@@ -31,7 +31,6 @@ double Math_Log(double x);
/* Computes e^x. Can also be used to approximate y^x. */
/* e.g. for 3^x, use: Math_Exp(log(3)*x) */
double Math_Exp(double x);
double Math_FastTan(double x);

int Math_Floor(float value);
int Math_Ceil(float value);
@@ -183,8 +183,9 @@ void Matrix_OrthographicOffCenter(struct Matrix* result, float left, float right
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) {
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);
}

0 comments on commit b62a787

Please sign in to comment.
You can’t perform that action at this time.