home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / mmath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  2.4 KB  |  100 lines

  1. /* $Id: mmath.h,v 1.4 1997/10/15 00:36:17 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.5
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: mmath.h,v $
  26.  * Revision 1.4  1997/10/15 00:36:17  brianp
  27.  * renamed the FAST/REGULAR_MATH macros
  28.  *
  29.  * Revision 1.3  1997/09/29 22:23:54  brianp
  30.  * added FAST/REGULAR_MATH macros
  31.  *
  32.  * Revision 1.2  1997/05/03 00:54:31  brianp
  33.  * fixed a comment
  34.  *
  35.  * Revision 1.1  1997/05/01 01:42:38  brianp
  36.  * Initial revision
  37.  *
  38.  */
  39.  
  40.  
  41. /*
  42.  * Faster arithmetic functions.  If the FAST_MATH preprocessor symbol is
  43.  * defined on the command line (-DFAST_MATH) then we'll use some (hopefully)
  44.  * faster functions for sqrt(), etc.
  45.  */
  46.  
  47.  
  48. #ifndef MMATH_H
  49. #define MMATH_H
  50.  
  51.  
  52. #include <math.h>
  53.  
  54.  
  55. /*
  56.  * Set the x86 FPU control word to less precision for more speed:
  57.  */
  58. #if defined(__linux__) && defined(__i386__) && defined(FAST_MATH)
  59. #include <i386/fpu_control.h>
  60. #define START_FAST_MATH  __setfpucw(_FPU_SINGLE | _FPU_MASK_IM | _FPU_MASK_DM \
  61.             | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_PM);
  62. #define END_FAST_MATH  __setfpucw(_FPU_EXTENDED | _FPU_MASK_IM | _FPU_MASK_DM \
  63.             | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_PM);
  64. #else
  65. #define START_FAST_MATH
  66. #define END_FAST_MATH
  67. #endif
  68.  
  69.  
  70.  
  71.  
  72. extern float gl_sqrt(float x);
  73.  
  74.  
  75. #ifdef FAST_MATH
  76. #  define GL_SQRT(X)  gl_sqrt(X)
  77. #else
  78. #  define GL_SQRT(X)  sqrt(X)
  79. #endif
  80.  
  81.  
  82. /* Normalize a 3-element vector to unit length */
  83. #define NORMALIZE_3FV( V )                \
  84. {                            \
  85.    GLfloat len;                        \
  86.    len = GL_SQRT(V[0]*V[0]+V[1]*V[1]+V[2]*V[2]);    \
  87.    if (len>0.0001F) {                    \
  88.       len = 1.0F / len;                    \
  89.       V[0] *= len;                    \
  90.       V[1] *= len;                    \
  91.       V[2] *= len;                    \
  92.    }                            \
  93. }
  94.  
  95.  
  96. extern void gl_init_math(void);
  97.  
  98.  
  99. #endif
  100.