ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ[ Rage Technologies, Inc. ]ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ ³ - Members - ³ ³ ] Myth: Ideas / Coder [ ³ ³ ] Night Stalker: Coder [ ³ ³ ] SKoRPiON: Musician [ ³ ³ ³ ³ - Support Board - ³ ³ ] Shadow Lands: (407) 851-2313, run by Night Stalker [ ³ ³ ³ ÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄ How to use Fixed Point (16.16) Math (Part 1 of 2) - by Night Stalker ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Allright, a simple question: what exactly *IS* fixed point math? Fixed point math is a very simple way to speed up any program that uses floating point. The 16.16 describes how many bits are before and after the decimal point. (In this case, 65535.65535 is the largest possible number.) There are other variants such as 24.8, and 8.24. It depends on what your application needs in regards to precision. Even with a math coprocessor (as it is becoming a standard nowadays), floating point speeds are slow. I will go into much detail about how fixed point can be used in your programs, as well as some trigonometric functions. But first, I must give credit to where credit is due. The code I am referencing was created by David Boeren. If you wish to reach him, E-mail me, and I will give you his address. (I'd rather not post it publicly, although I don't think he'd mind...) ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ First, we'll start out on how we actually set our program up to handle fixed point. You really only need one definition to use fixed point math: typedef long Fixed32; // 16.16 FixedPoint Then whenever you want a fixed point number, just use 'Fixed32' instead of 'float'. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Allright, you've got fixed point now. How do you actually get a number into this format? This is a little trickier. If you're using an integer or a char, you simply shift left over the decimal point. Longs are truncated because only 2 bytes fit in the upper portion of a Fixed32. The following #defines will help you out from converting to and from any format to Fixed32 and back: #define INT_TO_FIXED(x) ((x) << 16) #define DOUBLE_TO_FIXED(x) ((long)(x * 65536.0 + 0.5)) #define FIXED_TO_INT(x) ((x) >> 16) #define FIXED_TO_DOUBLE(x) (((double)x) / 65536.0) #define ROUND_FIXED_TO_INT(x) (((x) + 0x8000) >> 16) I also use the following #defines as well to access some well-known numbers: #define ONE INT_TO_FIXED(1) #define FIXED_PI 205887L #define FIXED_2PI 411775L #define FIXED_E 178144L #define FIXED_ROOT2 74804L #define FIXED_ROOT3 113512L #define FIXED_GOLDEN 106039L Notice that FIXED_2PI is not equal to 2 * PI. Why? Well, 2 * FIXED_PI is technically close enough, but FIXED_2PI is closer. :) ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Okay, you understand fixed point and now you want to do the basics of math. How do we accomplish adding, subtracting, multipling, and dividing? Adding and subtracting are simple. You simply add and subtract like you would normal floats. (ie: c = a + b; d -= c; etc, etc.) Multiplication and division require a little more. Since the code was done assuming you're using the 32-bit registers, you'll run into some problems if you try to port this to a 16-bit compiler. To be honest, I don't even think it's possible. Anyways, here's the code to multiply and divide fixed point numbers: Fixed32 FixedMul(Fixed32 num1, Fixed32 num2); Fixed32 FixedDiv(Fixed32 numer, Fixed32 denom); #pragma aux FixedMul = \ "imul edx" \ "add eax, 8000h" \ "adc edx, 0" \ "shrd eax, edx, 16" \ parm caller [eax] [edx] \ value [eax] \ modify [eax edx]; #pragma aux FixedDiv = \ "xor eax, eax" \ "shrd eax, edx, 16" \ "sar edx, 16" \ "idiv ebx" \ parm caller [edx] [ebx] \ value [eax] \ modify [eax ebx edx]; If you're up on your assembly code, you'll notice that FixedDiv() doesn't do any rounding. Just take that into note. If some of you have never done assembly in Watcom, I'll try to help. Watcom's way of adding assembly into your programs starts with a #pragma. The standard format is: #pragma aux = \ "" \ "" \ "<...>" \ parm caller [] ... \ value [] \ modify [ ...]; Watcom uses 'parm caller' to know where to put the variables that are passed to an inline assembly function. For example in FixedDiv(), the numerator is passed into the EDX register, and the denominator is passed into the EBX register. The 'value' command is used to determine what register contains the value to return to the program when the inline code has completed. The 'modify' command tells Watcom what registers to push onto the stack (since you will be modifying them). Watcom allows omitting of 'parm caller' and 'value' if there is no need for them. If you have a function which doesn't return a value, then omit 'value'. The same goes for 'parm caller'. Unfortunately, I've only had success at putting inline code into my .H (or .HPP) files. If anyone knows the answer to this mystery, *PLEASE* tell me. Thanks. :) ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Moving right along... now that you know the basic math, we can start on how to do some of the harder math functions: squaring, one over (1/x), square root, and logarithm. Fixed32 FixedSquare(Fixed32 n); Fixed32 OneOver(Fixed32 n); Fixed32 FixedSqrtLP(Fixed32 n); // Low Precision (8.8) Fixed32 FixedSqrtHP(Fixed32 n); // High Precision (8.16) Fixed32 FixedLog(Fixed32 num, Fixed32 base); // This is faster than using FixedMul for squares. #pragma aux FixedSquare = \ "imul eax" \ "add eax, 8000h" \ "adc edx, 0" \ "shrd eax, edx, 16" \ parm caller [eax] \ value [eax] \ modify [eax edx]; // This is faster than using FixedDiv. #pragma aux OneOver = \ "xor eax, eax" \ "mov edx, 1" \ "idiv ebx" \ parm caller [ebx] \ value [eax] \ modify [eax ebx edx]; #pragma aux FixedSqrtLP = \ " xor eax, eax" \ " mov ebx, 40000000h" \ "sqrtLP1: mov edx, ecx" \ " sub edx, ebx" \ " jl sqrtLP2" \ " sub edx, eax" \ " jl sqrtLP2" \ " mov ecx,edx" \ " shr eax, 1" \ " or eax, ebx" \ " shr ebx, 2" \ " jnz sqrtLP1" \ " shl eax, 8" \ " jmp sqrtLP3" \ "sqrtLP2: shr eax, 1" \ " shr ebx, 2" \ " jnz sqrtLP1" \ " shl eax, 8" \ "sqrtLP3: nop" \ parm caller [ecx] \ value [eax] \ modify [eax ebx ecx edx]; #pragma aux FixedSqrtHP = \ " xor eax, eax" \ " mov ebx, 40000000h" \ "sqrtHP1: mov edx, ecx" \ " sub edx, ebx" \ " jb sqrtHP2" \ " sub edx, eax" \ " jb sqrtHP2" \ " mov ecx,edx" \ " shr eax, 1" \ " or eax, ebx" \ " shr ebx, 2" \ " jnz sqrtHP1" \ " jz sqrtHP5" \ "sqrtHP2: shr eax, 1" \ " shr ebx, 2" \ " jnz sqrtHP1" \ "sqrtHP5: mov ebx, 00004000h" \ " shl eax, 16" \ " shl ecx, 16" \ "sqrtHP3: mov edx, ecx" \ " sub edx, ebx" \ " jb sqrtHP4" \ " sub edx, eax" \ " jb sqrtHP4" \ " mov ecx, edx" \ " shr eax, 1" \ " or eax, ebx" \ " shr ebx, 2" \ " jnz sqrtHP3" \ " jmp sqrtHP6" \ "sqrtHP4: shr eax, 1" \ " shr ebx, 2" \ " jnz sqrtHP3" \ "sqrtHP6: nop" \ parm caller [ecx] \ value [eax] \ modify [eax ebx ecx edx]; Fixed32 FixedLog(Fixed32 num, Fixed32 base) { return FixedDiv(FixedLn(num), FixedLn(base)); } I hope you don't gawk at all that assembly code. Not to worry, there isn't any more. :) Note that the high precision square root takes more time to perform than it does for the lower precision. One note here regarding the inline assembly. As you can see, jumps are possible in the code. However, when you have a jump to the last command (see 'sqrtHP6:' above..), you need an instruction or Watcom will yell at you. Pick your own, I found NOP to be the best since it suited my needs just fine. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Allright, this is the last section: How to do trigonometric functions in fixed point. Well, I found it easier to use lookup tables since the need for fixed point in the first place was for speed. Why bother bogging down the processor with floating point cosines and sines and converting them to fixed point? #define MAX_TRIG 1024 void CosSin(Iangle theta, Fixed32 *Cos, Fixed32 *Sin) { theta &= (MAX_TRIG - 1); *Sin = SinTab[theta]; *Cos = CosTab[theta]; } Fixed32 Tan(Iangle theta) { // This shifting stuff is for better accuracy. theta &= (MAX_TRIG - 1); return (FixedDiv(SinTab[theta] << 16, CosTab[theta]) >> 16); } The lookup tables are below. They're separated by bars for ease of reading. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Fixed32 SinTab[MAX_TRIG] = { 0, 402, 804, 1206, 1608, 2010, 2412, 2814, 3216, 3617, 4019, 4420, 4821, 5222, 5623, 6023, 6424, 6824, 7224, 7623, 8022, 8421, 8820, 9218, 9616, 10014, 10411, 10808, 11204, 11600, 11996, 12391, 12785, 13180, 13573, 13966, 14359, 14751, 15143, 15534, 15924, 16314, 16703, 17091, 17479, 17867, 18253, 18639, 19024, 19409, 19792, 20175, 20557, 20939, 21320, 21699, 22078, 22457, 22834, 23210, 23586, 23961, 24335, 24708, 25080, 25451, 25821, 26190, 26558, 26925, 27291, 27656, 28020, 28383, 28745, 29106, 29466, 29824, 30182, 30538, 30893, 31248, 31600, 31952, 32303, 32652, 33000, 33347, 33692, 34037, 34380, 34721, 35062, 35401, 35738, 36075, 36410, 36744, 37076, 37407, 37736, 38064, 38391, 38716, 39040, 39362, 39683, 40002, 40320, 40636, 40951, 41264, 41576, 41886, 42194, 42501, 42806, 43110, 43412, 43713, 44011, 44308, 44604, 44898, 45190, 45480, 45769, 46056, 46341, 46624, 46906, 47186, 47464, 47741, 48015, 48288, 48559, 48828, 49095, 49361, 49624, 49886, 50146, 50404, 50660, 50914, 51166, 51417, 51665, 51911, 52156, 52398, 52639, 52878, 53114, 53349, 53581, 53812, 54040, 54267, 54491, 54714, 54934, 55152, 55368, 55582, 55794, 56004, 56212, 56418, 56621, 56823, 57022, 57219, 57414, 57607, 57798, 57986, 58172, 58356, 58538, 58718, 58896, 59071, 59244, 59415, 59583, 59750, 59914, 60075, 60235, 60392, 60547, 60700, 60851, 60999, 61145, 61288, 61429, 61568, 61705, 61839, 61971, 62101, 62228, 62353, 62476, 62596, 62714, 62830, 62943, 63054, 63162, 63268, 63372, 63473, 63572, 63668, 63763, 63854, 63944, 64031, 64115, 64197, 64277, 64354, 64429, 64501, 64571, 64639, 64704, 64766, 64827, 64884, 64940, 64993, 65043, 65091, 65137, 65180, 65220, 65259, 65294, 65328, 65358, 65387, 65413, 65436, 65457, 65476, 65492, 65505, 65516, 65525, 65531, 65535, 65536, 65535, 65531, 65525, 65516, 65505, 65492, 65476, 65457, 65436, 65413, 65387, 65358, 65328, 65294, 65259, 65220, 65180, 65137, 65091, 65043, 64993, 64940, 64884, 64827, 64766, 64704, 64639, 64571, 64501, 64429, 64354, 64277, 64197, 64115, 64031, 63944, 63854, 63763, 63668, 63572, 63473, 63372, 63268, 63162, 63054, 62943, 62830, 62714, 62596, 62476, 62353, 62228, 62101, 61971, 61839, 61705, 61568, 61429, 61288, 61145, 60999, 60851, 60700, 60547, 60392, 60235, 60075, 59914, 59750, 59583, 59415, 59244, 59071, 58896, 58718, 58538, 58356, 58172, 57986, 57798, 57607, 57414, 57219, 57022, 56823, 56621, 56418, 56212, 56004, 55794, 55582, 55368, 55152, 54934, 54714, 54491, 54267, 54040, 53812, 53581, 53349, 53114, 52878, 52639, 52398, 52156, 51911, 51665, 51417, 51166, 50914, 50660, 50404, 50146, 49886, 49624, 49361, 49095, 48828, 48559, 48288, 48015, 47741, 47464, 47186, 46906, 46624, 46341, 46056, 45769, 45480, 45190, 44898, 44604, 44308, 44011, 43713, 43412, 43110, 42806, 42501, 42194, 41886, 41576, 41264, 40951, 40636, 40320, 40002, 39683, 39362, 39040, 38716, 38391, 38064, 37736, 37407, 37076, 36744, 36410, 36075, 35738, 35401, 35062, 34721, 34380, 34037, 33692, 33347, 33000, 32652, 32303, 31952, 31600, 31248, 30893, 30538, 30182, 29824, 29466, 29106, 28745, 28383, 28020, 27656, 27291, 26925, 26558, 26190, 25821, 25451, 25080, 24708, 24335, 23961, 23586, 23210, 22834, 22457, 22078, 21699, 21320, 20939, 20557, 20175, 19792, 19409, 19024, 18639, 18253, 17867, 17479, 17091, 16703, 16314, 15924, 15534, 15143, 14751, 14359, 13966, 13573, 13180, 12785, 12391, 11996, 11600, 11204, 10808, 10411, 10014, 9616, 9218, 8820, 8421, 8022, 7623, 7224, 6824, 6424, 6023, 5623, 5222, 4821, 4420, 4019, 3617, 3216, 2814, 2412, 2010, 1608, 1206, 804, 402, 0, 4294966895, 4294966493, 4294966091, 4294965689, 4294965287, 4294964885, 4294964483, 4294964081, 4294963680, 4294963278, 4294962877, 4294962476, 4294962075, 4294961674, 4294961274, 4294960873, 4294960473, 4294960073, 4294959674, 4294959275, 4294958876, 4294958477, 4294958079, 4294957681, 4294957283, 4294956886, 4294956489, 4294956093, 4294955697, 4294955301, 4294954906, 4294954512, 4294954117, 4294953724, 4294953331, 4294952938, 4294952546, 4294952154, 4294951763, 4294951373, 4294950983, 4294950594, 4294950206, 4294949818, 4294949430, 4294949044, 4294948658, 4294948273, 4294947888, 4294947505, 4294947122, 4294946740, 4294946358, 4294945977, 4294945598, 4294945219, 4294944840, 4294944463, 4294944087, 4294943711, 4294943336, 4294942962, 4294942589, 4294942217, 4294941846, 4294941476, 4294941107, 4294940739, 4294940372, 4294940006, 4294939641, 4294939277, 4294938914, 4294938552, 4294938191, 4294937831, 4294937473, 4294937115, 4294936759, 4294936404, 4294936049, 4294935697, 4294935345, 4294934994, 4294934645, 4294934297, 4294933950, 4294933605, 4294933260, 4294932917, 4294932576, 4294932235, 4294931896, 4294931559, 4294931222, 4294930887, 4294930553, 4294930221, 4294929890, 4294929561, 4294929233, 4294928906, 4294928581, 4294928257, 4294927935, 4294927614, 4294927295, 4294926977, 4294926661, 4294926346, 4294926033, 4294925721, 4294925411, 4294925103, 4294924796, 4294924491, 4294924187, 4294923885, 4294923584, 4294923286, 4294922989, 4294922693, 4294922399, 4294922107, 4294921817, 4294921528, 4294921241, 4294920956, 4294920673, 4294920391, 4294920111, 4294919833, 4294919556, 4294919282, 4294919009, 4294918738, 4294918469, 4294918202, 4294917936, 4294917673, 4294917411, 4294917151, 4294916893, 4294916637, 4294916383, 4294916131, 4294915880, 4294915632, 4294915386, 4294915141, 4294914899, 4294914658, 4294914419, 4294914183, 4294913948, 4294913716, 4294913485, 4294913257, 4294913030, 4294912806, 4294912583, 4294912363, 4294912145, 4294911929, 4294911715, 4294911503, 4294911293, 4294911085, 4294910879, 4294910676, 4294910474, 4294910275, 4294910078, 4294909883, 4294909690, 4294909499, 4294909311, 4294909125, 4294908941, 4294908759, 4294908579, 4294908401, 4294908226, 4294908053, 4294907882, 4294907714, 4294907547, 4294907383, 4294907222, 4294907062, 4294906905, 4294906750, 4294906597, 4294906446, 4294906298, 4294906152, 4294906009, 4294905868, 4294905729, 4294905592, 4294905458, 4294905326, 4294905196, 4294905069, 4294904944, 4294904821, 4294904701, 4294904583, 4294904467, 4294904354, 4294904243, 4294904135, 4294904029, 4294903925, 4294903824, 4294903725, 4294903629, 4294903534, 4294903443, 4294903353, 4294903266, 4294903182, 4294903100, 4294903020, 4294902943, 4294902868, 4294902796, 4294902726, 4294902658, 4294902593, 4294902531, 4294902470, 4294902413, 4294902357, 4294902304, 4294902254, 4294902206, 4294902160, 4294902117, 4294902077, 4294902038, 4294902003, 4294901969, 4294901939, 4294901910, 4294901884, 4294901861, 4294901840, 4294901821, 4294901805, 4294901792, 4294901781, 4294901772, 4294901766, 4294901762, 4294901761, 4294901762, 4294901766, 4294901772, 4294901781, 4294901792, 4294901805, 4294901821, 4294901840, 4294901861, 4294901884, 4294901910, 4294901939, 4294901969, 4294902003, 4294902038, 4294902077, 4294902117, 4294902160, 4294902206, 4294902254, 4294902304, 4294902357, 4294902413, 4294902470, 4294902531, 4294902593, 4294902658, 4294902726, 4294902796, 4294902868, 4294902943, 4294903020, 4294903100, 4294903182, 4294903266, 4294903353, 4294903443, 4294903534, 4294903629, 4294903725, 4294903824, 4294903925, 4294904029, 4294904135, 4294904243, 4294904354, 4294904467, 4294904583, 4294904701, 4294904821, 4294904944, 4294905069, 4294905196, 4294905326, 4294905458, 4294905592, 4294905729, 4294905868, 4294906009, 4294906152, 4294906298, 4294906446, 4294906597, 4294906750, 4294906905, 4294907062, 4294907222, 4294907383, 4294907547, 4294907714, 4294907882, 4294908053, 4294908226, 4294908401, 4294908579, 4294908759, 4294908941, 4294909125, 4294909311, 4294909499, 4294909690, 4294909883, 4294910078, 4294910275, 4294910474, 4294910676, 4294910879, 4294911085, 4294911293, 4294911503, 4294911715, 4294911929, 4294912145, 4294912363, 4294912583, 4294912806, 4294913030, 4294913257, 4294913485, 4294913716, 4294913948, 4294914183, 4294914419, 4294914658, 4294914899, 4294915141, 4294915386, 4294915632, 4294915880, 4294916131, 4294916383, 4294916637, 4294916893, 4294917151, 4294917411, 4294917673, 4294917936, 4294918202, 4294918469, 4294918738, 4294919009, 4294919282, 4294919556, 4294919833, 4294920111, 4294920391, 4294920673, 4294920956, 4294921241, 4294921528, 4294921817, 4294922107, 4294922399, 4294922693, 4294922989, 4294923286, 4294923584, 4294923885, 4294924187, 4294924491, 4294924796, 4294925103, 4294925411, 4294925721, 4294926033, 4294926346, 4294926661, 4294926977, 4294927295, 4294927614, 4294927935, 4294928257, 4294928581, 4294928906, 4294929233, 4294929561, 4294929890, 4294930221, 4294930553, 4294930887, 4294931222, 4294931559, 4294931896, 4294932235, 4294932576, 4294932917, 4294933260, 4294933605, 4294933950, 4294934297, 4294934645, 4294934994, 4294935345, 4294935697, 4294936049, 4294936404, 4294936759, 4294937115, 4294937473, 4294937831, 4294938191, 4294938552, 4294938914, 4294939277, 4294939641, 4294940006, 4294940372, 4294940739, 4294941107, 4294941476, 4294941846, 4294942217, 4294942589, 4294942962, 4294943336, 4294943711, 4294944087, 4294944463, 4294944840, 4294945219, 4294945598, 4294945977, 4294946358, 4294946740, 4294947122, 4294947505, 4294947888, 4294948273, 4294948658, 4294949044, 4294949430, 4294949818, 4294950206, 4294950594, 4294950983, 4294951373, 4294951763, 4294952154, 4294952546, 4294952938, 4294953331, 4294953724, 4294954117, 4294954512, 4294954906, 4294955301, 4294955697, 4294956093, 4294956489, 4294956886, 4294957283, 4294957681, 4294958079, 4294958477, 4294958876, 4294959275, 4294959674, 4294960073, 4294960473, 4294960873, 4294961274, 4294961674, 4294962075, 4294962476, 4294962877, 4294963278, 4294963680, 4294964081, 4294964483, 4294964885, 4294965287, 4294965689, 4294966091, 4294966493, 4294966895 }; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Fixed32 CosTab[MAX_TRIG] = { 65536, 65535, 65531, 65525, 65516, 65505, 65492, 65476, 65457, 65436, 65413, 65387, 65358, 65328, 65294, 65259, 65220, 65180, 65137, 65091, 65043, 64993, 64940, 64884, 64827, 64766, 64704, 64639, 64571, 64501, 64429, 64354, 64277, 64197, 64115, 64031, 63944, 63854, 63763, 63668, 63572, 63473, 63372, 63268, 63162, 63054, 62943, 62830, 62714, 62596, 62476, 62353, 62228, 62101, 61971, 61839, 61705, 61568, 61429, 61288, 61145, 60999, 60851, 60700, 60547, 60392, 60235, 60075, 59914, 59750, 59583, 59415, 59244, 59071, 58896, 58718, 58538, 58356, 58172, 57986, 57798, 57607, 57414, 57219, 57022, 56823, 56621, 56418, 56212, 56004, 55794, 55582, 55368, 55152, 54934, 54714, 54491, 54267, 54040, 53812, 53581, 53349, 53114, 52878, 52639, 52398, 52156, 51911, 51665, 51417, 51166, 50914, 50660, 50404, 50146, 49886, 49624, 49361, 49095, 48828, 48559, 48288, 48015, 47741, 47464, 47186, 46906, 46624, 46341, 46056, 45769, 45480, 45190, 44898, 44604, 44308, 44011, 43713, 43412, 43110, 42806, 42501, 42194, 41886, 41576, 41264, 40951, 40636, 40320, 40002, 39683, 39362, 39040, 38716, 38391, 38064, 37736, 37407, 37076, 36744, 36410, 36075, 35738, 35401, 35062, 34721, 34380, 34037, 33692, 33347, 33000, 32652, 32303, 31952, 31600, 31248, 30893, 30538, 30182, 29824, 29466, 29106, 28745, 28383, 28020, 27656, 27291, 26925, 26558, 26190, 25821, 25451, 25080, 24708, 24335, 23961, 23586, 23210, 22834, 22457, 22078, 21699, 21320, 20939, 20557, 20175, 19792, 19409, 19024, 18639, 18253, 17867, 17479, 17091, 16703, 16314, 15924, 15534, 15143, 14751, 14359, 13966, 13573, 13180, 12785, 12391, 11996, 11600, 11204, 10808, 10411, 10014, 9616, 9218, 8820, 8421, 8022, 7623, 7224, 6824, 6424, 6023, 5623, 5222, 4821, 4420, 4019, 3617, 3216, 2814, 2412, 2010, 1608, 1206, 804, 402, 0, 4294966895, 4294966493, 4294966091, 4294965689, 4294965287, 4294964885, 4294964483, 4294964081, 4294963680, 4294963278, 4294962877, 4294962476, 4294962075, 4294961674, 4294961274, 4294960873, 4294960473, 4294960073, 4294959674, 4294959275, 4294958876, 4294958477, 4294958079, 4294957681, 4294957283, 4294956886, 4294956489, 4294956093, 4294955697, 4294955301, 4294954906, 4294954512, 4294954117, 4294953724, 4294953331, 4294952938, 4294952546, 4294952154, 4294951763, 4294951373, 4294950983, 4294950594, 4294950206, 4294949818, 4294949430, 4294949044, 4294948658, 4294948273, 4294947888, 4294947505, 4294947122, 4294946740, 4294946358, 4294945977, 4294945598, 4294945219, 4294944840, 4294944463, 4294944087, 4294943711, 4294943336, 4294942962, 4294942589, 4294942217, 4294941846, 4294941476, 4294941107, 4294940739, 4294940372, 4294940006, 4294939641, 4294939277, 4294938914, 4294938552, 4294938191, 4294937831, 4294937473, 4294937115, 4294936759, 4294936404, 4294936049, 4294935697, 4294935345, 4294934994, 4294934645, 4294934297, 4294933950, 4294933605, 4294933260, 4294932917, 4294932576, 4294932235, 4294931896, 4294931559, 4294931222, 4294930887, 4294930553, 4294930221, 4294929890, 4294929561, 4294929233, 4294928906, 4294928581, 4294928257, 4294927935, 4294927614, 4294927295, 4294926977, 4294926661, 4294926346, 4294926033, 4294925721, 4294925411, 4294925103, 4294924796, 4294924491, 4294924187, 4294923885, 4294923584, 4294923286, 4294922989, 4294922693, 4294922399, 4294922107, 4294921817, 4294921528, 4294921241, 4294920956, 4294920673, 4294920391, 4294920111, 4294919833, 4294919556, 4294919282, 4294919009, 4294918738, 4294918469, 4294918202, 4294917936, 4294917673, 4294917411, 4294917151, 4294916893, 4294916637, 4294916383, 4294916131, 4294915880, 4294915632, 4294915386, 4294915141, 4294914899, 4294914658, 4294914419, 4294914183, 4294913948, 4294913716, 4294913485, 4294913257, 4294913030, 4294912806, 4294912583, 4294912363, 4294912145, 4294911929, 4294911715, 4294911503, 4294911293, 4294911085, 4294910879, 4294910676, 4294910474, 4294910275, 4294910078, 4294909883, 4294909690, 4294909499, 4294909311, 4294909125, 4294908941, 4294908759, 4294908579, 4294908401, 4294908226, 4294908053, 4294907882, 4294907714, 4294907547, 4294907383, 4294907222, 4294907062, 4294906905, 4294906750, 4294906597, 4294906446, 4294906298, 4294906152, 4294906009, 4294905868, 4294905729, 4294905592, 4294905458, 4294905326, 4294905196, 4294905069, 4294904944, 4294904821, 4294904701, 4294904583, 4294904467, 4294904354, 4294904243, 4294904135, 4294904029, 4294903925, 4294903824, 4294903725, 4294903629, 4294903534, 4294903443, 4294903353, 4294903266, 4294903182, 4294903100, 4294903020, 4294902943, 4294902868, 4294902796, 4294902726, 4294902658, 4294902593, 4294902531, 4294902470, 4294902413, 4294902357, 4294902304, 4294902254, 4294902206, 4294902160, 4294902117, 4294902077, 4294902038, 4294902003, 4294901969, 4294901939, 4294901910, 4294901884, 4294901861, 4294901840, 4294901821, 4294901805, 4294901792, 4294901781, 4294901772, 4294901766, 4294901762, 4294901761, 4294901762, 4294901766, 4294901772, 4294901781, 4294901792, 4294901805, 4294901821, 4294901840, 4294901861, 4294901884, 4294901910, 4294901939, 4294901969, 4294902003, 4294902038, 4294902077, 4294902117, 4294902160, 4294902206, 4294902254, 4294902304, 4294902357, 4294902413, 4294902470, 4294902531, 4294902593, 4294902658, 4294902726, 4294902796, 4294902868, 4294902943, 4294903020, 4294903100, 4294903182, 4294903266, 4294903353, 4294903443, 4294903534, 4294903629, 4294903725, 4294903824, 4294903925, 4294904029, 4294904135, 4294904243, 4294904354, 4294904467, 4294904583, 4294904701, 4294904821, 4294904944, 4294905069, 4294905196, 4294905326, 4294905458, 4294905592, 4294905729, 4294905868, 4294906009, 4294906152, 4294906298, 4294906446, 4294906597, 4294906750, 4294906905, 4294907062, 4294907222, 4294907383, 4294907547, 4294907714, 4294907882, 4294908053, 4294908226, 4294908401, 4294908579, 4294908759, 4294908941, 4294909125, 4294909311, 4294909499, 4294909690, 4294909883, 4294910078, 4294910275, 4294910474, 4294910676, 4294910879, 4294911085, 4294911293, 4294911503, 4294911715, 4294911929, 4294912145, 4294912363, 4294912583, 4294912806, 4294913030, 4294913257, 4294913485, 4294913716, 4294913948, 4294914183, 4294914419, 4294914658, 4294914899, 4294915141, 4294915386, 4294915632, 4294915880, 4294916131, 4294916383, 4294916637, 4294916893, 4294917151, 4294917411, 4294917673, 4294917936, 4294918202, 4294918469, 4294918738, 4294919009, 4294919282, 4294919556, 4294919833, 4294920111, 4294920391, 4294920673, 4294920956, 4294921241, 4294921528, 4294921817, 4294922107, 4294922399, 4294922693, 4294922989, 4294923286, 4294923584, 4294923885, 4294924187, 4294924491, 4294924796, 4294925103, 4294925411, 4294925721, 4294926033, 4294926346, 4294926661, 4294926977, 4294927295, 4294927614, 4294927935, 4294928257, 4294928581, 4294928906, 4294929233, 4294929561, 4294929890, 4294930221, 4294930553, 4294930887, 4294931222, 4294931559, 4294931896, 4294932235, 4294932576, 4294932917, 4294933260, 4294933605, 4294933950, 4294934297, 4294934645, 4294934994, 4294935345, 4294935697, 4294936049, 4294936404, 4294936759, 4294937115, 4294937473, 4294937831, 4294938191, 4294938552, 4294938914, 4294939277, 4294939641, 4294940006, 4294940372, 4294940739, 4294941107, 4294941476, 4294941846, 4294942217, 4294942589, 4294942962, 4294943336, 4294943711, 4294944087, 4294944463, 4294944840, 4294945219, 4294945598, 4294945977, 4294946358, 4294946740, 4294947122, 4294947505, 4294947888, 4294948273, 4294948658, 4294949044, 4294949430, 4294949818, 4294950206, 4294950594, 4294950983, 4294951373, 4294951763, 4294952154, 4294952546, 4294952938, 4294953331, 4294953724, 4294954117, 4294954512, 4294954906, 4294955301, 4294955697, 4294956093, 4294956489, 4294956886, 4294957283, 4294957681, 4294958079, 4294958477, 4294958876, 4294959275, 4294959674, 4294960073, 4294960473, 4294960873, 4294961274, 4294961674, 4294962075, 4294962476, 4294962877, 4294963278, 4294963680, 4294964081, 4294964483, 4294964885, 4294965287, 4294965689, 4294966091, 4294966493, 4294966895, 0, 402, 804, 1206, 1608, 2010, 2412, 2814, 3216, 3617, 4019, 4420, 4821, 5222, 5623, 6023, 6424, 6824, 7224, 7623, 8022, 8421, 8820, 9218, 9616, 10014, 10411, 10808, 11204, 11600, 11996, 12391, 12785, 13180, 13573, 13966, 14359, 14751, 15143, 15534, 15924, 16314, 16703, 17091, 17479, 17867, 18253, 18639, 19024, 19409, 19792, 20175, 20557, 20939, 21320, 21699, 22078, 22457, 22834, 23210, 23586, 23961, 24335, 24708, 25080, 25451, 25821, 26190, 26558, 26925, 27291, 27656, 28020, 28383, 28745, 29106, 29466, 29824, 30182, 30538, 30893, 31248, 31600, 31952, 32303, 32652, 33000, 33347, 33692, 34037, 34380, 34721, 35062, 35401, 35738, 36075, 36410, 36744, 37076, 37407, 37736, 38064, 38391, 38716, 39040, 39362, 39683, 40002, 40320, 40636, 40951, 41264, 41576, 41886, 42194, 42501, 42806, 43110, 43412, 43713, 44011, 44308, 44604, 44898, 45190, 45480, 45769, 46056, 46341, 46624, 46906, 47186, 47464, 47741, 48015, 48288, 48559, 48828, 49095, 49361, 49624, 49886, 50146, 50404, 50660, 50914, 51166, 51417, 51665, 51911, 52156, 52398, 52639, 52878, 53114, 53349, 53581, 53812, 54040, 54267, 54491, 54714, 54934, 55152, 55368, 55582, 55794, 56004, 56212, 56418, 56621, 56823, 57022, 57219, 57414, 57607, 57798, 57986, 58172, 58356, 58538, 58718, 58896, 59071, 59244, 59415, 59583, 59750, 59914, 60075, 60235, 60392, 60547, 60700, 60851, 60999, 61145, 61288, 61429, 61568, 61705, 61839, 61971, 62101, 62228, 62353, 62476, 62596, 62714, 62830, 62943, 63054, 63162, 63268, 63372, 63473, 63572, 63668, 63763, 63854, 63944, 64031, 64115, 64197, 64277, 64354, 64429, 64501, 64571, 64639, 64704, 64766, 64827, 64884, 64940, 64993, 65043, 65091, 65137, 65180, 65220, 65259, 65294, 65328, 65358, 65387, 65413, 65436, 65457, 65476, 65492, 65505, 65516, 65525, 65531, 65535 }; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ A couple of you first starting out in this might be wondering why the tables suddenly jump from zero to 4.2 billion. The reason is because I used unsigned numbers to dump this table. Since the highest bit in the number signifies the sign bit, when it jumps to a negative number, the number suddenly increases to 4.2 billion. (Actually, it's 2^31, if you want to get EXACT.) As this is the first part of two, the next file will cover doing Vector and Matrix calculations. I'll post it as soon as possible. But for now, enjoy the speed improvements in your program! - Night Stalker ------------------------------------------------------------------------------- Look for other Rage Technologies, Inc. stuff coming soon: - Our first major demo, "Transvectoring". The theme is to show off our new 3-D engine with lightsourcing and texture mapping... REALLY fast. Also to show what objects beyond 3D really look like. For example, a 4D or a 5D cube. Maybe more. Expected release date: Mid '95 (?) - Night Hawk 0.2à BBS. The first BBS software to show that ANSI is dead, and RIP is a thing of the past. Features include: True multitasking, full video and audio routines, and more. Expected release date: Early/Mid '96. ------------------------------------------------------------------------------- Other news: - Shadow Lands is *NOT* up! Please don't call for a few weeks! Night Stalker is in the process of rebuilding his system and adding more disk space. We are hoping that Night Stalker will have Shadow Lands up by Mid-February. - Rage Technologies, Inc. has a mailing list. If you'd like to get ahold of any one of us, send E-mail to: ragetech@trappen.vsl.ist.ucf.edu - Rage Technologies, Inc. also has an experimental FTP server running. If you would like to get any Rage products, simply anonymous FTP to: trappen.vsl.ist.ucf.edu. All Rage files are located in /pub/ragetech.