mathlib.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1997-2006 Id Software, Inc.
  4. This file is part of Quake 2 Tools source code.
  5. Quake 2 Tools 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 2 Tools 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 Quake 2 Tools source code; 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. #define SIDE_FRONT 0
  29. #define SIDE_ON 2
  30. #define SIDE_BACK 1
  31. #define SIDE_CROSS -2
  32. #define Q_PI 3.14159265358979323846
  33. extern vec3_t vec3_origin;
  34. #define EQUAL_EPSILON 0.001
  35. qboolean VectorCompare (vec3_t v1, vec3_t v2);
  36. #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
  37. #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
  38. #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
  39. #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
  40. #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
  41. #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
  42. #define VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
  43. vec_t Q_rint (vec_t in);
  44. vec_t _DotProduct (vec3_t v1, vec3_t v2);
  45. void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
  46. void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
  47. void _VectorCopy (vec3_t in, vec3_t out);
  48. void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
  49. double VectorLength(vec3_t v);
  50. void VectorMA (vec3_t va, double scale, vec3_t vb, vec3_t vc);
  51. void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
  52. vec_t VectorNormalize (vec3_t in, vec3_t out);
  53. vec_t ColorNormalize (vec3_t in, vec3_t out);
  54. void VectorInverse (vec3_t v);
  55. void ClearBounds (vec3_t mins, vec3_t maxs);
  56. void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs);
  57. #endif