GXMath.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:13k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       GXMath.h
  3.  
  4.      Contains:   QuickDraw GX math routine interfaces.
  5.  
  6.      Version:    Technology: Quickdraw GX 1.1
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1994-2001 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __GXMATH__
  18. #define __GXMATH__
  19. #ifndef __CONDITIONALMACROS__
  20. #include "ConditionalMacros.h"
  21. #endif
  22. #ifndef __MACTYPES__
  23. #include "MacTypes.h"
  24. #endif
  25. #ifndef __FIXMATH__
  26. #include "FixMath.h"
  27. #endif
  28. #if PRAGMA_ONCE
  29. #pragma once
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #if PRAGMA_IMPORT
  35. #pragma import on
  36. #endif
  37. #if PRAGMA_STRUCT_ALIGN
  38.     #pragma options align=mac68k
  39. #elif PRAGMA_STRUCT_PACKPUSH
  40.     #pragma pack(push, 2)
  41. #elif PRAGMA_STRUCT_PACK
  42.     #pragma pack(2)
  43. #endif
  44. #if defined(__MWERKS__) && TARGET_CPU_68K
  45.     #pragma push
  46.     #pragma pointers_in_D0
  47. #endif
  48.  
  49. struct gxPoint {
  50.     Fixed                           x;
  51.     Fixed                           y;
  52. };
  53. typedef struct gxPoint                  gxPoint;
  54. typedef unsigned short                  gxColorValue;
  55. struct gxPolar {
  56.     Fixed                           radius;
  57.     Fixed                           angle;
  58. };
  59. typedef struct gxPolar                  gxPolar;
  60. struct gxMapping {
  61.     Fixed                           map[3][3];
  62. };
  63. typedef struct gxMapping                gxMapping;
  64. #define gxColorValue1           ((gxColorValue) 0x0000FFFF)
  65. #define  gxPositiveInfinity     ((long) 0x7FFFFFFFL)
  66. #define gxNegativeInfinity      ((long) 0x80000000L)
  67. #if CALL_NOT_IN_CARBON
  68. EXTERN_API_C( gxMapping *)
  69. CopyToMapping                   (gxMapping *            target,
  70.                                  const gxMapping *      source)                             THREEWORDINLINE(0x303C, 0x0031, 0xA832);
  71. EXTERN_API_C( gxMapping *)
  72. InvertMapping                   (gxMapping *            target,
  73.                                  const gxMapping *      source)                             THREEWORDINLINE(0x303C, 0x0032, 0xA832);
  74. EXTERN_API_C( gxMapping *)
  75. MapMapping                      (gxMapping *            target,
  76.                                  const gxMapping *      source)                             THREEWORDINLINE(0x303C, 0x0033, 0xA832);
  77. EXTERN_API_C( gxMapping *)
  78. MoveMapping                     (gxMapping *            target,
  79.                                  Fixed                  hOffset,
  80.                                  Fixed                  vOffset)                            THREEWORDINLINE(0x303C, 0x0034, 0xA832);
  81. EXTERN_API_C( gxMapping *)
  82. MoveMappingTo                   (gxMapping *            target,
  83.                                  Fixed                  hPosition,
  84.                                  Fixed                  vPosition)                          THREEWORDINLINE(0x303C, 0x0035, 0xA832);
  85. EXTERN_API_C( gxMapping *)
  86. NormalizeMapping                (gxMapping *            target)                             THREEWORDINLINE(0x303C, 0x0036, 0xA832);
  87. EXTERN_API_C( gxMapping *)
  88. RotateMapping                   (gxMapping *            target,
  89.                                  Fixed                  angle,
  90.                                  Fixed                  xCenter,
  91.                                  Fixed                  yCenter)                            THREEWORDINLINE(0x303C, 0x0037, 0xA832);
  92. EXTERN_API_C( gxMapping *)
  93. ScaleMapping                    (gxMapping *            target,
  94.                                  Fixed                  hFactor,
  95.                                  Fixed                  vFactor,
  96.                                  Fixed                  xCenter,
  97.                                  Fixed                  yCenter)                            THREEWORDINLINE(0x303C, 0x0038, 0xA832);
  98. EXTERN_API_C( gxMapping *)
  99. ResetMapping                    (gxMapping *            target)                             THREEWORDINLINE(0x303C, 0x0039, 0xA832);
  100. EXTERN_API_C( gxMapping *)
  101. SkewMapping                     (gxMapping *            target,
  102.                                  Fixed                  skewX,
  103.                                  Fixed                  skewY,
  104.                                  Fixed                  xCenter,
  105.                                  Fixed                  yCenter)                            THREEWORDINLINE(0x303C, 0x003A, 0xA832);
  106. EXTERN_API_C( void )
  107. MapPoints                       (const gxMapping *      source,
  108.                                  long                   count,
  109.                                  gxPoint                theVector[])                          THREEWORDINLINE(0x303C, 0x003B, 0xA832);
  110. EXTERN_API_C( short )
  111. FirstBit                        (unsigned long          x)                                  THREEWORDINLINE(0x303C, 0x003C, 0xA832);
  112. EXTERN_API_C( short )
  113. WideScale                       (const wide *           source)                             THREEWORDINLINE(0x303C, 0x003D, 0xA832);
  114. EXTERN_API_C( short )
  115. LinearRoot                      (Fixed                  first,
  116.                                  Fixed                  last,
  117.                                  Fract                  t[])                                  THREEWORDINLINE(0x303C, 0x003E, 0xA832);
  118. EXTERN_API_C( short )
  119. QuadraticRoot                   (Fixed                  first,
  120.                                  Fixed                  control,
  121.                                  Fixed                  last,
  122.                                  Fract                  t[])                                  THREEWORDINLINE(0x303C, 0x003F, 0xA832);
  123. EXTERN_API_C( gxPoint *)
  124. PolarToPoint                    (const gxPolar *        ra,
  125.                                  gxPoint *              xy)                                 THREEWORDINLINE(0x303C, 0x0040, 0xA832);
  126. EXTERN_API_C( gxPolar *)
  127. PointToPolar                    (const gxPoint *        xy,
  128.                                  gxPolar *              ra)                                 THREEWORDINLINE(0x303C, 0x0041, 0xA832);
  129. EXTERN_API_C( Fract )
  130. FractCubeRoot                   (Fract                  source)                             THREEWORDINLINE(0x303C, 0x0042, 0xA832);
  131. EXTERN_API_C( Fract )
  132. FractDivide                     (Fract                  dividend,
  133.                                  Fract                  divisor)                            THREEWORDINLINE(0x303C, 0x0043, 0xA832);
  134. EXTERN_API_C( Fract )
  135. FractMultiply                   (Fract                  multiplicand,
  136.                                  Fract                  multiplier)                         THREEWORDINLINE(0x303C, 0x0044, 0xA832);
  137. EXTERN_API_C( Fract )
  138. FractSineCosine                 (Fixed                  degrees,
  139.                                  Fract *                cosine)                             THREEWORDINLINE(0x303C, 0x0045, 0xA832);
  140. EXTERN_API_C( Fract )
  141. FractSquareRoot                 (Fract                  source)                             THREEWORDINLINE(0x303C, 0x0046, 0xA832);
  142. EXTERN_API_C( Fixed )
  143. FixedDivide                     (Fixed                  dividend,
  144.                                  Fixed                  divisor)                            THREEWORDINLINE(0x303C, 0x0047, 0xA832);
  145. EXTERN_API_C( Fixed )
  146. FixedMultiply                   (Fixed                  multiplicand,
  147.                                  Fixed                  multiplier)                         THREEWORDINLINE(0x303C, 0x0048, 0xA832);
  148. /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  149. EXTERN_API_C( long )
  150. MultiplyDivide                  (long                   source,
  151.                                  long                   multiplier,
  152.                                  long                   divisor)                            THREEWORDINLINE(0x303C, 0x0049, 0xA832);
  153. EXTERN_API_C( unsigned long )
  154. Magnitude                       (long                   deltaX,
  155.                                  long                   deltaY)                             THREEWORDINLINE(0x303C, 0x004A, 0xA832);
  156. EXTERN_API_C( long )
  157. VectorMultiplyDivide            (long                   count,
  158.                                  const long *           vector1,
  159.                                  long                   step1,
  160.                                  const long *           vector2,
  161.                                  long                   step2,
  162.                                  long                   divisor)                            THREEWORDINLINE(0x303C, 0x004B, 0xA832);
  163. /* wide operations are defined within FixMath.h for PowerPC */
  164. #endif  /* CALL_NOT_IN_CARBON */
  165. #if TARGET_OS_MAC && TARGET_CPU_68K
  166. #if CALL_NOT_IN_CARBON
  167. EXTERN_API_C( wide *)
  168. WideAdd                         (wide *                 target,
  169.                                  const wide *           source)                             THREEWORDINLINE(0x303C, 0x004C, 0xA832);
  170. EXTERN_API_C( short )
  171. WideCompare                     (const wide *           target,
  172.                                  const wide *           source)                             THREEWORDINLINE(0x303C, 0x004D, 0xA832);
  173. EXTERN_API_C( wide *)
  174. WideNegate                      (wide *                 target)                             THREEWORDINLINE(0x303C, 0x004E, 0xA832);
  175. EXTERN_API_C( wide *)
  176. WideShift                       (wide *                 target,
  177.                                  long                   shift)                              THREEWORDINLINE(0x303C, 0x004F, 0xA832);
  178. EXTERN_API_C( unsigned long )
  179. WideSquareRoot                  (const wide *           source)                             THREEWORDINLINE(0x303C, 0x0050, 0xA832);
  180. EXTERN_API_C( wide *)
  181. WideSubtract                    (wide *                 target,
  182.                                  const wide *           source)                             THREEWORDINLINE(0x303C, 0x0051, 0xA832);
  183. EXTERN_API_C( wide *)
  184. WideMultiply                    (long                   multiplicand,
  185.                                  long                   multiplier,
  186.                                  wide *                 target)                             THREEWORDINLINE(0x303C, 0x0052, 0xA832);
  187. /* returns the quotient */
  188. EXTERN_API_C( long )
  189. WideDivide                      (const wide *           dividend,
  190.                                  long                   divisor,
  191.                                  long *                 remainder)                          THREEWORDINLINE(0x303C, 0x0053, 0xA832);
  192. /* quotient replaces dividend */
  193. EXTERN_API_C( wide *)
  194. WideWideDivide                  (wide *                 dividend,
  195.                                  long                   divisor,
  196.                                  long *                 remainder)                          THREEWORDINLINE(0x303C, 0x0055, 0xA832);
  197. #endif  /* CALL_NOT_IN_CARBON */
  198. #endif  /* TARGET_OS_MAC && TARGET_CPU_68K */
  199. #if CALL_NOT_IN_CARBON
  200. EXTERN_API_C( wide *)
  201. VectorMultiply                  (long                   count,
  202.                                  const long *           vector1,
  203.                                  long                   step1,
  204.                                  const long *           vector2,
  205.                                  long                   step2,
  206.                                  wide *                 dot)                                THREEWORDINLINE(0x303C, 0x0054, 0xA832);
  207. EXTERN_API_C( unsigned long )
  208. RandomBits                      (long                   count,
  209.                                  long                   focus)                              THREEWORDINLINE(0x303C, 0x0056, 0xA832);
  210. EXTERN_API_C( void )
  211. SetRandomSeed                   (const wide *           seed)                               THREEWORDINLINE(0x303C, 0x0057, 0xA832);
  212. EXTERN_API_C( wide *)
  213. GetRandomSeed                   (wide *                 seed)                               THREEWORDINLINE(0x303C, 0x0058, 0xA832);
  214. #endif  /* CALL_NOT_IN_CARBON */
  215. #define FixedRound(a)       ((short)((Fixed)(a) + fixed1/2 >> 16))
  216. #define FixedSquareRoot(a)  ((Fixed)FractSquareRoot(a) + 64 >> 7)
  217. #define FixedTruncate(a)        ((short)((Fixed)(a) >> 16))
  218. #define FixedToFract(a)     ((Fract)(a) << 14)
  219. #define FractToFixed(a)     ((Fixed)(a) + 8192L >> 14)
  220. #define FixedToInt(a)      ((short)((Fixed)(a) + fixed1/2 >> 16))
  221. #define IntToFixed(a)      ((Fixed)(a) << 16)
  222. #define FixedToFloat(a)  ((float)(a) / fixed1)
  223. #define FloatToFixed(a)      ((Fixed)((float)(a) * fixed1))
  224. #define FractToFloat(a)  ((float)(a) / fract1)
  225. #define FloatToFract(a)  ((Fract)((float)(a) * fract1))
  226. #define ColorToFract(a)  (((Fract) (a) << 14) + ((Fract)(a) + 2 >> 2))
  227. #define FractToColor(a)  ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  228. #ifndef ff  /* ff is already defined on some platforms */
  229. #define ff(a)              IntToFixed(a)
  230. #define fl(a)              FloatToFixed(a)
  231. #endif
  232.  
  233. #if defined(__MWERKS__) && TARGET_CPU_68K
  234.     #pragma pop
  235. #endif
  236. #if PRAGMA_STRUCT_ALIGN
  237.     #pragma options align=reset
  238. #elif PRAGMA_STRUCT_PACKPUSH
  239.     #pragma pack(pop)
  240. #elif PRAGMA_STRUCT_PACK
  241.     #pragma pack()
  242. #endif
  243. #ifdef PRAGMA_IMPORT_OFF
  244. #pragma import off
  245. #elif PRAGMA_IMPORT
  246. #pragma import reset
  247. #endif
  248. #ifdef __cplusplus
  249. }
  250. #endif
  251. #endif /* __GXMATH__ */