l_math.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #ifndef __MATHLIB__
  19. #define __MATHLIB__
  20. // mathlib.h
  21. #include <math.h>
  22. #ifdef DOUBLEVEC_T
  23. typedef double vec_t;
  24. #else
  25. typedef float vec_t;
  26. #endif
  27. typedef vec_t vec3_t[3];
  28. typedef vec_t vec4_t[4];
  29. #define SIDE_FRONT 0
  30. #define SIDE_ON 2
  31. #define SIDE_BACK 1
  32. #define SIDE_CROSS -2
  33. #define PITCH 0
  34. #define YAW 1
  35. #define ROLL 2
  36. #define Q_PI 3.14159265358979323846
  37. #define DEG2RAD( a ) ( a * M_PI ) / 180.0F
  38. #ifndef M_PI
  39. #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
  40. #endif
  41. extern vec3_t vec3_origin;
  42. #define EQUAL_EPSILON 0.001
  43. qboolean VectorCompare (vec3_t v1, vec3_t v2);
  44. #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
  45. #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
  46. #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
  47. #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
  48. #define Vector4Copy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];}
  49. #define VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
  50. #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
  51. #define VectorNegate(x, y) {y[0]=-x[0];y[1]=-x[1];y[2]=-x[2];}
  52. #define VectorMA(v, s, b, o) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
  53. vec_t Q_rint (vec_t in);
  54. vec_t _DotProduct (vec3_t v1, vec3_t v2);
  55. void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
  56. void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
  57. void _VectorCopy (vec3_t in, vec3_t out);
  58. void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
  59. void _VectorMA(vec3_t va, double scale, vec3_t vb, vec3_t vc);
  60. double VectorLength(vec3_t v);
  61. void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross);
  62. vec_t VectorNormalize(vec3_t inout);
  63. vec_t ColorNormalize(vec3_t in, vec3_t out);
  64. vec_t VectorNormalize2(const vec3_t v, vec3_t out);
  65. void VectorInverse (vec3_t v);
  66. void ClearBounds (vec3_t mins, vec3_t maxs);
  67. void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs);
  68. void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
  69. void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
  70. void RotatePoint(vec3_t point, float matrix[3][3]);
  71. void CreateRotationMatrix(vec3_t angles, float matrix[3][3]);
  72. #endif