wings/src/maths.c

29 lines
364 B
C
Raw Normal View History

2017-04-20 12:44:09 +02:00
#include "maths.h"
2017-04-20 14:37:02 +02:00
#define MAX_TURN 6
2017-04-20 12:44:09 +02:00
float cos(float x)
{
2017-04-20 14:37:02 +02:00
unsigned int a = 8 * MAX_TURN - 6;
unsigned int b = 2 * MAX_TURN * (2 * MAX_TURN - 1); // 2n(2n-1)
2017-04-20 12:44:09 +02:00
float s = 1;
2017-04-20 14:37:02 +02:00
unsigned short i;
2017-04-20 12:44:09 +02:00
2017-04-20 14:37:02 +02:00
x = x * x; // x²
2017-04-20 12:44:09 +02:00
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);
}