]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake2/extra/common/mathlib.h
Merge branch 'master' into divVerent/farplanedist-sky-fix
[xonotic/netradiant.git] / tools / quake2 / extra / common / mathlib.h
1 /*
2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
4
5 This file is part of Quake 2 Tools source code.
6
7 Quake 2 Tools 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 2 Tools 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 2 Tools 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
23 #ifndef __MATHLIB__
24 #define __MATHLIB__
25
26 // mathlib.h
27
28 #include <math.h>
29
30 #ifdef DOUBLEVEC_T
31 typedef double vec_t;
32 #else
33 typedef float vec_t;
34 #endif
35 typedef vec_t vec3_t[3];
36
37 #define SIDE_FRONT              0
38 #define SIDE_ON                 2
39 #define SIDE_BACK               1
40 #define SIDE_CROSS              -2
41
42 #define Q_PI    3.14159265358979323846
43
44 extern vec3_t vec3_origin;
45
46 #define EQUAL_EPSILON   0.001
47
48 qboolean VectorCompare (vec3_t v1, vec3_t v2);
49
50 #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
51 #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
52 #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
53 #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
54 #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
55 #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
56 #define VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
57
58 vec_t Q_rint (vec_t in);
59 vec_t _DotProduct (vec3_t v1, vec3_t v2);
60 void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
61 void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
62 void _VectorCopy (vec3_t in, vec3_t out);
63 void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
64
65 double VectorLength(vec3_t v);
66
67 void VectorMA (vec3_t va, double scale, vec3_t vb, vec3_t vc);
68
69 void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
70 vec_t VectorNormalize (vec3_t in, vec3_t out);
71 vec_t ColorNormalize (vec3_t in, vec3_t out);
72 void VectorInverse (vec3_t v);
73
74 void ClearBounds (vec3_t mins, vec3_t maxs);
75 void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs);
76
77 #endif