Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
8.4 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: trig.cxx
  3. *
  4. * trigonometric functions
  5. * adjusted andrew code so that it works with wendy's ELOATS
  6. *
  7. * Created: 05-Mar-1991 09:55:39
  8. * Author: Bodin Dresevic [BodinD]
  9. *
  10. * Copyright (c) 1990-1999 Microsoft Corporation
  11. *
  12. * (General description of its use)
  13. *
  14. * Dependencies:
  15. *
  16. \**************************************************************************/
  17. #include "precomp.hxx"
  18. /******************************Public*Data******************************\
  19. * It's Hack-o-rama time. The new 'C' compiler that runs on NT does
  20. * not have support for floating point constants. All floating point
  21. * constants must be defined in HEX values. In this file we have a
  22. * variable for each of the HEX constants used in the engine. flhack.hxx
  23. * has some #defines for casting these into floating point values.
  24. * The end result is a floating point constant like 3.0f get changed
  25. * to FP_3_0.
  26. *
  27. * To add a new floating point constant do the following:
  28. *
  29. * 1) check if already in the list. If so, no need to add
  30. * it again.
  31. * 2) Create a definition for it below. Figuring the exact
  32. * HEX constant is a little tricky. See kentd for help.
  33. * 3) Edit flhack.hxx, adding the proper defines.
  34. * 4) Include flhack.hxx in the file with the constant.
  35. * 5) Replace the constant X.Xf with FPX_X.
  36. *
  37. * the proper floating point support.
  38. *
  39. * History:
  40. * 22-Jul-1991 -by- J. Andrew Goossen [andrewgo]
  41. * Nuked all FLOATs. Will eventually generate this file at compile time.
  42. *
  43. * 01-May-1991 -by- Kent Diamond [kentd]
  44. * Wrote it.
  45. \**************************************************************************/
  46. #if defined(_AMD64_) || defined(_IA64_) || defined(BUILD_WOW6432)
  47. //
  48. // IEEE floats:
  49. //
  50. extern "C" {
  51. ULONG gaefArctan[] =
  52. {
  53. 0x0, 0x3fe51bca, 0x4064e2aa, 0x40ab62eb,
  54. 0x40e40022, 0x410e172e, 0x4129ea1c, 0x41456ce7,
  55. 0x41609474, 0x417b5695, 0x418ad50b, 0x4197c365,
  56. 0x41a472c8, 0x41b0e026, 0x41bd08f7, 0x41c8eb2f,
  57. 0x41d4853a, 0x41dfd5f7, 0x41eadcae, 0x41f59908,
  58. 0x42000583, 0x4205197c, 0x420a08ba, 0x420ed3a7,
  59. 0x42137ac6, 0x4217feb4, 0x421c601d, 0x42209fbe,
  60. 0x4224be63, 0x4228bcdf, 0x422c9c0c, 0x42305ccb,
  61. 0x42340000, 0x0
  62. };
  63. ULONG gaefSin[] =
  64. {
  65. 0x0, 0x3d48fb30, 0x3dc8bd36, 0x3e164083,
  66. 0x3e47c5c2, 0x3e78cfcc, 0x3e94a031, 0x3eac7cd4,
  67. 0x3ec3ef15, 0x3edae880, 0x3ef15aea, 0x3f039c3d,
  68. 0x3f0e39da, 0x3f187fc0, 0x3f226799, 0x3f2beb4a,
  69. 0x3f3504f3, 0x3f3daef9, 0x3f45e403, 0x3f4d9f02,
  70. 0x3f54db31, 0x3f5b941a, 0x3f61c598, 0x3f676bd8,
  71. 0x3f6c835e, 0x3f710908, 0x3f74fa0b, 0x3f7853f8,
  72. 0x3f7b14be, 0x3f7d3aac, 0x3f7ec46d, 0x3f7fb10f,
  73. 0x3f800000
  74. };
  75. ULONG gaefAxisCoord[] =
  76. {
  77. 0x0, 0x3f800000, 0x0, 0xbf800000
  78. };
  79. ULONG gaefAxisAngle[] =
  80. {
  81. 0x0, 0x42b40000, 0x43340000, 0x43870000,
  82. 0x43b40000
  83. };
  84. ULONG FP_0_0 = 0x0;
  85. ULONG FP_0_005 = 0x3ba3d70a;
  86. ULONG FP_0_5 = 0x3f000000;
  87. ULONG FP_1_0 = 0x3f800000;
  88. ULONG FP_2_0 = 0x40000000;
  89. ULONG FP_3_0 = 0x40400000;
  90. ULONG FP_4_0 = 0x40800000;
  91. ULONG FP_90_0 = 0x42b40000;
  92. ULONG FP_180_0 = 0x43340000;
  93. ULONG FP_270_0 = 0x43870000;
  94. ULONG FP_360_0 = 0x43b40000;
  95. ULONG FP_1000_0 = 0x447a0000;
  96. ULONG FP_3600_0 = 0x45610000;
  97. ULONG FP_M3600_0 = 0xc5610000;
  98. ULONG FP_QUADRANT_TAU = 0x3ee53aef; // 0.44772...
  99. ULONG FP_ORIGIN_TAU = 0x3f0d6289; // 0.552...
  100. ULONG FP_SINE_FACTOR = 0x3eb60b61; // SINE_TABLE_SIZE / 90.0
  101. ULONG FP_4DIV3 = 0x3faaaaab;
  102. ULONG FP_1DIV90 = 0x3c360b61;
  103. ULONG FP_EPSILON = 0x37800000;
  104. ULONG FP_ARCTAN_TABLE_SIZE = 0x42000000;
  105. ULONG FP_PI = 0x40490fda; // 3.1415926...
  106. };
  107. #else
  108. //
  109. // Internal EFloats:
  110. //
  111. extern "C" {
  112. EFLOAT_S gaefArctan[] =
  113. {
  114. {0x0, 0}, {0x728de539, 2}, {0x727154c9, 3},
  115. {0x55b17599, 4}, {0x72001124, 4}, {0x470b9706, 5},
  116. {0x54f50dd3, 5}, {0x62b67364, 5}, {0x704a3a03, 5},
  117. {0x7dab4a4f, 5}, {0x456a856f, 6}, {0x4be1b295, 6},
  118. {0x523963eb, 6}, {0x5870133a, 6}, {0x5e847b98, 6},
  119. {0x64759746, 6}, {0x6a429cc6, 6}, {0x6feafb55, 6},
  120. {0x756e56f1, 6}, {0x7acc8411, 6}, {0x4002c196, 7},
  121. {0x428cbe1e, 7}, {0x45045d20, 7}, {0x4769d374, 7},
  122. {0x49bd6339, 7}, {0x4bff59db, 7}, {0x4e300e45, 7},
  123. {0x504fdf2e, 7}, {0x525f3195, 7}, {0x545e6f5a, 7},
  124. {0x564e0606, 7}, {0x582e65af, 7}, {0x5a000000, 7},
  125. {0x0, 0}
  126. };
  127. EFLOAT_S gaefSin[] =
  128. {
  129. {0x0, 0}, {0x647d97c4, -3}, {0x645e9af0, -2},
  130. {0x4b2041ba, -1}, {0x63e2e0f1, -1}, {0x7c67e5ec, -1},
  131. {0x4a5018bb, 0}, {0x563e69d6, 0}, {0x61f78a9a, 0},
  132. {0x6d744027, 0}, {0x78ad74e0, 0}, {0x41ce1e64, 1},
  133. {0x471cece6, 1}, {0x4c3fdff3, 1}, {0x5133cc94, 1},
  134. {0x55f5a4d2, 1}, {0x5a827999, 1}, {0x5ed77c89, 1},
  135. {0x62f201ac, 1}, {0x66cf811f, 1}, {0x6a6d98a4, 1},
  136. {0x6dca0d14, 1}, {0x70e2cbc6, 1}, {0x73b5ebd0, 1},
  137. {0x7641af3c, 1}, {0x78848413, 1}, {0x7a7d055b, 1},
  138. {0x7c29fbee, 1}, {0x7d8a5f3f, 1}, {0x7e9d55fc, 1},
  139. {0x7f62368f, 1}, {0x7fd8878d, 1}, {0x40000000, 2}
  140. };
  141. EFLOAT_S gaefAxisCoord[] =
  142. {
  143. {0x0, 0}, {0x40000000, 2}, {0x0, 0},
  144. {0xc0000000, 2}
  145. };
  146. EFLOAT_S gaefAxisAngle[] =
  147. {
  148. {0x0, 0}, {0x5a000000, 8}, {0x5a000000, 9},
  149. {0x43800000, 10}, {0x5a000000, 10}
  150. };
  151. EFLOAT_S FP_0_0 = {0x0, 0};
  152. EFLOAT_S FP_0_005 = {0x51eb851e, -6};
  153. EFLOAT_S FP_0_5 = {0x40000000, 1};
  154. EFLOAT_S FP_1_0 = {0x40000000, 2};
  155. EFLOAT_S FP_2_0 = {0x40000000, 3};
  156. EFLOAT_S FP_3_0 = {0x60000000, 3};
  157. EFLOAT_S FP_4_0 = {0x40000000, 4};
  158. EFLOAT_S FP_90_0 = {0x5a000000, 8};
  159. EFLOAT_S FP_180_0 = {0x5a000000, 9};
  160. EFLOAT_S FP_270_0 = {0x43800000, 10};
  161. EFLOAT_S FP_360_0 = {0x5a000000, 10};
  162. EFLOAT_S FP_1000_0 = {0x7d000000, 11};
  163. EFLOAT_S FP_3600_0 = {0x70800000, 13};
  164. EFLOAT_S FP_M3600_0 = {0x8f800000, 13};
  165. EFLOAT_S FP_QUADRANT_TAU = {0x729d7775, 0}; // 0.44772...
  166. EFLOAT_S FP_ORIGIN_TAU = {0x46b14445, 1}; // 0.552...
  167. EFLOAT_S FP_SINE_FACTOR = {0x5b05b05b, 0}; // SINE_TABLE_SIZE / 90.0
  168. EFLOAT_S FP_4DIV3 = {0x55555555, 2};
  169. EFLOAT_S FP_1DIV90 = {0x5b05b05b, -5};
  170. EFLOAT_S FP_EPSILON = {0x40000000, -14};
  171. EFLOAT_S FP_ARCTAN_TABLE_SIZE = {0x40000000, 7};
  172. EFLOAT_S FP_PI = {0x6487ed51, 3}; // 3.1415926...
  173. };
  174. #endif
  175. /******************************Public*Routine******************************\
  176. * EFLOAT functions *
  177. * *
  178. * Wrote it. *
  179. \**************************************************************************/
  180. EFLOAT EFLOAT::eqCross(const POINTFL& ptflA, const POINTFL& ptflB)
  181. {
  182. EFLOAT efTmp;
  183. efTmp.eqMul(ptflA.y,ptflB.x);
  184. eqMul(ptflA.x,ptflB.y);
  185. return(eqSub(*this,efTmp));
  186. }
  187. EFLOAT EFLOAT::eqDot(const POINTFL& ptflA, const POINTFL& ptflB)
  188. {
  189. EFLOAT efTmp;
  190. efTmp.eqMul(ptflA.x,ptflB.x);
  191. eqMul(ptflA.y,ptflB.y);
  192. return(eqAdd(*this,efTmp));
  193. }
  194. EFLOAT EFLOAT::eqLength(const POINTFL& ptflA)
  195. {
  196. return(eqSqrt(eqDot(ptflA,ptflA)));
  197. }
  198. /******************************Public*Routine******************************\
  199. * lNormAngle (lAngle) *
  200. * *
  201. * Given an angle in tenths of a degree, returns an equivalent positive *
  202. * angle of less than 360.0 degrees. *
  203. * *
  204. * Sat 21-Mar-1992 12:27:18 -by- Charles Whitmer [chuckwh] *
  205. * Wrote it. *
  206. \**************************************************************************/
  207. LONG lNormAngle(LONG lAngle)
  208. {
  209. if (lAngle >= 3600)
  210. return(lAngle % 3600);
  211. if (lAngle < 0)
  212. return(3599 - ((-lAngle-1) % 3600));
  213. else
  214. return(lAngle);
  215. }