00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __MATHLIB__
00023 #define __MATHLIB__
00024
00025
00026
00027 #include <math.h>
00028
00029 #ifdef DOUBLEVEC_T
00030 typedef double vec_t;
00031 #else
00032 typedef float vec_t;
00033 #endif
00034 typedef vec_t vec2_t[3];
00035 typedef vec_t vec3_t[3];
00036 typedef vec_t vec4_t[4];
00037
00038 #define SIDE_FRONT 0
00039 #define SIDE_ON 2
00040 #define SIDE_BACK 1
00041 #define SIDE_CROSS -2
00042
00043 #define Q_PI 3.14159265358979323846
00044 #define DEG2RAD( a ) ( ( (a) * Q_PI ) / 180.0F )
00045 #define RAD2DEG( a ) ( ( (a) * 180.0f ) / Q_PI )
00046
00047 extern vec3_t vec3_origin;
00048
00049 #define EQUAL_EPSILON 0.001
00050
00051
00052
00053 #define PLANE_X 0
00054 #define PLANE_Y 1
00055 #define PLANE_Z 2
00056 #define PLANE_NON_AXIAL 3
00057
00058 qboolean VectorCompare( const vec3_t v1, const vec3_t v2 );
00059
00060 #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
00061 #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
00062 #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
00063 #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
00064 #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
00065 #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
00066 #define VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
00067 void Vec10Copy( vec_t *in, vec_t *out );
00068
00069 vec_t Q_rint (vec_t in);
00070 vec_t _DotProduct (vec3_t v1, vec3_t v2);
00071 void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
00072 void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
00073 void _VectorCopy (vec3_t in, vec3_t out);
00074 void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
00075
00076 double VectorLength( const vec3_t v );
00077
00078 void VectorMA( const vec3_t va, double scale, const vec3_t vb, vec3_t vc );
00079
00080 void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
00081 vec_t VectorNormalize( const vec3_t in, vec3_t out );
00082 vec_t ColorNormalize( const vec3_t in, vec3_t out );
00083 void VectorInverse (vec3_t v);
00084
00085 void ClearBounds (vec3_t mins, vec3_t maxs);
00086 void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
00087
00088 qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
00089
00090 void NormalToLatLong( const vec3_t normal, byte bytes[2] );
00091
00092 int PlaneTypeForNormal (vec3_t normal);
00093
00094 #endif