2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
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.
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.
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 ===========================================================================
23 // mathlib.c -- math primitives
28 vec3_t vec3_origin = {0.0f,0.0f,0.0f};
31 float VectorLength(vec3_t v)
37 for (i=0 ; i< 3 ; i++)
39 length = (float)sqrt (length);
44 qboolean VectorCompare (vec3_t v1, vec3_t v2)
49 if (fabs(v1[i]-v2[i]) > EQUAL_EPSILON)
55 vec_t Q_rint (vec_t in)
57 return (float)floor (in + 0.5);
60 void VectorMA (vec3_t va, float scale, vec3_t vb, vec3_t vc)
62 vc[0] = va[0] + scale*vb[0];
63 vc[1] = va[1] + scale*vb[1];
64 vc[2] = va[2] + scale*vb[2];
67 void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross)
69 cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
70 cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
71 cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
74 vec_t _DotProduct (vec3_t v1, vec3_t v2)
76 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
79 void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out)
86 void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out)
93 void _VectorCopy (vec3_t in, vec3_t out)
100 vec_t VectorNormalize (vec3_t v)
106 for (i=0 ; i< 3 ; i++)
108 length = (float)sqrt (length);
112 for (i=0 ; i< 3 ; i++)
118 void VectorInverse (vec3_t v)
125 void VectorScale (vec3_t v, vec_t scale, vec3_t out)
127 out[0] = v[0] * scale;
128 out[1] = v[1] * scale;
129 out[2] = v[2] * scale;