home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Peter's Final Project / src / my_math.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  3.3 KB  |  112 lines  |  [TEXT/KAHL]

  1. /*
  2.  *  Peter's Final Project -- A texture mapping demonstration
  3.  *  © 1995, Peter Mattis
  4.  *
  5.  *  E-mail:
  6.  *  petm@soda.csua.berkeley.edu
  7.  *
  8.  *  Snail-mail:
  9.  *   Peter Mattis
  10.  *   557 Fort Laramie Dr.
  11.  *   Sunnyvale, CA 94087
  12.  *
  13.  *  Avaible from:
  14.  *  http://www.csua.berkeley.edu/~petm/final.html
  15.  *
  16.  *  This program is free software; you can redistribute it and/or modify
  17.  *  it under the terms of the GNU General Public License as published by
  18.  *  the Free Software Foundation; either version 2 of the License, or
  19.  *  (at your option) any later version.
  20.  *
  21.  *  This program is distributed in the hope that it will be useful,
  22.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24.  *  GNU General Public License for more details.
  25.  *
  26.  *  You should have received a copy of the GNU General Public License
  27.  *  along with this program; if not, write to the Free Software
  28.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  */
  30.  
  31. #ifndef __MY_MATH_H__
  32. #define __MY_MATH_H__
  33.  
  34. /*
  35.  * This header file is used to quickly convert from using
  36.  *  fix point math to using floating point math. It contains
  37.  *  defines for doing multiplies, divides, square roots,
  38.  *  conversions, and other stuff that are representation
  39.  *  dependent. Using the defines allows a quick conversion
  40.  *  from using one type to using the other. This can
  41.  *  be useful since on the 68k architecture using fix point
  42.  *  will be faster, but on the PowerPC, using floating point
  43.  *  will probably be faster. (I'm not sure about the PowerPC
  44.  *  since I've never had the opportunity to test this, but
  45.  *  I at least know the two versions are about the same speed
  46.  *  on my IIsi w/ FPU).
  47.  *
  48.  * To use floating point math simply change the 1 in the '#if'
  49.  *  below to a 0.
  50.  */
  51.  
  52. #if 1
  53.  
  54. #include "fixed.h"
  55.  
  56. typedef FIX_NUM NUM;
  57.  
  58. #define my_mul(x, y)        fix_mul((x), (y))
  59. #define my_div(x, y)        fix_div((x), (y))
  60. #define my_sqrt(x)          fix_sqrt(x)
  61. #define my_frac(x)          fix_frac(x)
  62. #define my_floor(x)         fix_floor(x)
  63. #define my_ceil(x)          fix_ceil(x)
  64.  
  65. #define my_num_to_float(x)  fix_to_float(x)
  66. #define my_num_to_int(x)    fix_to_int(x)
  67. #define my_float_to_num(x)  float_to_fix(x)
  68. #define my_int_to_num(x)    int_to_fix(x)
  69. #define my_num_to_fix(x)    (x)
  70. #define my_fix_to_num(x)    (x)
  71.  
  72. #define NUM_ZERO            0
  73. #define NUM_ONE             65536
  74. #define NUM_ONE_HALF        32768
  75. #define NUM_EPSILON         255
  76.  
  77. #else
  78.  
  79. #include <math.h>
  80.  
  81. typedef double NUM;
  82.  
  83. #define my_mul(x, y)        ((x) * (y))
  84. #define my_div(x, y)        ((x) / (y))
  85. #define my_sqrt(x)          ((NUM) sqrt((double) (x)))
  86. #define my_frac(x)          (((x) - (NUM) floor((double) (x))))
  87. #define my_floor(x)         ((NUM) floor((double) (x)))
  88. #define my_ceil(x)          ((NUM) ceil((double) (x)))
  89.  
  90. #define my_num_to_float(x)  (x)
  91. #define my_num_to_int(x)    (x)
  92. #define my_float_to_num(x)  (x)
  93. #define my_int_to_num(x)    (x)
  94. #define my_num_to_fix(x)    float_to_fix(x)
  95. #define my_fix_to_num(x)    fix_to_float(x)
  96.  
  97. #define NUM_ZERO            0.0
  98. #define NUM_ONE             1.0
  99. #define NUM_ONE_HALF        0.5
  100. #define NUM_EPSILON         0.000000001
  101.  
  102. #endif
  103.  
  104. typedef short ANGLE;
  105.  
  106. void my_math_init (void);
  107. void my_math_quit (void);
  108. ANGLE my_normalize_angle (ANGLE);
  109. NUM my_sin (ANGLE);
  110. NUM my_cos (ANGLE);
  111.  
  112. #endif /* __MY_MATH_H__ */