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

  1. /* ------------------------------------------------------------------------- *\
  2.    SINT.H :
  3.  
  4.    Definition of a signed integer type (and related types)
  5.  
  6.    by Christophe Schlick (1 June 1992)
  7. \* ------------------------------------------------------------------------- */
  8.  
  9. #ifndef _SINT_
  10. #define _SINT_
  11.  
  12. #include "tool.h"
  13.  
  14. /*
  15. ** By default, signed integers are defined in double precision (ie long)
  16. ** To get single precision, simply add "#define SINGLE_SINT" in your program
  17. */
  18.  
  19. /*
  20. ** Scalar type definition (single or double precision)
  21. */
  22.  
  23. #ifdef SINGLE_SINT
  24.  
  25. typedef short sint;
  26.  
  27. #define SINT1FILE "%d\n"
  28. #define SINT2FILE "%d %d\n"
  29. #define SINT3FILE "%d %d %d\n"
  30. #define SINT4FILE "%d %d %d %d\n"
  31.  
  32. #else
  33.  
  34. typedef long sint;
  35.  
  36. #define SINT1FILE "%ld\n"
  37. #define SINT2FILE "%ld %ld\n"
  38. #define SINT3FILE "%ld %ld %ld\n"
  39. #define SINT4FILE "%ld %ld %ld %ld\n"
  40.  
  41. #endif
  42.  
  43. /*
  44. ** Vector type definition
  45. */
  46.  
  47. typedef struct {
  48.   sint x,y;
  49. } sintvec2;                         /* 2D vector of signed integers */
  50.  
  51. typedef struct {
  52.   sint x,y,z;
  53. } sintvec3;                         /* 3D vector of signed integers */
  54.  
  55. typedef struct {
  56.   sint x,y,z,w;
  57. } sintvec4;                         /* 4D vector of signed integers */
  58.  
  59. /*
  60. ** Matrix type definition
  61. */
  62.  
  63. typedef sintvec2   sintmat2[2];     /* 2D matrix of signed integers */
  64.  
  65. typedef sintvec3   sintmat3[3];     /* 3D matrix of signed integers */
  66.  
  67. typedef sintvec4   sintmat4[4];     /* 4D matrix of signed integers */
  68.  
  69. /*
  70. ** Aliases for lazy programmers
  71. */
  72.  
  73. typedef sintvec2 sv2;
  74. typedef sintvec3 sv3;
  75. typedef sintvec4 sv4;
  76. typedef sintmat2 sm2;
  77. typedef sintmat3 sm3;
  78. typedef sintmat4 sm4;
  79.  
  80. /*
  81. ** Get values from file
  82. */
  83.  
  84. #define GET_SINT(File,Var)\
  85.         (fscanf (File, SINT1FILE, &(Var)))
  86.  
  87. #define GET_SINTVEC2(File,Var)\
  88.         (fscanf (File, SINT2FILE, &(Var).x, &(Var).y))
  89.  
  90. #define GET_SINTVEC3(File,Var)\
  91.         (fscanf (File, SINT3FILE, &(Var).x, &(Var).y, &(Var).z))
  92.  
  93. #define GET_SINTVEC4(File,Var)\
  94.         (fscanf (File, SINT4FILE, &(Var).x, &(Var).y, &(Var).z, &(Var).w))
  95.  
  96. #define GET_SINTMAT2(File,Var)\
  97.         (GET_SINTVEC2(File,(Var)[0]),\
  98.          GET_SINTVEC2(File,(Var)[1]))
  99.  
  100. #define GET_SINTMAT3(File,Var)\
  101.         (GET_SINTVEC3(File,(Var)[0]),\
  102.          GET_SINTVEC3(File,(Var)[1]),\
  103.          GET_SINTVEC3(File,(Var)[2]))
  104.  
  105. #define GET_SINTMAT4(File,Var)\
  106.         (GET_SINTVEC4(File,(Var)[0]),\
  107.          GET_SINTVEC4(File,(Var)[1]),\
  108.          GET_SINTVEC4(File,(Var)[2]),\
  109.          GET_SINTVEC4(File,(Var)[3]))
  110.  
  111. /*
  112. ** Put values in file
  113. */
  114.  
  115. #define PUT_SINT(File,Var)\
  116.         (fprintf (File, SINT1FILE, (Var)))
  117.  
  118. #define PUT_SINTVEC2(File,Var)\
  119.         (fprintf (File, SINT2FILE, (Var).x, (Var).y))
  120.  
  121. #define PUT_SINTVEC3(File,Var)\
  122.         (fprintf (File, SINT3FILE, (Var).x, (Var).y, (Var).z))
  123.  
  124. #define PUT_SINTVEC4(File,Var)\
  125.         (fprintf (File, SINT4FILE, (Var).x, (Var).y, (Var).z, (Var).w))
  126.  
  127. #define PUT_SINTMAT2(File,Var)\
  128.         (PUT_SINTVEC2 (File,(Var)[0]),\
  129.          PUT_SINTVEC2 (File,(Var)[1]))
  130.  
  131. #define PUT_SINTMAT3(File,Var)\
  132.         (PUT_SINTVEC3(File,(Var)[0]),\
  133.          PUT_SINTVEC3(File,(Var)[1]),\
  134.          PUT_SINTVEC3(File,(Var)[2]))
  135.  
  136. #define PUT_SINTMAT4(File,Var)\
  137.         (PUT_SINTVEC4(File,(Var)[0]),\
  138.          PUT_SINTVEC4(File,(Var)[1]),\
  139.          PUT_SINTVEC4(File,(Var)[2]),\
  140.          PUT_SINTVEC4(File,(Var)[3]))
  141.  
  142. #endif
  143.  
  144. /* ------------------------------------------------------------------------- */
  145.