2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
21 // mathlib.c -- math primitives
\r
24 #include "mathlib.h"
\r
26 vec3_t vec3_origin = {0,0,0};
\r
29 double VectorLength(vec3_t v)
\r
35 for (i=0 ; i< 3 ; i++)
\r
36 length += v[i]*v[i];
\r
37 length = sqrt (length); // FIXME
\r
42 qboolean VectorCompare (vec3_t v1, vec3_t v2)
\r
46 for (i=0 ; i<3 ; i++)
\r
47 if (fabs(v1[i]-v2[i]) > EQUAL_EPSILON)
\r
53 vec_t Q_rint (vec_t in)
\r
55 return floor (in + 0.5);
\r
58 void VectorMA (vec3_t va, double scale, vec3_t vb, vec3_t vc)
\r
60 vc[0] = va[0] + scale*vb[0];
\r
61 vc[1] = va[1] + scale*vb[1];
\r
62 vc[2] = va[2] + scale*vb[2];
\r
65 void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross)
\r
67 cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
\r
68 cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
\r
69 cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
\r
72 vec_t _DotProduct (vec3_t v1, vec3_t v2)
\r
74 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
\r
77 void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out)
\r
79 out[0] = va[0]-vb[0];
\r
80 out[1] = va[1]-vb[1];
\r
81 out[2] = va[2]-vb[2];
\r
84 void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out)
\r
86 out[0] = va[0]+vb[0];
\r
87 out[1] = va[1]+vb[1];
\r
88 out[2] = va[2]+vb[2];
\r
91 void _VectorCopy (vec3_t in, vec3_t out)
\r
98 void _VectorScale (vec3_t v, vec_t scale, vec3_t out)
\r
100 out[0] = v[0] * scale;
\r
101 out[1] = v[1] * scale;
\r
102 out[2] = v[2] * scale;
\r
105 vec_t VectorNormalize (vec3_t in, vec3_t out)
\r
107 vec_t length, ilength;
\r
109 length = sqrt (in[0]*in[0] + in[1]*in[1] + in[2]*in[2]);
\r
116 ilength = 1.0/length;
\r
117 out[0] = in[0]*ilength;
\r
118 out[1] = in[1]*ilength;
\r
119 out[2] = in[2]*ilength;
\r
124 vec_t ColorNormalize (vec3_t in, vec3_t out)
\r
139 VectorScale (in, scale, out);
\r
146 void VectorInverse (vec3_t v)
\r
153 void ClearBounds (vec3_t mins, vec3_t maxs)
\r
155 mins[0] = mins[1] = mins[2] = 99999;
\r
156 maxs[0] = maxs[1] = maxs[2] = -99999;
\r
159 void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs)
\r
164 for (i=0 ; i<3 ; i++)
\r