wings/src/maths.c

48 lines
609 B
C
Executable File

#include "maths.h"
float fcos(unsigned char x)
{
char n = 1;
float cos[4] = {1.0, 0.707106, 0.0, -0.707106};
while(x >= 4)
{
x -= 4;
n = -n;
}
return (n*cos[x]);
}
float fsin(unsigned char x)
{
return fcos(x - 2);
}
#define MAX_TURN 6
float cos(float x)
{
unsigned int a = 8 * MAX_TURN - 6;
unsigned int b = 2 * MAX_TURN * (2 * MAX_TURN - 1); // 2n(2n-1)
float s = 1;
unsigned short i;
x = x * x; // x²
for(i = 0; i < MAX_TURN; i++)
{
s = 1 - x * s / b;
b -= a;
a -= 8;
}
return s;
}
float sin(float x)
{
return cos(x - pi_2);
}