gba-x3dtest
annotate 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 |
rev | line source |
---|---|
nuclear@3 | 1 #include <math.h> |
nuclear@4 | 2 #include "fixed.h" |
nuclear@3 | 3 #include "sincos.h" |
nuclear@3 | 4 #include "logger.h" |
nuclear@3 | 5 |
nuclear@3 | 6 void sincos_init(void) |
nuclear@3 | 7 { |
nuclear@3 | 8 int i; |
nuclear@3 | 9 |
nuclear@3 | 10 logmsg(LOG_ALL, "calculating sin/cos lut...\n"); |
nuclear@3 | 11 |
nuclear@3 | 12 for(i=0; i<SINLUT_SIZE; i++) { |
nuclear@3 | 13 float angle = 2.0 * M_PI * ((float)i / (float)SINLUT_SIZE); |
nuclear@3 | 14 float val = sin(angle); |
nuclear@3 | 15 sinlut[i] = (int16_t)(val * SINLUT_SCALE); |
nuclear@3 | 16 } |
nuclear@3 | 17 } |
nuclear@3 | 18 |
nuclear@3 | 19 int16_t sin_int(int16_t norm_angle) |
nuclear@3 | 20 { |
nuclear@3 | 21 norm_angle %= SINLUT_SIZE; |
nuclear@3 | 22 if(norm_angle < 0) { |
nuclear@3 | 23 norm_angle += SINLUT_SIZE; |
nuclear@3 | 24 } |
nuclear@3 | 25 return sinlut[norm_angle]; |
nuclear@3 | 26 } |
nuclear@3 | 27 |
nuclear@3 | 28 int16_t cos_int(int16_t norm_angle) |
nuclear@3 | 29 { |
nuclear@3 | 30 return sin_int(norm_angle + SINLUT_SIZE / 4); |
nuclear@3 | 31 } |
nuclear@3 | 32 |
nuclear@3 | 33 int32_t sin_x16(int32_t radians) |
nuclear@3 | 34 { |
nuclear@4 | 35 int32_t na = x16div(radians, M_PI_X16 * 2); |
nuclear@4 | 36 return (sin_int((na * SINLUT_SIZE) >> 16) << 16) / SINLUT_SCALE; |
nuclear@3 | 37 } |
nuclear@3 | 38 |
nuclear@3 | 39 int32_t cos_x16(int32_t radians) |
nuclear@3 | 40 { |
nuclear@4 | 41 int32_t na = x16div(radians, M_PI_X16 * 2); |
nuclear@4 | 42 return (cos_int((na * SINLUT_SIZE) >> 16) << 16) / SINLUT_SCALE; |
nuclear@3 | 43 } |