mathlib.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 vec2_t[3];
  28. typedef vec_t vec3_t[3];
  29. typedef vec_t vec4_t[4];
  30. #define SIDE_FRONT 0
  31. #define SIDE_ON 2
  32. #define SIDE_BACK 1
  33. #define SIDE_CROSS -2
  34. #define Q_PI 3.14159265358979323846
  35. #define DEG2RAD( a ) ( ( (a) * Q_PI ) / 180.0F )
  36. #define RAD2DEG( a ) ( ( (a) * 180.0f ) / Q_PI )
  37. extern vec3_t vec3_origin;
  38. #define EQUAL_EPSILON 0.001
  39. // plane types are used to speed some tests
  40. // 0-2 are axial planes
  41. #define PLANE_X 0
  42. #define PLANE_Y 1
  43. #define PLANE_Z 2
  44. #define PLANE_NON_AXIAL 3
  45. qboolean VectorCompare( const vec3_t v1, const vec3_t v2 );
  46. #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
  47. #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
  48. #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
  49. #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
  50. #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
  51. #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
  52. #define VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
  53. void Vec10Copy( vec_t *in, vec_t *out );
  54. vec_t Q_rint (vec_t in);
  55. vec_t _DotProduct (vec3_t v1, vec3_t v2);
  56. void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
  57. void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
  58. void _VectorCopy (vec3_t in, vec3_t out);
  59. void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
  60. double VectorLength( const vec3_t v );
  61. void VectorMA( const vec3_t va, double scale, const vec3_t vb, vec3_t vc );
  62. void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
  63. vec_t VectorNormalize( const vec3_t in, vec3_t out );
  64. vec_t ColorNormalize( const vec3_t in, 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. qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
  69. void NormalToLatLong( const vec3_t normal, byte bytes[2] );
  70. int PlaneTypeForNormal (vec3_t normal);
  71. #endif