… | |
… | |
36 | * Get a coordinate |
36 | * Get a coordinate |
37 | * |
37 | * |
38 | * @param p Pointer to the coordinate |
38 | * @param p Pointer to the coordinate |
39 | * @returns the coordinate |
39 | * @returns the coordinate |
40 | */ |
40 | */ |
|
|
41 | |
|
|
42 | |
|
|
43 | |
|
|
44 | /* |
|
|
45 | ================ |
|
|
46 | sine lookup table (input in degress) |
|
|
47 | ================ |
|
|
48 | */ |
|
|
49 | /* |
|
|
50 | #define SINMAX 9000 |
|
|
51 | double sinlut[SINMAX + 1]; |
|
|
52 | void sincreate(void) |
|
|
53 | { |
|
|
54 | int i; |
|
|
55 | double angle, angleinc; |
|
|
56 | |
|
|
57 | angleinc = 3.1415926535 / 2.0 / (SINMAX); |
|
|
58 | for (i = 0, angle = 0.0; i <= SINMAX; ++i, angle += angleinc) |
|
|
59 | { |
|
|
60 | sinlut[i] = sin(angle); |
|
|
61 | } |
|
|
62 | } |
|
|
63 | |
|
|
64 | double sin_lut(double degrees) |
|
|
65 | { |
|
|
66 | int ix; |
|
|
67 | ix = (int)(degrees * 100.0); |
|
|
68 | return sinlut[ix]; |
|
|
69 | } |
|
|
70 | */ |
|
|
71 | |
|
|
72 | // very fast, but can be a bit off the real value!! so be careful! |
|
|
73 | float sqrtf_fast2(float x2) |
|
|
74 | { |
|
|
75 | unsigned int i = *(unsigned int*) &x2; |
|
|
76 | // adjust bias |
|
|
77 | i += 127 << 23; |
|
|
78 | // approximation of square root |
|
|
79 | i >>= 1; |
|
|
80 | return *(float*) &i; |
|
|
81 | } |
|
|
82 | |
|
|
83 | /* |
|
|
84 | ================ |
|
|
85 | SquareRootFloat (rather accurate) |
|
|
86 | ================ |
|
|
87 | */ |
|
|
88 | float sqrtf_fast(float number2) |
|
|
89 | { |
|
|
90 | long i; |
|
|
91 | float x, y; |
|
|
92 | const float f = 1.5F; |
|
|
93 | |
|
|
94 | x = number2 * 0.5F; |
|
|
95 | y = number2; |
|
|
96 | |
|
|
97 | i = * ( long * ) &y; |
|
|
98 | i = 0x5f3759df - ( i >> 1 ); |
|
|
99 | y = * ( float * ) &i; |
|
|
100 | y = y * ( f - ( x * y * y ) ); |
|
|
101 | y = y * ( f - ( x * y * y ) ); |
|
|
102 | return number2 * y; |
|
|
103 | } |
|
|
104 | |
|
|
105 | |
41 | |
106 | |
42 | struct coord * |
107 | struct coord * |
43 | coord_get(unsigned char **p) |
108 | coord_get(unsigned char **p) |
44 | { |
109 | { |
45 | struct coord *ret=(struct coord *)(*p); |
110 | struct coord *ret=(struct coord *)(*p); |