1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4 
5 This file is part of Quake III Arena source code.
6 
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11 
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 ===========================================================================
21 */
22 #ifndef __MATHLIB__
23 #define __MATHLIB__
24 
25 // mathlib.h
26 
27 #include <math.h>
28 
29 #ifdef DOUBLEVEC_T
30 typedef double vec_t;
31 #else
32 typedef float vec_t;
33 #endif
34 typedef vec_t vec2_t[3];
35 typedef vec_t vec3_t[3];
36 typedef vec_t vec4_t[4];
37 
38 #define	SIDE_FRONT		0
39 #define	SIDE_ON			2
40 #define	SIDE_BACK		1
41 #define	SIDE_CROSS		-2
42 
43 #define	Q_PI	3.14159265358979323846
44 #define DEG2RAD( a ) ( ( (a) * Q_PI ) / 180.0F )
45 #define RAD2DEG( a ) ( ( (a) * 180.0f ) / Q_PI )
46 
47 extern vec3_t vec3_origin;
48 
49 #define	EQUAL_EPSILON	0.001
50 
51 // plane types are used to speed some tests
52 // 0-2 are axial planes
53 #define	PLANE_X			0
54 #define	PLANE_Y			1
55 #define	PLANE_Z			2
56 #define	PLANE_NON_AXIAL	3
57 
58 qboolean VectorCompare( const vec3_t v1, const vec3_t v2 );
59 
60 #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
61 #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
62 #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
63 #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
64 #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
65 #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
66 #define	VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
67 void Vec10Copy( vec_t *in, vec_t *out );
68 
69 vec_t Q_rint (vec_t in);
70 vec_t _DotProduct (vec3_t v1, vec3_t v2);
71 void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
72 void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
73 void _VectorCopy (vec3_t in, vec3_t out);
74 void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
75 
76 double VectorLength( const vec3_t v );
77 
78 void VectorMA( const vec3_t va, double scale, const vec3_t vb, vec3_t vc );
79 
80 void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
81 vec_t VectorNormalize( const vec3_t in, vec3_t out );
82 vec_t ColorNormalize( const vec3_t in, vec3_t out );
83 void VectorInverse (vec3_t v);
84 
85 void ClearBounds (vec3_t mins, vec3_t maxs);
86 void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
87 
88 qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
89 
90 void NormalToLatLong( const vec3_t normal, byte bytes[2] );
91 
92 int	PlaneTypeForNormal (vec3_t normal);
93 
94 #endif
95