gba-x3dtest

view src/sincos.c @ 20:2e903e27e35a

fixed x3d_disable_texture added runtime teture checks in the rasterizer
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 01 Jul 2014 23:23:37 +0300
parents 8e9225853d75
children
line source
1 #include <math.h>
2 #include "fixed.h"
3 #include "sincos.h"
4 #include "logger.h"
6 void sincos_init(void)
7 {
8 int i;
10 logmsg(LOG_ALL, "calculating sin/cos lut...\n");
12 for(i=0; i<SINLUT_SIZE; i++) {
13 float angle = 2.0 * M_PI * ((float)i / (float)SINLUT_SIZE);
14 float val = sin(angle);
15 sinlut[i] = (int16_t)(val * SINLUT_SCALE);
16 }
17 }
19 int16_t sin_int(int16_t norm_angle)
20 {
21 norm_angle %= SINLUT_SIZE;
22 if(norm_angle < 0) {
23 norm_angle += SINLUT_SIZE;
24 }
25 return sinlut[norm_angle];
26 }
28 int16_t cos_int(int16_t norm_angle)
29 {
30 return sin_int(norm_angle + SINLUT_SIZE / 4);
31 }
33 int32_t sin_x16(int32_t radians)
34 {
35 int32_t na = x16div(radians, M_PI_X16 * 2);
36 return (sin_int((na * SINLUT_SIZE) >> 16) << 16) / SINLUT_SCALE;
37 }
39 int32_t cos_x16(int32_t radians)
40 {
41 int32_t na = x16div(radians, M_PI_X16 * 2);
42 return (cos_int((na * SINLUT_SIZE) >> 16) << 16) / SINLUT_SCALE;
43 }