2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // mathlib.c -- math primitives
25 vec3_t vec3_origin = {0,0,0};
28 /*-----------------------------------------------------------------*/
30 float m_bytenormals[NUMVERTEXNORMALS][3] =
32 {-0.525731, 0.000000, 0.850651}, {-0.442863, 0.238856, 0.864188},
33 {-0.295242, 0.000000, 0.955423}, {-0.309017, 0.500000, 0.809017},
34 {-0.162460, 0.262866, 0.951056}, {0.000000, 0.000000, 1.000000},
35 {0.000000, 0.850651, 0.525731}, {-0.147621, 0.716567, 0.681718},
36 {0.147621, 0.716567, 0.681718}, {0.000000, 0.525731, 0.850651},
37 {0.309017, 0.500000, 0.809017}, {0.525731, 0.000000, 0.850651},
38 {0.295242, 0.000000, 0.955423}, {0.442863, 0.238856, 0.864188},
39 {0.162460, 0.262866, 0.951056}, {-0.681718, 0.147621, 0.716567},
40 {-0.809017, 0.309017, 0.500000}, {-0.587785, 0.425325, 0.688191},
41 {-0.850651, 0.525731, 0.000000}, {-0.864188, 0.442863, 0.238856},
42 {-0.716567, 0.681718, 0.147621}, {-0.688191, 0.587785, 0.425325},
43 {-0.500000, 0.809017, 0.309017}, {-0.238856, 0.864188, 0.442863},
44 {-0.425325, 0.688191, 0.587785}, {-0.716567, 0.681718, -0.147621},
45 {-0.500000, 0.809017, -0.309017}, {-0.525731, 0.850651, 0.000000},
46 {0.000000, 0.850651, -0.525731}, {-0.238856, 0.864188, -0.442863},
47 {0.000000, 0.955423, -0.295242}, {-0.262866, 0.951056, -0.162460},
48 {0.000000, 1.000000, 0.000000}, {0.000000, 0.955423, 0.295242},
49 {-0.262866, 0.951056, 0.162460}, {0.238856, 0.864188, 0.442863},
50 {0.262866, 0.951056, 0.162460}, {0.500000, 0.809017, 0.309017},
51 {0.238856, 0.864188, -0.442863}, {0.262866, 0.951056, -0.162460},
52 {0.500000, 0.809017, -0.309017}, {0.850651, 0.525731, 0.000000},
53 {0.716567, 0.681718, 0.147621}, {0.716567, 0.681718, -0.147621},
54 {0.525731, 0.850651, 0.000000}, {0.425325, 0.688191, 0.587785},
55 {0.864188, 0.442863, 0.238856}, {0.688191, 0.587785, 0.425325},
56 {0.809017, 0.309017, 0.500000}, {0.681718, 0.147621, 0.716567},
57 {0.587785, 0.425325, 0.688191}, {0.955423, 0.295242, 0.000000},
58 {1.000000, 0.000000, 0.000000}, {0.951056, 0.162460, 0.262866},
59 {0.850651, -0.525731, 0.000000}, {0.955423, -0.295242, 0.000000},
60 {0.864188, -0.442863, 0.238856}, {0.951056, -0.162460, 0.262866},
61 {0.809017, -0.309017, 0.500000}, {0.681718, -0.147621, 0.716567},
62 {0.850651, 0.000000, 0.525731}, {0.864188, 0.442863, -0.238856},
63 {0.809017, 0.309017, -0.500000}, {0.951056, 0.162460, -0.262866},
64 {0.525731, 0.000000, -0.850651}, {0.681718, 0.147621, -0.716567},
65 {0.681718, -0.147621, -0.716567}, {0.850651, 0.000000, -0.525731},
66 {0.809017, -0.309017, -0.500000}, {0.864188, -0.442863, -0.238856},
67 {0.951056, -0.162460, -0.262866}, {0.147621, 0.716567, -0.681718},
68 {0.309017, 0.500000, -0.809017}, {0.425325, 0.688191, -0.587785},
69 {0.442863, 0.238856, -0.864188}, {0.587785, 0.425325, -0.688191},
70 {0.688191, 0.587785, -0.425325}, {-0.147621, 0.716567, -0.681718},
71 {-0.309017, 0.500000, -0.809017}, {0.000000, 0.525731, -0.850651},
72 {-0.525731, 0.000000, -0.850651}, {-0.442863, 0.238856, -0.864188},
73 {-0.295242, 0.000000, -0.955423}, {-0.162460, 0.262866, -0.951056},
74 {0.000000, 0.000000, -1.000000}, {0.295242, 0.000000, -0.955423},
75 {0.162460, 0.262866, -0.951056}, {-0.442863, -0.238856, -0.864188},
76 {-0.309017, -0.500000, -0.809017}, {-0.162460, -0.262866, -0.951056},
77 {0.000000, -0.850651, -0.525731}, {-0.147621, -0.716567, -0.681718},
78 {0.147621, -0.716567, -0.681718}, {0.000000, -0.525731, -0.850651},
79 {0.309017, -0.500000, -0.809017}, {0.442863, -0.238856, -0.864188},
80 {0.162460, -0.262866, -0.951056}, {0.238856, -0.864188, -0.442863},
81 {0.500000, -0.809017, -0.309017}, {0.425325, -0.688191, -0.587785},
82 {0.716567, -0.681718, -0.147621}, {0.688191, -0.587785, -0.425325},
83 {0.587785, -0.425325, -0.688191}, {0.000000, -0.955423, -0.295242},
84 {0.000000, -1.000000, 0.000000}, {0.262866, -0.951056, -0.162460},
85 {0.000000, -0.850651, 0.525731}, {0.000000, -0.955423, 0.295242},
86 {0.238856, -0.864188, 0.442863}, {0.262866, -0.951056, 0.162460},
87 {0.500000, -0.809017, 0.309017}, {0.716567, -0.681718, 0.147621},
88 {0.525731, -0.850651, 0.000000}, {-0.238856, -0.864188, -0.442863},
89 {-0.500000, -0.809017, -0.309017}, {-0.262866, -0.951056, -0.162460},
90 {-0.850651, -0.525731, 0.000000}, {-0.716567, -0.681718, -0.147621},
91 {-0.716567, -0.681718, 0.147621}, {-0.525731, -0.850651, 0.000000},
92 {-0.500000, -0.809017, 0.309017}, {-0.238856, -0.864188, 0.442863},
93 {-0.262866, -0.951056, 0.162460}, {-0.864188, -0.442863, 0.238856},
94 {-0.809017, -0.309017, 0.500000}, {-0.688191, -0.587785, 0.425325},
95 {-0.681718, -0.147621, 0.716567}, {-0.442863, -0.238856, 0.864188},
96 {-0.587785, -0.425325, 0.688191}, {-0.309017, -0.500000, 0.809017},
97 {-0.147621, -0.716567, 0.681718}, {-0.425325, -0.688191, 0.587785},
98 {-0.162460, -0.262866, 0.951056}, {0.442863, -0.238856, 0.864188},
99 {0.162460, -0.262866, 0.951056}, {0.309017, -0.500000, 0.809017},
100 {0.147621, -0.716567, 0.681718}, {0.000000, -0.525731, 0.850651},
101 {0.425325, -0.688191, 0.587785}, {0.587785, -0.425325, 0.688191},
102 {0.688191, -0.587785, 0.425325}, {-0.955423, 0.295242, 0.000000},
103 {-0.951056, 0.162460, 0.262866}, {-1.000000, 0.000000, 0.000000},
104 {-0.850651, 0.000000, 0.525731}, {-0.955423, -0.295242, 0.000000},
105 {-0.951056, -0.162460, 0.262866}, {-0.864188, 0.442863, -0.238856},
106 {-0.951056, 0.162460, -0.262866}, {-0.809017, 0.309017, -0.500000},
107 {-0.864188, -0.442863, -0.238856}, {-0.951056, -0.162460, -0.262866},
108 {-0.809017, -0.309017, -0.500000}, {-0.681718, 0.147621, -0.716567},
109 {-0.681718, -0.147621, -0.716567}, {-0.850651, 0.000000, -0.525731},
110 {-0.688191, 0.587785, -0.425325}, {-0.587785, 0.425325, -0.688191},
111 {-0.425325, 0.688191, -0.587785}, {-0.425325, -0.688191, -0.587785},
112 {-0.587785, -0.425325, -0.688191}, {-0.688191, -0.587785, -0.425325},
115 qbyte NormalToByte(const vec3_t n)
118 float bestdistance, distance;
121 bestdistance = DotProduct (n, m_bytenormals[0]);
122 for (i = 1;i < NUMVERTEXNORMALS;i++)
124 distance = DotProduct (n, m_bytenormals[i]);
125 if (distance > bestdistance)
127 bestdistance = distance;
134 // note: uses byte partly to force unsigned for the validity check
135 void ByteToNormal(qbyte num, vec3_t n)
137 if (num < NUMVERTEXNORMALS)
138 VectorCopy(m_bytenormals[num], n);
140 VectorClear(n); // FIXME: complain?
143 float Q_RSqrt(float number)
150 *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1);
151 return y * (1.5f - (number * 0.5f * y * y));
155 // assumes "src" is normalized
156 void PerpendicularVector( vec3_t dst, const vec3_t src )
158 // LordHavoc: optimized to death and beyond
172 minelem = fabs(src[0]);
173 if (fabs(src[1]) < minelem)
176 minelem = fabs(src[1]);
178 if (fabs(src[2]) < minelem)
182 dst[0] -= src[pos] * src[0];
183 dst[1] -= src[pos] * src[1];
184 dst[2] -= src[pos] * src[2];
186 // normalize the result
187 VectorNormalize(dst);
207 // LordHavoc: like AngleVectors, but taking a forward vector instead of angles, useful!
208 void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
212 right[0] = forward[2];
213 right[1] = -forward[0];
214 right[2] = forward[1];
216 d = DotProduct(forward, right);
217 right[0] -= d * forward[0];
218 right[1] -= d * forward[1];
219 right[2] -= d * forward[2];
220 VectorNormalizeFast(right);
221 CrossProduct(right, forward, up);
224 void VectorVectorsDouble(const double *forward, double *right, double *up)
228 right[0] = forward[2];
229 right[1] = -forward[0];
230 right[2] = forward[1];
232 d = DotProduct(forward, right);
233 right[0] -= d * forward[0];
234 right[1] -= d * forward[1];
235 right[2] -= d * forward[2];
236 VectorNormalize(right);
237 CrossProduct(right, forward, up);
240 void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
246 angle = DEG2RAD(degrees);
255 VectorVectors(vf, vr, vu);
257 t0 = vr[0] * c + vu[0] * -s;
258 t1 = vr[0] * s + vu[0] * c;
259 dst[0] = (t0 * vr[0] + t1 * vu[0] + vf[0] * vf[0]) * point[0]
260 + (t0 * vr[1] + t1 * vu[1] + vf[0] * vf[1]) * point[1]
261 + (t0 * vr[2] + t1 * vu[2] + vf[0] * vf[2]) * point[2];
263 t0 = vr[1] * c + vu[1] * -s;
264 t1 = vr[1] * s + vu[1] * c;
265 dst[1] = (t0 * vr[0] + t1 * vu[0] + vf[1] * vf[0]) * point[0]
266 + (t0 * vr[1] + t1 * vu[1] + vf[1] * vf[1]) * point[1]
267 + (t0 * vr[2] + t1 * vu[2] + vf[1] * vf[2]) * point[2];
269 t0 = vr[2] * c + vu[2] * -s;
270 t1 = vr[2] * s + vu[2] * c;
271 dst[2] = (t0 * vr[0] + t1 * vu[0] + vf[2] * vf[0]) * point[0]
272 + (t0 * vr[1] + t1 * vu[1] + vf[2] * vf[1]) * point[1]
273 + (t0 * vr[2] + t1 * vu[2] + vf[2] * vf[2]) * point[2];
276 /*-----------------------------------------------------------------*/
280 // BoxOnPlaneSide did a switch on a 'signbits' value and had optimized
281 // assembly in an attempt to accelerate it further, very inefficient
282 // considering that signbits of the frustum planes only changed each
283 // frame, and the world planes changed only at load time.
284 // So, to optimize it further I took the obvious route of storing a function
285 // pointer in the plane struct itself, and shrunk each of the individual
286 // cases to a single return statement.
288 // realized axial cases would be a nice speedup for world geometry, although
289 // never useful for the frustum planes.
290 int BoxOnPlaneSideX (vec3_t emins, vec3_t emaxs, mplane_t *p) {return p->dist <= emins[0] ? 1 : (p->dist >= emaxs[0] ? 2 : 3);}
291 int BoxOnPlaneSideY (vec3_t emins, vec3_t emaxs, mplane_t *p) {return p->dist <= emins[1] ? 1 : (p->dist >= emaxs[1] ? 2 : 3);}
292 int BoxOnPlaneSideZ (vec3_t emins, vec3_t emaxs, mplane_t *p) {return p->dist <= emins[2] ? 1 : (p->dist >= emaxs[2] ? 2 : 3);}
293 int BoxOnPlaneSide0 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]) >= p->dist) | (((p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]) < p->dist) << 1));}
294 int BoxOnPlaneSide1 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]) >= p->dist) | (((p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]) < p->dist) << 1));}
295 int BoxOnPlaneSide2 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]) >= p->dist) | (((p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]) < p->dist) << 1));}
296 int BoxOnPlaneSide3 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]) >= p->dist) | (((p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]) < p->dist) << 1));}
297 int BoxOnPlaneSide4 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]) >= p->dist) | (((p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]) < p->dist) << 1));}
298 int BoxOnPlaneSide5 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]) >= p->dist) | (((p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]) < p->dist) << 1));}
299 int BoxOnPlaneSide6 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]) >= p->dist) | (((p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]) < p->dist) << 1));}
300 int BoxOnPlaneSide7 (vec3_t emins, vec3_t emaxs, mplane_t *p) {return (((p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]) >= p->dist) | (((p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]) < p->dist) << 1));}
302 void BoxOnPlaneSideClassify(mplane_t *p)
307 p->BoxOnPlaneSideFunc = BoxOnPlaneSideX;
310 p->BoxOnPlaneSideFunc = BoxOnPlaneSideY;
313 p->BoxOnPlaneSideFunc = BoxOnPlaneSideZ;
316 if (p->normal[2] < 0) // 4
318 if (p->normal[1] < 0) // 2
320 if (p->normal[0] < 0) // 1
321 p->BoxOnPlaneSideFunc = BoxOnPlaneSide7;
323 p->BoxOnPlaneSideFunc = BoxOnPlaneSide6;
327 if (p->normal[0] < 0) // 1
328 p->BoxOnPlaneSideFunc = BoxOnPlaneSide5;
330 p->BoxOnPlaneSideFunc = BoxOnPlaneSide4;
335 if (p->normal[1] < 0) // 2
337 if (p->normal[0] < 0) // 1
338 p->BoxOnPlaneSideFunc = BoxOnPlaneSide3;
340 p->BoxOnPlaneSideFunc = BoxOnPlaneSide2;
344 if (p->normal[0] < 0) // 1
345 p->BoxOnPlaneSideFunc = BoxOnPlaneSide1;
347 p->BoxOnPlaneSideFunc = BoxOnPlaneSide0;
354 void PlaneClassify(mplane_t *p)
356 if (p->normal[0] == 1)
358 else if (p->normal[1] == 1)
360 else if (p->normal[2] == 1)
364 BoxOnPlaneSideClassify(p);
367 void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
369 double angle, sr, sp, sy, cr, cp, cy;
371 angle = angles[YAW] * (M_PI*2 / 360);
374 angle = angles[PITCH] * (M_PI*2 / 360);
385 angle = angles[ROLL] * (M_PI*2 / 360);
390 right[0] = -1*(sr*sp*cy+cr*-sy);
391 right[1] = -1*(sr*sp*sy+cr*cy);
392 right[2] = -1*(sr*cp);
396 up[0] = (cr*sp*cy+-sr*-sy);
397 up[1] = (cr*sp*sy+-sr*cy);
403 void AngleVectorsFLU (const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up)
405 double angle, sr, sp, sy, cr, cp, cy;
407 angle = angles[YAW] * (M_PI*2 / 360);
410 angle = angles[PITCH] * (M_PI*2 / 360);
421 angle = angles[ROLL] * (M_PI*2 / 360);
426 left[0] = sr*sp*cy+cr*-sy;
427 left[1] = sr*sp*sy+cr*cy;
432 up[0] = cr*sp*cy+-sr*-sy;
433 up[1] = cr*sp*sy+-sr*cy;
439 void AngleMatrix (const vec3_t angles, const vec3_t translate, vec_t matrix[][4])
441 double angle, sr, sp, sy, cr, cp, cy;
443 angle = angles[YAW] * (M_PI*2 / 360);
446 angle = angles[PITCH] * (M_PI*2 / 360);
449 angle = angles[ROLL] * (M_PI*2 / 360);
452 matrix[0][0] = cp*cy;
453 matrix[0][1] = sr*sp*cy+cr*-sy;
454 matrix[0][2] = cr*sp*cy+-sr*-sy;
455 matrix[0][3] = translate[0];
456 matrix[1][0] = cp*sy;
457 matrix[1][1] = sr*sp*sy+cr*cy;
458 matrix[1][2] = cr*sp*sy+-sr*cy;
459 matrix[1][3] = translate[1];
461 matrix[2][1] = sr*cp;
462 matrix[2][2] = cr*cp;
463 matrix[2][3] = translate[2];
467 // LordHavoc: renamed this to Length, and made the normal one a #define
468 float VectorNormalizeLength (vec3_t v)
470 float length, ilength;
472 length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
473 length = sqrt (length);
493 void R_ConcatRotations (const float in1[3*3], const float in2[3*3], float out[3*3])
495 out[0*3+0] = in1[0*3+0] * in2[0*3+0] + in1[0*3+1] * in2[1*3+0] + in1[0*3+2] * in2[2*3+0];
496 out[0*3+1] = in1[0*3+0] * in2[0*3+1] + in1[0*3+1] * in2[1*3+1] + in1[0*3+2] * in2[2*3+1];
497 out[0*3+2] = in1[0*3+0] * in2[0*3+2] + in1[0*3+1] * in2[1*3+2] + in1[0*3+2] * in2[2*3+2];
498 out[1*3+0] = in1[1*3+0] * in2[0*3+0] + in1[1*3+1] * in2[1*3+0] + in1[1*3+2] * in2[2*3+0];
499 out[1*3+1] = in1[1*3+0] * in2[0*3+1] + in1[1*3+1] * in2[1*3+1] + in1[1*3+2] * in2[2*3+1];
500 out[1*3+2] = in1[1*3+0] * in2[0*3+2] + in1[1*3+1] * in2[1*3+2] + in1[1*3+2] * in2[2*3+2];
501 out[2*3+0] = in1[2*3+0] * in2[0*3+0] + in1[2*3+1] * in2[1*3+0] + in1[2*3+2] * in2[2*3+0];
502 out[2*3+1] = in1[2*3+0] * in2[0*3+1] + in1[2*3+1] * in2[1*3+1] + in1[2*3+2] * in2[2*3+1];
503 out[2*3+2] = in1[2*3+0] * in2[0*3+2] + in1[2*3+1] * in2[1*3+2] + in1[2*3+2] * in2[2*3+2];
512 void R_ConcatTransforms (const float in1[3*4], const float in2[3*4], float out[3*4])
514 out[0*4+0] = in1[0*4+0] * in2[0*4+0] + in1[0*4+1] * in2[1*4+0] + in1[0*4+2] * in2[2*4+0];
515 out[0*4+1] = in1[0*4+0] * in2[0*4+1] + in1[0*4+1] * in2[1*4+1] + in1[0*4+2] * in2[2*4+1];
516 out[0*4+2] = in1[0*4+0] * in2[0*4+2] + in1[0*4+1] * in2[1*4+2] + in1[0*4+2] * in2[2*4+2];
517 out[0*4+3] = in1[0*4+0] * in2[0*4+3] + in1[0*4+1] * in2[1*4+3] + in1[0*4+2] * in2[2*4+3] + in1[0*4+3];
518 out[1*4+0] = in1[1*4+0] * in2[0*4+0] + in1[1*4+1] * in2[1*4+0] + in1[1*4+2] * in2[2*4+0];
519 out[1*4+1] = in1[1*4+0] * in2[0*4+1] + in1[1*4+1] * in2[1*4+1] + in1[1*4+2] * in2[2*4+1];
520 out[1*4+2] = in1[1*4+0] * in2[0*4+2] + in1[1*4+1] * in2[1*4+2] + in1[1*4+2] * in2[2*4+2];
521 out[1*4+3] = in1[1*4+0] * in2[0*4+3] + in1[1*4+1] * in2[1*4+3] + in1[1*4+2] * in2[2*4+3] + in1[1*4+3];
522 out[2*4+0] = in1[2*4+0] * in2[0*4+0] + in1[2*4+1] * in2[1*4+0] + in1[2*4+2] * in2[2*4+0];
523 out[2*4+1] = in1[2*4+0] * in2[0*4+1] + in1[2*4+1] * in2[1*4+1] + in1[2*4+2] * in2[2*4+1];
524 out[2*4+2] = in1[2*4+0] * in2[0*4+2] + in1[2*4+1] * in2[1*4+2] + in1[2*4+2] * in2[2*4+2];
525 out[2*4+3] = in1[2*4+0] * in2[0*4+3] + in1[2*4+1] * in2[1*4+3] + in1[2*4+2] * in2[2*4+3] + in1[2*4+3];
529 void Mathlib_Init(void)
533 // LordHavoc: setup 1.0f / N table for quick recipricols of integers
535 for (a = 1;a < 4096;a++)
536 ixtable[a] = 1.0f / a;