MATHLIB.H 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. typedef float vec_t;
  23. typedef vec_t vec3_t[3];
  24. typedef vec_t vec5_t[5];
  25. #define SIDE_FRONT 0
  26. #define SIDE_ON 2
  27. #define SIDE_BACK 1
  28. #define SIDE_CROSS -2
  29. #define Q_PI 3.14159265358979323846
  30. extern vec3_t vec3_origin;
  31. #define EQUAL_EPSILON 0.001
  32. qboolean VectorCompare (vec3_t v1, vec3_t v2);
  33. #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
  34. #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
  35. #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
  36. #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
  37. #define VectorSet(v, a, b, c) {v[0]=a;v[1]=b;v[2]=c;}
  38. vec_t Q_rint (vec_t in);
  39. vec_t _DotProduct (vec3_t v1, vec3_t v2);
  40. void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
  41. void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
  42. void _VectorCopy (vec3_t in, vec3_t out);
  43. float VectorLength(vec3_t v);
  44. void VectorMA (vec3_t va, float scale, vec3_t vb, vec3_t vc);
  45. void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
  46. vec_t VectorNormalize (vec3_t v);
  47. void VectorInverse (vec3_t v);
  48. void VectorScale (vec3_t v, vec_t scale, vec3_t out);
  49. void VectorPolar(vec3_t v, float radius, float theta, float phi);
  50. void VectorSnap(vec3_t v);
  51. void _Vector53Copy (vec5_t in, vec3_t out);
  52. void _Vector5Scale (vec5_t v, vec_t scale, vec5_t out);
  53. void _Vector5Add (vec5_t va, vec5_t vb, vec5_t out);
  54. // NOTE: added these from Ritual's Q3Radiant
  55. void ClearBounds (vec3_t mins, vec3_t maxs);
  56. void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs);
  57. void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
  58. void VectorToAngles( vec3_t vec, vec3_t angles );
  59. #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
  60. #define ZERO_EPSILON 1.0E-6
  61. #define RAD2DEG( a ) ( ( (a) * 180.0f ) / Q_PI )
  62. #define DEG2RAD( a ) ( ( (a) * Q_PI ) / 180.0f )
  63. #endif