Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

MATHLIB.H (2845B)


      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 Foobar; 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 typedef float vec_t;
     30 typedef vec_t vec3_t[3];
     31 typedef vec_t vec5_t[5];
     32 
     33 #define	SIDE_FRONT		0
     34 #define	SIDE_ON			2
     35 #define	SIDE_BACK		1
     36 #define	SIDE_CROSS		-2
     37 
     38 #define	Q_PI	3.14159265358979323846
     39 
     40 extern vec3_t vec3_origin;
     41 
     42 #define	EQUAL_EPSILON	0.001
     43 
     44 qboolean VectorCompare (vec3_t v1, vec3_t v2);
     45 
     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 VectorSet(v, a, b, c) {v[0]=a;v[1]=b;v[2]=c;}
     51 
     52 vec_t Q_rint (vec_t in);
     53 vec_t _DotProduct (vec3_t v1, vec3_t v2);
     54 void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
     55 void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
     56 void _VectorCopy (vec3_t in, vec3_t out);
     57 
     58 float VectorLength(vec3_t v);
     59 
     60 void VectorMA (vec3_t va, float scale, vec3_t vb, vec3_t vc);
     61 
     62 void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
     63 vec_t VectorNormalize (vec3_t v);
     64 void VectorInverse (vec3_t v);
     65 void VectorScale (vec3_t v, vec_t scale, vec3_t out);
     66 void VectorPolar(vec3_t v, float radius, float theta, float phi);
     67 void VectorSnap(vec3_t v);
     68 
     69 void _Vector53Copy (vec5_t in, vec3_t out);
     70 void _Vector5Scale (vec5_t v, vec_t scale, vec5_t out);
     71 void _Vector5Add (vec5_t va, vec5_t vb, vec5_t out);
     72 
     73 // NOTE: added these from Ritual's Q3Radiant
     74 void ClearBounds (vec3_t mins, vec3_t maxs);
     75 void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs);
     76 
     77 void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
     78 void VectorToAngles( vec3_t vec, vec3_t angles );
     79 #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
     80 
     81 #define ZERO_EPSILON 1.0E-6
     82 #define RAD2DEG( a ) ( ( (a) * 180.0f ) / Q_PI )
     83 #define DEG2RAD( a ) ( ( (a) * Q_PI ) / 180.0f )
     84 
     85 
     86 #endif