Team Fortress 2 Source Code as on 22/4/2020
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.

744 lines
17 KiB

  1. /*
  2. File: GXMath.h
  3. Contains: QuickDraw GX math routine interfaces.
  4. Version: Technology: Quickdraw GX 1.1
  5. Release: QuickTime 7.3
  6. Copyright: (c) 2007 (c) 1994-2006 by Apple Computer, Inc., all rights reserved.
  7. Bugs?: For bug reports, consult the following page on
  8. the World Wide Web:
  9. http://developer.apple.com/bugreporter/
  10. */
  11. #ifndef __GXMATH__
  12. #define __GXMATH__
  13. #ifndef __CONDITIONALMACROS__
  14. #include <ConditionalMacros.h>
  15. #endif
  16. #ifndef __MACTYPES__
  17. #include <MacTypes.h>
  18. #endif
  19. #ifndef __FIXMATH__
  20. #include <FixMath.h>
  21. #endif
  22. #ifndef __IMAGECODEC__
  23. #include <ImageCodec.h>
  24. #endif
  25. #if PRAGMA_ONCE
  26. #pragma once
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #if PRAGMA_IMPORT
  32. #pragma import on
  33. #endif
  34. #if PRAGMA_STRUCT_ALIGN
  35. #pragma options align=mac68k
  36. #elif PRAGMA_STRUCT_PACKPUSH
  37. #pragma pack(push, 2)
  38. #elif PRAGMA_STRUCT_PACK
  39. #pragma pack(2)
  40. #endif
  41. #if defined(__MWERKS__) && TARGET_CPU_68K
  42. #pragma push
  43. #pragma pointers_in_D0
  44. #endif
  45. /* Now defined in ImageCodec.i*/
  46. #if 0
  47. struct gxPoint {
  48. Fixed x;
  49. Fixed y;
  50. };
  51. typedef struct gxPoint gxPoint;
  52. #endif /* 0 */
  53. typedef unsigned short gxColorValue;
  54. struct gxPolar {
  55. Fixed radius;
  56. Fixed angle;
  57. };
  58. typedef struct gxPolar gxPolar;
  59. struct gxMapping {
  60. Fixed map[3][3];
  61. };
  62. typedef struct gxMapping gxMapping;
  63. #define gxColorValue1 ((gxColorValue) 0x0000FFFF)
  64. #define gxPositiveInfinity ((long) 0x7FFFFFFFL)
  65. #define gxNegativeInfinity ((long) 0x80000000L)
  66. #if CALL_NOT_IN_CARBON
  67. /*
  68. * CopyToMapping()
  69. *
  70. * Availability:
  71. * Non-Carbon CFM: not available
  72. * CarbonLib: not available
  73. * Mac OS X: not available
  74. */
  75. EXTERN_API_C( gxMapping * )
  76. CopyToMapping(
  77. gxMapping * target,
  78. const gxMapping * source) THREEWORDINLINE(0x303C, 0x0031, 0xA832);
  79. /*
  80. * InvertMapping()
  81. *
  82. * Availability:
  83. * Non-Carbon CFM: not available
  84. * CarbonLib: not available
  85. * Mac OS X: not available
  86. */
  87. EXTERN_API_C( gxMapping * )
  88. InvertMapping(
  89. gxMapping * target,
  90. const gxMapping * source) THREEWORDINLINE(0x303C, 0x0032, 0xA832);
  91. /*
  92. * MapMapping()
  93. *
  94. * Availability:
  95. * Non-Carbon CFM: not available
  96. * CarbonLib: not available
  97. * Mac OS X: not available
  98. */
  99. EXTERN_API_C( gxMapping * )
  100. MapMapping(
  101. gxMapping * target,
  102. const gxMapping * source) THREEWORDINLINE(0x303C, 0x0033, 0xA832);
  103. /*
  104. * MoveMapping()
  105. *
  106. * Availability:
  107. * Non-Carbon CFM: not available
  108. * CarbonLib: not available
  109. * Mac OS X: not available
  110. */
  111. EXTERN_API_C( gxMapping * )
  112. MoveMapping(
  113. gxMapping * target,
  114. Fixed hOffset,
  115. Fixed vOffset) THREEWORDINLINE(0x303C, 0x0034, 0xA832);
  116. /*
  117. * MoveMappingTo()
  118. *
  119. * Availability:
  120. * Non-Carbon CFM: not available
  121. * CarbonLib: not available
  122. * Mac OS X: not available
  123. */
  124. EXTERN_API_C( gxMapping * )
  125. MoveMappingTo(
  126. gxMapping * target,
  127. Fixed hPosition,
  128. Fixed vPosition) THREEWORDINLINE(0x303C, 0x0035, 0xA832);
  129. /*
  130. * NormalizeMapping()
  131. *
  132. * Availability:
  133. * Non-Carbon CFM: not available
  134. * CarbonLib: not available
  135. * Mac OS X: not available
  136. */
  137. EXTERN_API_C( gxMapping * )
  138. NormalizeMapping(gxMapping * target) THREEWORDINLINE(0x303C, 0x0036, 0xA832);
  139. /*
  140. * RotateMapping()
  141. *
  142. * Availability:
  143. * Non-Carbon CFM: not available
  144. * CarbonLib: not available
  145. * Mac OS X: not available
  146. */
  147. EXTERN_API_C( gxMapping * )
  148. RotateMapping(
  149. gxMapping * target,
  150. Fixed angle,
  151. Fixed xCenter,
  152. Fixed yCenter) THREEWORDINLINE(0x303C, 0x0037, 0xA832);
  153. /*
  154. * ScaleMapping()
  155. *
  156. * Availability:
  157. * Non-Carbon CFM: not available
  158. * CarbonLib: not available
  159. * Mac OS X: not available
  160. */
  161. EXTERN_API_C( gxMapping * )
  162. ScaleMapping(
  163. gxMapping * target,
  164. Fixed hFactor,
  165. Fixed vFactor,
  166. Fixed xCenter,
  167. Fixed yCenter) THREEWORDINLINE(0x303C, 0x0038, 0xA832);
  168. /*
  169. * ResetMapping()
  170. *
  171. * Availability:
  172. * Non-Carbon CFM: not available
  173. * CarbonLib: not available
  174. * Mac OS X: not available
  175. */
  176. EXTERN_API_C( gxMapping * )
  177. ResetMapping(gxMapping * target) THREEWORDINLINE(0x303C, 0x0039, 0xA832);
  178. /*
  179. * SkewMapping()
  180. *
  181. * Availability:
  182. * Non-Carbon CFM: not available
  183. * CarbonLib: not available
  184. * Mac OS X: not available
  185. */
  186. EXTERN_API_C( gxMapping * )
  187. SkewMapping(
  188. gxMapping * target,
  189. Fixed skewX,
  190. Fixed skewY,
  191. Fixed xCenter,
  192. Fixed yCenter) THREEWORDINLINE(0x303C, 0x003A, 0xA832);
  193. /*
  194. * MapPoints()
  195. *
  196. * Availability:
  197. * Non-Carbon CFM: not available
  198. * CarbonLib: not available
  199. * Mac OS X: not available
  200. */
  201. EXTERN_API_C( void )
  202. MapPoints(
  203. const gxMapping * source,
  204. long count,
  205. gxPoint theVector[]) THREEWORDINLINE(0x303C, 0x003B, 0xA832);
  206. /*
  207. * FirstBit()
  208. *
  209. * Availability:
  210. * Non-Carbon CFM: not available
  211. * CarbonLib: not available
  212. * Mac OS X: not available
  213. */
  214. EXTERN_API_C( short )
  215. FirstBit(unsigned long x) THREEWORDINLINE(0x303C, 0x003C, 0xA832);
  216. /*
  217. * WideScale()
  218. *
  219. * Availability:
  220. * Non-Carbon CFM: not available
  221. * CarbonLib: not available
  222. * Mac OS X: not available
  223. */
  224. EXTERN_API_C( short )
  225. WideScale(const wide * source) THREEWORDINLINE(0x303C, 0x003D, 0xA832);
  226. /*
  227. * LinearRoot()
  228. *
  229. * Availability:
  230. * Non-Carbon CFM: not available
  231. * CarbonLib: not available
  232. * Mac OS X: not available
  233. */
  234. EXTERN_API_C( short )
  235. LinearRoot(
  236. Fixed first,
  237. Fixed last,
  238. Fract t[]) THREEWORDINLINE(0x303C, 0x003E, 0xA832);
  239. /*
  240. * QuadraticRoot()
  241. *
  242. * Availability:
  243. * Non-Carbon CFM: not available
  244. * CarbonLib: not available
  245. * Mac OS X: not available
  246. */
  247. EXTERN_API_C( short )
  248. QuadraticRoot(
  249. Fixed first,
  250. Fixed control,
  251. Fixed last,
  252. Fract t[]) THREEWORDINLINE(0x303C, 0x003F, 0xA832);
  253. /*
  254. * PolarToPoint()
  255. *
  256. * Availability:
  257. * Non-Carbon CFM: not available
  258. * CarbonLib: not available
  259. * Mac OS X: not available
  260. */
  261. EXTERN_API_C( gxPoint * )
  262. PolarToPoint(
  263. const gxPolar * ra,
  264. gxPoint * xy) THREEWORDINLINE(0x303C, 0x0040, 0xA832);
  265. /*
  266. * PointToPolar()
  267. *
  268. * Availability:
  269. * Non-Carbon CFM: not available
  270. * CarbonLib: not available
  271. * Mac OS X: not available
  272. */
  273. EXTERN_API_C( gxPolar * )
  274. PointToPolar(
  275. const gxPoint * xy,
  276. gxPolar * ra) THREEWORDINLINE(0x303C, 0x0041, 0xA832);
  277. /*
  278. * FractCubeRoot()
  279. *
  280. * Availability:
  281. * Non-Carbon CFM: not available
  282. * CarbonLib: not available
  283. * Mac OS X: not available
  284. */
  285. EXTERN_API_C( Fract )
  286. FractCubeRoot(Fract source) THREEWORDINLINE(0x303C, 0x0042, 0xA832);
  287. /*
  288. * FractDivide()
  289. *
  290. * Availability:
  291. * Non-Carbon CFM: not available
  292. * CarbonLib: not available
  293. * Mac OS X: not available
  294. */
  295. EXTERN_API_C( Fract )
  296. FractDivide(
  297. Fract dividend,
  298. Fract divisor) THREEWORDINLINE(0x303C, 0x0043, 0xA832);
  299. /*
  300. * FractMultiply()
  301. *
  302. * Availability:
  303. * Non-Carbon CFM: not available
  304. * CarbonLib: not available
  305. * Mac OS X: not available
  306. */
  307. EXTERN_API_C( Fract )
  308. FractMultiply(
  309. Fract multiplicand,
  310. Fract multiplier) THREEWORDINLINE(0x303C, 0x0044, 0xA832);
  311. /*
  312. * FractSineCosine()
  313. *
  314. * Availability:
  315. * Non-Carbon CFM: not available
  316. * CarbonLib: not available
  317. * Mac OS X: not available
  318. */
  319. EXTERN_API_C( Fract )
  320. FractSineCosine(
  321. Fixed degrees,
  322. Fract * cosine) THREEWORDINLINE(0x303C, 0x0045, 0xA832);
  323. /*
  324. * FractSquareRoot()
  325. *
  326. * Availability:
  327. * Non-Carbon CFM: not available
  328. * CarbonLib: not available
  329. * Mac OS X: not available
  330. */
  331. EXTERN_API_C( Fract )
  332. FractSquareRoot(Fract source) THREEWORDINLINE(0x303C, 0x0046, 0xA832);
  333. /*
  334. * FixedDivide()
  335. *
  336. * Availability:
  337. * Non-Carbon CFM: not available
  338. * CarbonLib: not available
  339. * Mac OS X: not available
  340. */
  341. EXTERN_API_C( Fixed )
  342. FixedDivide(
  343. Fixed dividend,
  344. Fixed divisor) THREEWORDINLINE(0x303C, 0x0047, 0xA832);
  345. /*
  346. * FixedMultiply()
  347. *
  348. * Availability:
  349. * Non-Carbon CFM: not available
  350. * CarbonLib: not available
  351. * Mac OS X: not available
  352. */
  353. EXTERN_API_C( Fixed )
  354. FixedMultiply(
  355. Fixed multiplicand,
  356. Fixed multiplier) THREEWORDINLINE(0x303C, 0x0048, 0xA832);
  357. /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  358. /*
  359. * MultiplyDivide()
  360. *
  361. * Availability:
  362. * Non-Carbon CFM: not available
  363. * CarbonLib: not available
  364. * Mac OS X: not available
  365. */
  366. EXTERN_API_C( long )
  367. MultiplyDivide(
  368. long source,
  369. long multiplier,
  370. long divisor) THREEWORDINLINE(0x303C, 0x0049, 0xA832);
  371. /*
  372. * Magnitude()
  373. *
  374. * Availability:
  375. * Non-Carbon CFM: not available
  376. * CarbonLib: not available
  377. * Mac OS X: not available
  378. */
  379. EXTERN_API_C( unsigned long )
  380. Magnitude(
  381. long deltaX,
  382. long deltaY) THREEWORDINLINE(0x303C, 0x004A, 0xA832);
  383. /*
  384. * VectorMultiplyDivide()
  385. *
  386. * Availability:
  387. * Non-Carbon CFM: not available
  388. * CarbonLib: not available
  389. * Mac OS X: not available
  390. */
  391. EXTERN_API_C( long )
  392. VectorMultiplyDivide(
  393. long count,
  394. const long * vector1,
  395. long step1,
  396. const long * vector2,
  397. long step2,
  398. long divisor) THREEWORDINLINE(0x303C, 0x004B, 0xA832);
  399. /* wide operations are defined within FixMath.h for PowerPC */
  400. #endif /* CALL_NOT_IN_CARBON */
  401. #if TARGET_OS_MAC && TARGET_CPU_68K
  402. #if CALL_NOT_IN_CARBON
  403. /*
  404. * WideAdd()
  405. *
  406. * Availability:
  407. * Non-Carbon CFM: not available
  408. * CarbonLib: not available
  409. * Mac OS X: not available
  410. */
  411. EXTERN_API_C( wide * )
  412. WideAdd(
  413. wide * target,
  414. const wide * source) THREEWORDINLINE(0x303C, 0x004C, 0xA832);
  415. /*
  416. * WideCompare()
  417. *
  418. * Availability:
  419. * Non-Carbon CFM: not available
  420. * CarbonLib: not available
  421. * Mac OS X: not available
  422. */
  423. EXTERN_API_C( short )
  424. WideCompare(
  425. const wide * target,
  426. const wide * source) THREEWORDINLINE(0x303C, 0x004D, 0xA832);
  427. /*
  428. * WideNegate()
  429. *
  430. * Availability:
  431. * Non-Carbon CFM: not available
  432. * CarbonLib: not available
  433. * Mac OS X: not available
  434. */
  435. EXTERN_API_C( wide * )
  436. WideNegate(wide * target) THREEWORDINLINE(0x303C, 0x004E, 0xA832);
  437. /*
  438. * WideShift()
  439. *
  440. * Availability:
  441. * Non-Carbon CFM: not available
  442. * CarbonLib: not available
  443. * Mac OS X: not available
  444. */
  445. EXTERN_API_C( wide * )
  446. WideShift(
  447. wide * target,
  448. long shift) THREEWORDINLINE(0x303C, 0x004F, 0xA832);
  449. /*
  450. * WideSquareRoot()
  451. *
  452. * Availability:
  453. * Non-Carbon CFM: not available
  454. * CarbonLib: not available
  455. * Mac OS X: not available
  456. */
  457. EXTERN_API_C( unsigned long )
  458. WideSquareRoot(const wide * source) THREEWORDINLINE(0x303C, 0x0050, 0xA832);
  459. /*
  460. * WideSubtract()
  461. *
  462. * Availability:
  463. * Non-Carbon CFM: not available
  464. * CarbonLib: not available
  465. * Mac OS X: not available
  466. */
  467. EXTERN_API_C( wide * )
  468. WideSubtract(
  469. wide * target,
  470. const wide * source) THREEWORDINLINE(0x303C, 0x0051, 0xA832);
  471. /*
  472. * WideMultiply()
  473. *
  474. * Availability:
  475. * Non-Carbon CFM: not available
  476. * CarbonLib: not available
  477. * Mac OS X: not available
  478. */
  479. EXTERN_API_C( wide * )
  480. WideMultiply(
  481. long multiplicand,
  482. long multiplier,
  483. wide * target) THREEWORDINLINE(0x303C, 0x0052, 0xA832);
  484. /* returns the quotient */
  485. /*
  486. * WideDivide()
  487. *
  488. * Availability:
  489. * Non-Carbon CFM: not available
  490. * CarbonLib: not available
  491. * Mac OS X: not available
  492. */
  493. EXTERN_API_C( long )
  494. WideDivide(
  495. const wide * dividend,
  496. long divisor,
  497. long * remainder) THREEWORDINLINE(0x303C, 0x0053, 0xA832);
  498. /* quotient replaces dividend */
  499. /*
  500. * WideWideDivide()
  501. *
  502. * Availability:
  503. * Non-Carbon CFM: not available
  504. * CarbonLib: not available
  505. * Mac OS X: not available
  506. */
  507. EXTERN_API_C( wide * )
  508. WideWideDivide(
  509. wide * dividend,
  510. long divisor,
  511. long * remainder) THREEWORDINLINE(0x303C, 0x0055, 0xA832);
  512. #endif /* CALL_NOT_IN_CARBON */
  513. #endif /* TARGET_OS_MAC && TARGET_CPU_68K */
  514. #if CALL_NOT_IN_CARBON
  515. /*
  516. * VectorMultiply()
  517. *
  518. * Availability:
  519. * Non-Carbon CFM: not available
  520. * CarbonLib: not available
  521. * Mac OS X: not available
  522. */
  523. EXTERN_API_C( wide * )
  524. VectorMultiply(
  525. long count,
  526. const long * vector1,
  527. long step1,
  528. const long * vector2,
  529. long step2,
  530. wide * dot) THREEWORDINLINE(0x303C, 0x0054, 0xA832);
  531. /*
  532. * RandomBits()
  533. *
  534. * Availability:
  535. * Non-Carbon CFM: not available
  536. * CarbonLib: not available
  537. * Mac OS X: not available
  538. */
  539. EXTERN_API_C( unsigned long )
  540. RandomBits(
  541. long count,
  542. long focus) THREEWORDINLINE(0x303C, 0x0056, 0xA832);
  543. /*
  544. * SetRandomSeed()
  545. *
  546. * Availability:
  547. * Non-Carbon CFM: not available
  548. * CarbonLib: not available
  549. * Mac OS X: not available
  550. */
  551. EXTERN_API_C( void )
  552. SetRandomSeed(const wide * seed) THREEWORDINLINE(0x303C, 0x0057, 0xA832);
  553. /*
  554. * GetRandomSeed()
  555. *
  556. * Availability:
  557. * Non-Carbon CFM: not available
  558. * CarbonLib: not available
  559. * Mac OS X: not available
  560. */
  561. EXTERN_API_C( wide * )
  562. GetRandomSeed(wide * seed) THREEWORDINLINE(0x303C, 0x0058, 0xA832);
  563. #endif /* CALL_NOT_IN_CARBON */
  564. #ifndef FixedRound
  565. #define FixedRound(a) ((short)(((Fixed)(a) + fixed1/2) >> 16))
  566. #endif
  567. #ifndef FixedSquareRoot
  568. #define FixedSquareRoot(a) (((Fixed)FractSquareRoot(a) + 64) >> 7)
  569. #endif
  570. #ifndef FixedTruncate
  571. #define FixedTruncate(a) ((short)((Fixed)(a) >> 16))
  572. #endif
  573. #ifndef FixedToFract
  574. #define FixedToFract(a) ((Fract)(a) << 14)
  575. #endif
  576. #ifndef FractToFixed
  577. #define FractToFixed(a) ((Fixed)(a) + 8192L >> 14)
  578. #endif
  579. #ifndef FixedToInt
  580. #define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16))
  581. #endif
  582. #ifndef IntToFixed
  583. #define IntToFixed(a) ((Fixed)(a) << 16)
  584. #endif
  585. #ifndef FixedToFloat
  586. #define FixedToFloat(a) ((float)(a) / fixed1)
  587. #endif
  588. #ifndef FloatToFixed
  589. #define FloatToFixed(a) ((Fixed)((float)(a) * fixed1))
  590. #endif
  591. #ifndef FractToFloat
  592. #define FractToFloat(a) ((float)(a) / fract1)
  593. #endif
  594. #ifndef FloatToFract
  595. #define FloatToFract(a) ((Fract)((float)(a) * fract1))
  596. #endif
  597. #ifndef ColorToFract
  598. #define ColorToFract(a) (((Fract) (a) << 14) + (((Fract)(a) + 2) >> 2))
  599. #endif
  600. #ifndef FractToColor
  601. #define FractToColor(a) ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  602. #endif
  603. #ifndef ff /* ff is already defined on some platforms */
  604. #define ff(a) IntToFixed(a)
  605. #define fl(a) FloatToFixed(a)
  606. #endif
  607. #if defined(__MWERKS__) && TARGET_CPU_68K
  608. #pragma pop
  609. #endif
  610. #if PRAGMA_STRUCT_ALIGN
  611. #pragma options align=reset
  612. #elif PRAGMA_STRUCT_PACKPUSH
  613. #pragma pack(pop)
  614. #elif PRAGMA_STRUCT_PACK
  615. #pragma pack()
  616. #endif
  617. #ifdef PRAGMA_IMPORT_OFF
  618. #pragma import off
  619. #elif PRAGMA_IMPORT
  620. #pragma import reset
  621. #endif
  622. #ifdef __cplusplus
  623. }
  624. #endif
  625. #endif /* __GXMATH__ */