1 /*
2 * mathlib.c -- math primitives
3 * $Id: mathlib.c,v 1.4 2008-03-06 18:55:07 sezero Exp $
4 *
5 * Copyright (C) 1996-1997 Id Software, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "q_stdinc.h"
24 #include "compiler.h"
25 #include "arch_def.h"
26 #include "mathlib.h"
27
28 vec3_t vec3_origin = { 0, 0, 0 };
29
30
VectorCompare(vec3_t v1,vec3_t v2)31 qboolean VectorCompare (vec3_t v1, vec3_t v2)
32 {
33 int i;
34
35 for (i = 0; i < 3; i++)
36 {
37 if (fabs(v1[i]-v2[i]) > EQUAL_EPSILON)
38 return false;
39 }
40
41 return true;
42 }
43
Q_rint(vec_t in)44 vec_t Q_rint (vec_t in)
45 {
46 return (vec_t)floor(in + 0.49);
47 }
48
VectorNormalize(vec3_t v)49 vec_t VectorNormalize (vec3_t v)
50 {
51 double length;
52
53 length = VectorLength(v);
54 if (length == 0)
55 return 0;
56
57 v[0] /= length;
58 v[1] /= length;
59 v[2] /= length;
60
61 return (vec_t)length;
62 }
63
64