mathlib.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. typedef float vec_t;
  23. typedef vec_t vec3_t[3];
  24. #define SIDE_FRONT 0
  25. #define SIDE_ON 2
  26. #define SIDE_BACK 1
  27. #define SIDE_CROSS -2
  28. #define Q_PI 3.14159265358979323846
  29. extern vec3_t vec3_origin;
  30. #define EQUAL_EPSILON 0.001
  31. qboolean VectorCompare (vec3_t v1, vec3_t v2);
  32. #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
  33. #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
  34. #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
  35. #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
  36. vec_t Q_rint (vec_t in);
  37. vec_t _DotProduct (vec3_t v1, vec3_t v2);
  38. void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
  39. void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
  40. void _VectorCopy (vec3_t in, vec3_t out);
  41. float VectorLength(vec3_t v);
  42. void VectorMA (vec3_t va, float scale, vec3_t vb, vec3_t vc);
  43. void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
  44. vec_t VectorNormalize (vec3_t v);
  45. void VectorInverse (vec3_t v);
  46. void VectorScale (vec3_t v, vec_t scale, vec3_t out);
  47. #endif