home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src-glu / tess_macros.h < prev    next >
C/C++ Source or Header  |  1999-12-06  |  6KB  |  222 lines

  1. /* $Id: tess_macros.h,v 1.6.2.3 1999/12/05 02:04:31 gareth Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  *
  7.  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  8.  *
  9.  * Permission is hereby granted, free of charge, to any person obtaining a
  10.  * copy of this software and associated documentation files (the "Software"),
  11.  * to deal in the Software without restriction, including without limitation
  12.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13.  * and/or sell copies of the Software, and to permit persons to whom the
  14.  * Software is furnished to do so, subject to the following conditions:
  15.  *
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  *
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  23.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  */
  26.  
  27. /*****************************************************************************
  28.  *
  29.  * GLU 1.3 Polygon Tessellation by Gareth Hughes <garethh@bell-labs.com>
  30.  *
  31.  *****************************************************************************/
  32.  
  33. #ifndef __GLU_TESS_MACROS_H__
  34. #define __GLU_TESS_MACROS_H__
  35.  
  36. #if defined(__GNUC__)
  37. #define INLINE __inline__
  38. #elif defined(__MSC__)
  39. #define INLINE __inline
  40. #else
  41. #define INLINE
  42. #endif
  43.  
  44. #ifndef M_PI
  45. #define M_PI        3.14159265358979323846
  46. #endif
  47.  
  48. #define X    0
  49. #define Y    1
  50. #define Z    2
  51.  
  52. /* Limits: */
  53. #ifndef DBL_MAX
  54. #define DBL_MAX            1e+37
  55. #endif
  56.  
  57. #define MAX_GLDOUBLE        DBL_MAX
  58. #define GLU_TESS_EPSILON    1e-06
  59.  
  60. /* Radians to degrees conversion: */
  61.  
  62. #define DEG_TO_RAD( A )        ( (A) * ( M_PI / 180.0 ) )
  63. #define RAD_TO_DEG( A )        ( (A) * ( 180.0 / M_PI ) )
  64.  
  65. /* Absolute value: */
  66.  
  67. #define ABSI( X )        ( ( (X) < 0 ) ? -(X) : (X) )
  68. #define ABSF( X )        ( ( (X) < 0.0F ) ? -(X) : (X) )
  69. #define ABSD( X )        ( ( (X) < 0.0 ) ? -(X) : (X) )
  70.  
  71. /* Dot product: */
  72.  
  73. #define DOT_3V( A, B )        ( (A)[0]*(B)[0] + (A)[1]*(B)[1] + (A)[2]*(B)[2] )
  74.  
  75. /* Cross product: */
  76.  
  77. #define CROSS_3V( n, u, v )                 \
  78. do {                            \
  79.    (n)[0] = (u)[1]*(v)[2] - (u)[2]*(v)[1];         \
  80.    (n)[1] = (u)[2]*(v)[0] - (u)[0]*(v)[2];         \
  81.    (n)[2] = (u)[0]*(v)[1] - (u)[1]*(v)[0];        \
  82. } while ( 0 )
  83.  
  84. /* Vector clear: */
  85.  
  86. #define ZERO_3V( DST )        (DST)[0] = (DST)[1] = (DST)[2] = 0
  87.  
  88. /* Vector subtract: */
  89.  
  90. #define SUB_2V( DST, SRCA, SRCB )            \
  91. do {                            \
  92.     (DST)[0] = (SRCA)[0] - (SRCB)[0];            \
  93.     (DST)[1] = (SRCA)[1] - (SRCB)[1];            \
  94. } while ( 0 )
  95.  
  96. #define SUB_3V( DST, SRCA, SRCB )            \
  97. do {                            \
  98.     (DST)[0] = (SRCA)[0] - (SRCB)[0];            \
  99.     (DST)[1] = (SRCA)[1] - (SRCB)[1];            \
  100.     (DST)[2] = (SRCA)[2] - (SRCB)[2];            \
  101. } while ( 0 )
  102.  
  103. /* Vector copy: */
  104.  
  105. #define COPY_3V( DST, SRC )                \
  106. do {                            \
  107.     (DST)[0] = (SRC)[0];                \
  108.     (DST)[1] = (SRC)[1];                \
  109.     (DST)[2] = (SRC)[2];                \
  110. } while ( 0 )
  111.  
  112. /* Vector negate: */
  113.  
  114. #define NEG_3V( DST )                    \
  115. do {                            \
  116.     (DST)[0] = -(DST)[0];                \
  117.     (DST)[1] = -(DST)[1];                \
  118.     (DST)[2] = -(DST)[2];                \
  119. } while ( 0 )
  120.  
  121. /* Assign scalers to short vectors: */
  122.  
  123. #define ASSIGN_3V( V, V0, V1, V2 )             \
  124. do {                             \
  125.     V[0] = V0;                        \
  126.     V[1] = V1;                        \
  127.     V[2] = V2;                        \
  128. } while ( 0 )
  129.  
  130. #define ASSIGN_4V( V, V0, V1, V2, V3 )             \
  131. do {                             \
  132.     V[0] = V0;                        \
  133.     V[1] = V1;                        \
  134.     V[2] = V2;                        \
  135.     V[3] = V3;                         \
  136. } while ( 0 )
  137.  
  138. /* Comparison: */
  139.  
  140. #define IS_EQUAL( A, B )    ( ABSD( (A) - (B) ) < GLU_TESS_EPSILON )
  141.  
  142. #define IS_EQUAL_3DV( A, B )                \
  143. ( ( ABSD( (A)[X] - (B)[X] ) < GLU_TESS_EPSILON ) &&    \
  144.   ( ABSD( (A)[Y] - (B)[Y] ) < GLU_TESS_EPSILON ) &&    \
  145.   ( ABSD( (A)[Z] - (B)[Z] ) < GLU_TESS_EPSILON ) )
  146.  
  147. #define IS_ZERO_3DV( A )                \
  148. ( ( ABSD( (A)[X] ) < GLU_TESS_EPSILON ) &&        \
  149.   ( ABSD( (A)[Y] ) < GLU_TESS_EPSILON ) &&        \
  150.   ( ABSD( (A)[Z] ) < GLU_TESS_EPSILON ) )
  151.  
  152. #define IS_LEQ( A, B )        ( ( (A) - (B) ) < GLU_TESS_EPSILON )
  153.  
  154. /* Length: */
  155.  
  156. #define LEN_SCALAR( V1, V2 )    ( sqrt( (V1)*(V1) + (V2)*(V2) ) )
  157.  
  158. #define NORMALIZE_3DV( V )                \
  159. do {                            \
  160.     GLdouble len = LEN_SQUARED_3DV(V);            \
  161.     if (len > 1e-50) {                    \
  162.     len = 1.0 / sqrt(len);                \
  163.     V[0] = (GLfloat) (V[0] * len);            \
  164.     V[1] = (GLfloat) (V[1] * len);            \
  165.     V[2] = (GLfloat) (V[2] * len);            \
  166.     }                            \
  167. } while ( 0 )
  168.  
  169. #define LEN_3DV( V )        ( sqrt( V[0]*V[0] + V[1]*V[1] + V[2]*V[2] ) )
  170.  
  171. #define LEN_SQUARED_3DV( V )    ( V[0]*V[0] + V[1]*V[1] + V[2]*V[2] )
  172.  
  173. #define NORMALIZE_2DV( V )                \
  174. do {                            \
  175.    GLdouble len = LEN_SQUARED_2DV( V );            \
  176.    if ( len > 1e-50 ) {                    \
  177.       len = 1.0 / sqrt( len );                \
  178.       (V)[0] *= len;                    \
  179.       (V)[1] *= len;                    \
  180.    }                            \
  181. } while ( 0 )
  182.  
  183. #define LEN_2DV( V )        ( sqrt( (V)[0]*(V)[0] + (V)[1]*(V)[1] ) )
  184.  
  185. #define LEN_SQUARED_2DV( V )    ( (V)[0]*(V)[0] + (V)[1]*(V)[1] )
  186.  
  187.  
  188. /* Bounding boxes: */
  189.  
  190. #define CLEAR_BBOX_2DV( MINS, MAXS )            \
  191. do {                            \
  192.     (MINS)[X] = (MINS)[Y] = MAX_GLDOUBLE;        \
  193.     (MAXS)[X] = (MAXS)[Y] = -MAX_GLDOUBLE;        \
  194. } while ( 0 )
  195.  
  196. #define ACC_BBOX_2V( V, MINS, MAXS )            \
  197. do {                            \
  198.     if ( (V)[X] < (MINS)[X] ) {                \
  199.     (MINS)[X] = (V)[X];                \
  200.     }                            \
  201.     if ( (V)[X] > (MAXS)[X] ) {                \
  202.     (MAXS)[X] = (V)[X];                \
  203.     }                            \
  204.     if ( (V)[Y] < (MINS)[Y] ) {                \
  205.     (MINS)[Y] = (V)[Y];                \
  206.     }                            \
  207.     if ( (V)[Y] > (MAXS)[Y] ) {                \
  208.     (MAXS)[Y] = (V)[Y];                \
  209.     }                            \
  210. } while ( 0 )
  211.  
  212. /* Test if bbox B is inside bbox A: */
  213. #define CONTAINS_BBOX_2V( AMINS, AMAXS, BMINS, BMAXS )            \
  214. ( ( (AMINS)[X] < (BMINS)[X] ) && ( (AMINS)[Y] < (BMINS)[Y] ) &&        \
  215.   ( (AMAXS)[X] > (BMAXS)[X] ) && ( (AMAXS)[Y] > (BMAXS)[Y] ) )
  216.  
  217. #define INSIDE_BBOX_2V( V, MINS, MAXS )            \
  218. ( ( (MINS)[X] < (V)[X] ) && ( (MINS)[Y] < (V)[Y] ) &&    \
  219.   ( (MAXS)[X] > (V)[X] ) && ( (MAXS)[Y] > (V)[Y] ) )
  220.  
  221. #endif /* __GLU_TESS_MACROS_H__ */
  222.