diff options
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_acf/imp_acf_wing.c')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/plugins/import/imp_acf/imp_acf_wing.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_acf/imp_acf_wing.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_acf/imp_acf_wing.c new file mode 100644 index 0000000..fd144e5 --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_acf/imp_acf_wing.c | |||
@@ -0,0 +1,79 @@ | |||
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 | #include <string.h> | ||
23 | |||
24 | #include <g3d/types.h> | ||
25 | #include <g3d/face.h> | ||
26 | #include <g3d/vector.h> | ||
27 | |||
28 | #include "imp_acf_airfoil.h" | ||
29 | |||
30 | G3DObject *acf_wing(G3DMaterial *material, const gchar *name, | ||
31 | G3DFloat *msweep, G3DFloat *mdihed, G3DFloat *mtrans, | ||
32 | G3DFloat *vrt, G3DFloat *vtp, | ||
33 | AcfAirfoil *aflrt, AcfAirfoil *afltp, | ||
34 | G3DFloat wrt, G3DFloat wtp, G3DFloat lf) | ||
35 | { | ||
36 | G3DObject *object; | ||
37 | G3DFace *face; | ||
38 | guint32 nverts; | ||
39 | gint32 i; | ||
40 | G3DFloat vec[3]; | ||
41 | |||
42 | nverts = aflrt->vertex_count; | ||
43 | |||
44 | object = g_new0(G3DObject, 1); | ||
45 | object->name = g_strdup(name); | ||
46 | object->vertex_count = nverts * 2; | ||
47 | object->vertex_data = g_new0(G3DFloat, object->vertex_count * 3); | ||
48 | |||
49 | /* vertices */ | ||
50 | for(i = 0; i < nverts; i ++) { | ||
51 | /* wing root */ | ||
52 | vec[2] = aflrt->vertex_data[i * 2 + 0] * wrt; | ||
53 | vec[1] = aflrt->vertex_data[i * 2 + 1] * wrt; | ||
54 | vec[0] = 0.0; | ||
55 | g3d_vector_transform(vec, vec + 1, vec + 2, mdihed); | ||
56 | g3d_vector_transform(vec, vec + 1, vec + 2, mtrans); | ||
57 | memcpy(object->vertex_data + i * 3, vec, sizeof(vec)); | ||
58 | |||
59 | /* wing tip */ | ||
60 | vec[2] = afltp->vertex_data[i * 2 + 0] * wtp; | ||
61 | vec[1] = afltp->vertex_data[i * 2 + 1] * wtp; | ||
62 | vec[0] = 0.0; | ||
63 | g3d_vector_transform(vec, vec + 1, vec + 2, mdihed); | ||
64 | g3d_vector_transform(vec, vec + 1, vec + 2, mtrans); | ||
65 | vec[0] += lf * vtp[0]; | ||
66 | vec[1] += lf * vtp[1]; | ||
67 | vec[2] += lf * vtp[2]; | ||
68 | memcpy(object->vertex_data + (i + nverts) * 3, vec, sizeof(vec)); | ||
69 | } | ||
70 | /* faces */ | ||
71 | for(i = 0; i < (nverts - 1); i ++) { | ||
72 | face = g3d_face_new_tri(material, i + 1, i, i + nverts); | ||
73 | object->faces = g_slist_prepend(object->faces, face); | ||
74 | face = g3d_face_new_tri(material, i + 1, i + nverts + 1, i + nverts); | ||
75 | object->faces = g_slist_prepend(object->faces, face); | ||
76 | } | ||
77 | |||
78 | return object; | ||
79 | } | ||