wolf_math.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. Copyright (C) 2004 Michael Liebscher
  3. Copyright (C) 2000 by DarkOne the Hacker
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * wolf_math.h: Wolfenstein 3-D math routines.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. *
  21. * Acknowledgement:
  22. * This code was derived from NewWolf, and was originally
  23. * written by DarkOne the Hacker.
  24. *
  25. *
  26. */
  27. /*
  28. Notes:
  29. This module is implemented by wolf_math.c
  30. */
  31. #ifndef __WOLF_MATH_H__
  32. #define __WOLF_MATH_H__
  33. #define FLOATTILE 65536.0f
  34. // Angle Direction Types & LUTs (Hard Coded! Please do not mess them)
  35. typedef enum {q_first, q_second, q_third, q_fourth} quadrant;
  36. typedef enum {dir4_east, dir4_north, dir4_west, dir4_south, dir4_nodir} dir4type;
  37. typedef enum { dir8_east, dir8_northeast, dir8_north, dir8_northwest, dir8_west,
  38. dir8_southwest, dir8_south, dir8_southeast, dir8_nodir} dir8type;
  39. extern char dx4dir[5], dy4dir[5], dx8dir[9], dy8dir[9];
  40. extern dir4type opposite4[5], dir4d[3][3];
  41. extern dir8type opposite8[9], dir4to8[5], diagonal[9][9];
  42. extern int dir8angle[9], dir4angle[5];
  43. // ------------------------- * Vectors * -------------------------
  44. // Vectors & angles for 3D-Space
  45. typedef struct
  46. {
  47. long origin[2];
  48. long angle;
  49. } placeonplane_t;
  50. // ------------------------- * Some Macroses * -------------------------
  51. #define max_of_2(a, b) ((a)>(b)?(a):(b))
  52. #define LABS(x) ((long)(x)>0?(x):-(x))
  53. #define TILE2POS(a) (((a)<<TILESHIFT)+HALFTILE)
  54. #define POS2TILE(a) ((a)>>TILESHIFT)
  55. #define POS2TILEf(a) ((a)/FLOATTILE)
  56. // ------------------------- * vvv FINE angles vvv * -------------------------
  57. #define ASTEP 0.0078125f // 1 FINE=x DEGREES
  58. #define ASTEPRAD 0.000136354f // 1 FINE=x RADIANS
  59. #define ANG_1RAD 7333.8598 // 1 RADIAN=x FINES
  60. #define ANG_0 0 //(int)((float)0/ASTEP)
  61. #define ANG_1 128 //(int)((float)1/ASTEP)
  62. #define ANG_6 768 //(int)((float)6/ASTEP)
  63. #define ANG_15 1920 //(int)((float)15/ASTEP)
  64. #define ANG_22_5 2880 //(int)((float)22.5/ASTEP)
  65. #define ANG_30 3840 //(int)((float)30/ASTEP)
  66. #define ANG_45 5760 //(int)((float)45/ASTEP)
  67. #define ANG_67_5 8640 //(int)((float)67.5/ASTEP)
  68. #define ANG_90 11520 //(int)((float)90/ASTEP)
  69. #define ANG_112_5 14400 //(int)((float)112.5/ASTEP)
  70. #define ANG_135 17280 //(int)((float)135/ASTEP)
  71. #define ANG_157_5 20160 //(int)((float)157.5/ASTEP)
  72. #define ANG_180 23040 //(int)((float)180/ASTEP)
  73. #define ANG_202_5 25920 //(int)((float)202.5/ASTEP)
  74. #define ANG_225 28800 //(int)((float)225/ASTEP)
  75. #define ANG_247_5 31680 //(int)((float)247.5/ASTEP)
  76. #define ANG_270 34560 //(int)((float)270/ASTEP)
  77. #define ANG_292_5 37440 //(int)((float)292.5/ASTEP)
  78. #define ANG_315 40320 //(int)((float)225/ASTEP)
  79. #define ANG_337_5 43200 //(int)((float)337.5/ASTEP)
  80. #define ANG_360 46080 //(int)((float)360/ASTEP)
  81. // ------------------------- * ^^^ FINE angles ^^^ * -------------------------
  82. #define FINE2RAD( a ) (((a) * M_PI ) / ANG_180)
  83. #define RAD2FINE( a ) (((a) * ANG_180) / M_PI)
  84. #define FINE2DEG( a ) ((float)(a) / ANG_1) // !@# don't lose precision bits
  85. #define FINE2DEGf( a ) ((a) / (float)ANG_1)
  86. #define DEG2FINE( a ) ((a) * ANG_1)
  87. extern double SinTable[], *CosTable, TanTable[ ANG_360 + 1 ];
  88. extern int XnextTable[ ANG_360 + 1], YnextTable[ ANG_360 + 1 ];
  89. extern int ColumnAngle[640]; //
  90. extern int G_Build_Tables(void);
  91. #define TanDgr( x ) (tan( DEG2RAD( x ) ))
  92. #define SinDgr( x ) (sin( DEG2RAD( x ) ))
  93. #define CosDgr( x ) (cos( DEG2RAD( x ) ))
  94. #define ArcTanDgr( x ) (RAD2DEG( atan( x ) ))
  95. #define ArcSinDgr( x ) (RAD2DEG( asin( x ) ))
  96. #define ArcCosDgr( x ) (RAD2DEG( acos( x ) ))
  97. extern int NormalizeAngle( int angle );
  98. extern int Point2LineDist( int x, int y, int a );
  99. extern int LineLen2Point( int x, int y, int a );
  100. extern quadrant GetQuadrant( float angle );
  101. extern dir4type Get4dir( float angle );
  102. extern dir8type Get8dir( float angle );
  103. extern float TransformPoint( double Point1X, double Point1Y, double Point2X, double Point2Y );
  104. #endif /* __WOLF_MATH_H__ */