diff options
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/src/face.c')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/src/face.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/src/face.c b/src/others/mimesh/libg3d-0.0.8/src/face.c new file mode 100644 index 0000000..1b796bb --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/src/face.c | |||
@@ -0,0 +1,57 @@ | |||
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 <g3d/types.h> | ||
24 | #include <g3d/vector.h> | ||
25 | |||
26 | #define VERTEX_ITEM(a, b) \ | ||
27 | object->vertex_data[face->vertex_indices[a] * 3 + (b)] | ||
28 | |||
29 | EAPI | ||
30 | void g3d_face_free(G3DFace *face) | ||
31 | { | ||
32 | if(face->vertex_indices) | ||
33 | g_free(face->vertex_indices); | ||
34 | g_free(face); | ||
35 | } | ||
36 | |||
37 | EAPI | ||
38 | gboolean g3d_face_get_normal(G3DFace *face, G3DObject *object, | ||
39 | G3DVector *nx, G3DVector *ny, G3DVector *nz) | ||
40 | { | ||
41 | guint32 n = face->vertex_count - 1; | ||
42 | |||
43 | return g3d_vector_normal( | ||
44 | /* ax, ay, az */ | ||
45 | VERTEX_ITEM(1, 0) - VERTEX_ITEM(0, 0), | ||
46 | VERTEX_ITEM(1, 1) - VERTEX_ITEM(0, 1), | ||
47 | VERTEX_ITEM(1, 2) - VERTEX_ITEM(0, 2), | ||
48 | /* bx, by, bz */ | ||
49 | VERTEX_ITEM(n, 0) - VERTEX_ITEM(0, 0), | ||
50 | VERTEX_ITEM(n, 1) - VERTEX_ITEM(0, 1), | ||
51 | VERTEX_ITEM(n, 2) - VERTEX_ITEM(0, 2), | ||
52 | /* nx, ny, nz */ | ||
53 | nx, ny, nz); | ||
54 | } | ||
55 | |||
56 | #undef VERTEX_ITEM | ||
57 | |||