aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/src/vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/src/vector.c')
-rw-r--r--src/others/mimesh/libg3d-0.0.8/src/vector.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/src/vector.c b/src/others/mimesh/libg3d-0.0.8/src/vector.c
new file mode 100644
index 0000000..97b3c26
--- /dev/null
+++ b/src/others/mimesh/libg3d-0.0.8/src/vector.c
@@ -0,0 +1,84 @@
1/* $Id$ */
2
3/*
4 libg3d - 3D object loading library
5
6 Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21*/
22
23#include <math.h>
24#include <g3d/types.h>
25
26EAPI
27gboolean g3d_vector_normal(G3DVector ax, G3DVector ay, G3DVector az,
28 G3DVector bx, G3DVector by, G3DVector bz,
29 G3DVector *nx, G3DVector *ny, G3DVector *nz)
30{
31 *nx = ay * bz - az * by;
32 *ny = az * bx - ax * bz;
33 *nz = ax * by - ay * bx;
34
35 return TRUE;
36}
37
38EAPI
39gboolean g3d_vector_unify(G3DVector *nx, G3DVector *ny, G3DVector *nz)
40{
41 G3DFloat r;
42
43 r = sqrt(*nx * *nx + *ny * *ny + *nz * *nz);
44 if(r == 0.0F)
45 *nx = *ny = *nz = 0.0F;
46 else {
47 *nx /= r;
48 *ny /= r;
49 *nz /= r;
50 }
51
52 return TRUE;
53}
54
55EAPI
56gboolean g3d_vector_transform(G3DVector *x, G3DVector *y, G3DVector *z,
57 G3DMatrix *matrix)
58{
59 G3DVector vector[4], result[4];
60 guint32 i, k;
61
62 vector[0] = *x;
63 vector[1] = *y;
64 vector[2] = *z;
65 vector[3] = 1.0;
66
67 for(i = 0; i < 4; i ++) {
68 result[i] = 0.0;
69
70 for(k = 0; k < 4; k ++)
71#if 0
72 result[i] += matrix[i * 4 + k] * vector[k];
73#else
74 result[i] += matrix[k * 4 + i] * vector[k];
75#endif
76 }
77
78 *x = result[0];
79 *y = result[1];
80 *z = result[2];
81
82 return TRUE;
83}
84