home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / SPD.3.0.shar.gz / SPD.3.0.shar / def.h < prev    next >
C/C++ Source or Header  |  1991-01-13  |  2KB  |  81 lines

  1. /*
  2.  * def.h contains some useful definitions for "C" programs.
  3.  *
  4.  * Author:  Eric Haines, 3D/Eye, Inc.
  5.  */
  6.  
  7. /* exit codes - define as you wish */
  8. #define    EXIT_SUCCESS    0
  9. #define    EXIT_FAIL    1
  10.  
  11. #define EPSILON        5.0e-6
  12.  
  13. #ifndef FALSE
  14. #define    FALSE    0
  15. #endif
  16.  
  17. #ifndef NULL
  18. #define    NULL    0
  19. #endif
  20.  
  21. #ifndef TRUE
  22. #define    TRUE    1
  23. #endif
  24.  
  25. #ifndef PI
  26. #define    PI    3.141592653589793
  27. #endif
  28.  
  29. typedef    double    COORD3[3] ;
  30. typedef    double    COORD4[4] ;
  31.  
  32. #define    X    0
  33. #define    Y    1
  34. #define    Z    2
  35. #define    W    3
  36.  
  37. typedef    double        MATRIX[4][4] ;    /* row major form */
  38.  
  39. #define ABSOLUTE(A)        ( (A) < 0 ? -(A) : (A) )
  40. #define    FRACTION(A)        ( (A) - (int)(A) )
  41. #define    IS_VAL_ALMOST_ZERO(A,E)    ( ABSOLUTE(A) <= (E) )
  42. #define    MAX(A,B)        ( (A) > (B) ? (A) : (B) )
  43. #define    MIN(A,B)        ( (A) < (B) ? (A) : (B) )
  44. #define SQR(A)            ( (A) * (A) )
  45.  
  46. #define ADD2_COORD3(r,a)    { (r)[X] += (a)[X]; (r)[Y] += (a)[Y];\
  47.                   (r)[Z] += (a)[Z]; }
  48. #define ADD3_COORD3(r,a,b)    { (r)[X] = (a)[X] + (b)[X];\
  49.                   (r)[Y] = (a)[Y] + (b)[Y];\
  50.                   (r)[Z] = (a)[Z] + (b)[Z]; }
  51. #define COPY_COORD3(r,a)    { (r)[X] = (a)[X];\
  52.                   (r)[Y] = (a)[Y];\
  53.                   (r)[Z] = (a)[Z];}
  54. #define COPY_COORD4(r,a)    { (r)[X] = (a)[X];\
  55.                   (r)[Y] = (a)[Y];\
  56.                   (r)[Z] = (a)[Z];\
  57.                   (r)[W] = (a)[W]; }
  58. #define CROSS(r,a,b)        { (r)[X] = (a)[Y] * (b)[Z] - (a)[Z] * (b)[Y];\
  59.                   (r)[Y] = (a)[Z] * (b)[X] - (a)[X] * (b)[Z];\
  60.                   (r)[Z] = (a)[X] * (b)[Y] - (a)[Y] * (b)[X]; }
  61. #define DOT_PRODUCT(a,b)    ( (a)[X] * (b)[X] +\
  62.                   (a)[Y] * (b)[Y] +\
  63.                   (a)[Z] * (b)[Z] )
  64. #define DOT4(a,b)        ( (a)[X] * (b)[X] +\
  65.                   (a)[Y] * (b)[Y] +\
  66.                   (a)[Z] * (b)[Z] +\
  67.                   (a)[W] * (b)[W] )
  68. #define IS_COORD3_ALMOST_ZERO(a,E)    (\
  69.                      IS_VAL_ALMOST_ZERO( (a)[X], (E) )\
  70.                   && IS_VAL_ALMOST_ZERO( (a)[Y], (E) )\
  71.                   && IS_VAL_ALMOST_ZERO( (a)[Z], (E) ) )
  72. #define MAX_COORD3(a)        ( MAX( MAX( (a)[X], (a)[Y] ), (a)[Z] ) )
  73. #define SET_COORD3(r,A,B,C)    { (r)[X] = (A); (r)[Y] = (B); (r)[Z] = (C); }
  74. #define SET_COORD4(r,A,B,C,D)    { (r)[X] = (A); (r)[Y] = (B); (r)[Z] = (C);\
  75.                   (r)[W] = (D); }
  76. #define SUB2_COORD3(r,a)    { (r)[X] -= (a)[X]; (r)[Y] -= (a)[Y];\
  77.                   (r)[Z] -= (a)[Z]; }
  78. #define SUB3_COORD3(r,a,b)    { (r)[X] = (a)[X] - (b)[X];\
  79.                   (r)[Y] = (a)[Y] - (b)[Y];\
  80.                   (r)[Z] = (a)[Z] - (b)[Z]; }
  81.