home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch7_7 / mactbox / uint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-28  |  3.3 KB  |  145 lines

  1. /* ------------------------------------------------------------------------- *\
  2.    UINT.H :
  3.  
  4.    Definition of an unsigned integer type (and related types)
  5.  
  6.    by Christophe Schlick (1 June 1992)
  7. \* ------------------------------------------------------------------------- */
  8.  
  9. #ifndef _UINT_
  10. #define _UINT_
  11.  
  12. #include "tool.h"
  13.  
  14. /*
  15. ** By default, unsigned integers are defined in double precision (ie ulong)
  16. ** To get single precision, simply add "#define SINGLE_UINT" in your program
  17. */
  18.  
  19. /*
  20. ** Scalar type definition (single or double precision)
  21. */
  22.  
  23. #ifdef SINGLE_UINT
  24.  
  25. typedef unsigned short uint;
  26.  
  27. #define UINT1FILE "%u\n"
  28. #define UINT2FILE "%u %u\n"
  29. #define UINT3FILE "%u %u %u\n"
  30. #define UINT4FILE "%u %u %u %u\n"
  31.  
  32. #else
  33.  
  34. typedef unsigned long uint;
  35.  
  36. #define UINT1FILE "%lu\n"
  37. #define UINT2FILE "%lu %lu\n"
  38. #define UINT3FILE "%lu %lu %lu\n"
  39. #define UINT4FILE "%lu %lu %lu %lu\n"
  40.  
  41. #endif
  42.  
  43. /*
  44. ** Vector type definition
  45. */
  46.  
  47. typedef struct {
  48.   uint x,y;
  49. } uintvec2;                         /* 2D vector of signed integers */
  50.  
  51. typedef struct {
  52.   uint x,y,z;
  53. } uintvec3;                         /* 3D vector of signed integers */
  54.  
  55. typedef struct {
  56.   uint x,y,z,w;
  57. } uintvec4;                         /* 4D vector of signed integers */
  58.  
  59. /*
  60. ** Matrix type definition
  61. */
  62.  
  63. typedef uintvec2 uintmat2[2];       /* 2D matrix of signed integers */
  64.  
  65. typedef uintvec3 uintmat3[3];       /* 3D matrix of signed integers */
  66.  
  67. typedef uintvec4 uintmat4[4];       /* 4D matrix of signed integers */
  68.  
  69. /*
  70. ** Aliases for lazy programmers
  71. */
  72.  
  73. typedef uintvec2 uv2;
  74. typedef uintvec3 uv3;
  75. typedef uintvec4 uv4;
  76. typedef uintmat2 um2;
  77. typedef uintmat3 um3;
  78. typedef uintmat4 um4;
  79.  
  80. /*
  81. ** Get values from file
  82. */
  83.  
  84. #define GET_UINT(File,Var)\
  85.         (fscanf (File, UINT1FILE, &(Var)))
  86.  
  87. #define GET_UINTVEC2(File,Var)\
  88.         (fscanf (File, UINT2FILE, &(Var).x, &(Var).y))
  89.  
  90. #define GET_UINTVEC3(File,Var)\
  91.         (fscanf (File, UINT3FILE, &(Var).x, &(Var).y, &(Var).z))
  92.  
  93. #define GET_UINTVEC4(File,Var)\
  94.         (fscanf (File, UINT4FILE, &(Var).x, &(Var).y, &(Var).z, &(Var).w))
  95.  
  96. #define GET_UINTMAT2(File,Var)\
  97.         (GET_UINTVEC2(File,(Var)[0]),\
  98.          GET_UINTVEC2(File,(Var)[1]))
  99.  
  100. #define GET_UINTMAT3(File,Var)\
  101.         (GET_UINTVEC3(File,(Var)[0]),\
  102.          GET_UINTVEC3(File,(Var)[1]),\
  103.          GET_UINTVEC3(File,(Var)[2]))
  104.  
  105. #define GET_UINTMAT4(File,Var)\
  106.         (GET_UINTVEC4(File,(Var)[0]),\
  107.          GET_UINTVEC4(File,(Var)[1]),\
  108.          GET_UINTVEC4(File,(Var)[2]),\
  109.          GET_UINTVEC4(File,(Var)[3]))
  110.  
  111. /*
  112. ** Put values in file
  113. */
  114.  
  115. #define PUT_UINT(File,Var)\
  116.         (fprintf (File, UINT1FILE, (Var)))
  117.  
  118. #define PUT_UINTVEC2(File,Var)\
  119.         (fprintf (File, UINT2FILE, (Var).x, (Var).y))
  120.  
  121. #define PUT_UINTVEC3(File,Var)\
  122.         (fprintf (File, UINT3FILE, (Var).x, (Var).y, (Var).z))
  123.  
  124. #define PUT_UINTVEC4(File,Var)\
  125.         (fprintf (File, UINT4FILE, (Var).x, (Var).y, (Var).z, (Var).w))
  126.  
  127. #define PUT_UINTMAT2(File,Var)\
  128.         (PUT_UINTVEC2 (File,(Var)[0]),\
  129.          PUT_UINTVEC2 (File,(Var)[1]))
  130.  
  131. #define PUT_UINTMAT3(File,Var)\
  132.         (PUT_UINTVEC3(File,(Var)[0]),\
  133.          PUT_UINTVEC3(File,(Var)[1]),\
  134.          PUT_UINTVEC3(File,(Var)[2]))
  135.  
  136. #define PUT_UINTMAT4(File,Var)\
  137.         (PUT_UINTVEC4(File,(Var)[0]),\
  138.          PUT_UINTVEC4(File,(Var)[1]),\
  139.          PUT_UINTVEC4(File,(Var)[2]),\
  140.          PUT_UINTVEC4(File,(Var)[3]))
  141.  
  142. #endif
  143.  
  144. /* ------------------------------------------------------------------------- */
  145.