-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmathHelp.c
59 lines (42 loc) · 1.14 KB
/
mathHelp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef MATH_HELP_GUARD_H
#include "mathHelp.h"
#include <time.h>
#endif
#define MEMOIZATION_TABLE 360
static GLdouble sinTable[MEMOIZATION_TABLE];
static GLdouble cosTable[MEMOIZATION_TABLE];
static char wasInitialized;
/**
* Inicia o processo de memoization para os valores de seno e cosseno
*/
static void initializeMemoization(void){
wasInitialized = 1;
time_t t;
srand((unsigned int) time(&t));
size_t i;
GLdouble division = M_PI / 180.;
for(i = 0; i < MEMOIZATION_TABLE; i++){
sinTable[i] = sin(division * (GLdouble) i);
cosTable[i] = cos(division * (GLdouble) i);
}
}
/**
* Consulta o valor do seno para o ângulo especificado.
* @param degrees Ângulo em graus a ser consultado.
* @return Valor do seno.
*/
GLdouble consultSin(GLuint degrees){
if(!wasInitialized)
initializeMemoization();
return sinTable[degrees % MEMOIZATION_TABLE];
}
/**
* Consulta o valor do cosseno para o ângulo especificado.
* @param degrees Ângulo em graus a ser consultado.
* @return Valor do cosseno.
*/
GLdouble consultCos(GLuint degrees){
if(!wasInitialized)
initializeMemoization();
return cosTable[degrees % MEMOIZATION_TABLE];
}