3 * @brief The icosahedron module.
5 * Copyright 2001, 2008 David Ashley <dashxdr@gmail.com>
6 * Copyright 2008 Stephen M. Webb <stephen.webb@bregmasoft.ca>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of Version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #if defined(_WIN32) && !defined(__CYGWIN__)
24 # define WIN32_LEAN_AND_MEAN 1
33 #define X .525731112119133606f
34 #define Z .850650808352039932f
36 static GLfloat vdata
[12][3] = {
37 {-X
, 0.0, Z
}, {X
, 0.0, Z
}, {-X
, 0.0, -Z
},
38 {X
, 0.0, -Z
}, {0.0, Z
, X
}, {0.0, Z
, -X
},
39 {0.0, -Z
, X
}, {0.0, -Z
, -X
}, {Z
, X
, 0.0},
40 {-Z
, X
, 0.0}, {Z
, -X
, 0.0}, {-Z
, -X
, 0.0}
43 static GLuint tindices
[20][3] = {
46 {1, 8, 4}, {1, 10, 8},
47 {10, 3, 8}, {8, 3, 5},
49 {3, 10, 7}, {10, 6, 7},
50 {6, 11, 7}, {6, 0, 11},
51 {6, 1, 0}, {10, 1, 6},
52 {11, 0, 9}, {2, 11, 9},
56 void dup3(float *a
,float *b
)
63 void mid(float *a
,float *b
,float *c
)
66 a
[0]=(*b
++ + *c
++)/2.0f
;
67 a
[1]=(*b
++ + *c
++)/2.0f
;
69 d
=1.0f
/sqrtf(a
[0]*a
[0]+a
[1]*a
[1]+a
[2]*a
[2]);
77 void makeicosahedron(int sub
,float scale
)
87 tris
[j
][0]=vdata
[p
][0];
88 tris
[j
][1]=vdata
[p
][1];
89 tris
[j
][2]=vdata
[p
][2];
92 tris
[j
][0]=vdata
[p
][0];
93 tris
[j
][1]=vdata
[p
][1];
94 tris
[j
][2]=vdata
[p
][2];
97 tris
[j
][0]=vdata
[p
][0];
98 tris
[j
][1]=vdata
[p
][1];
99 tris
[j
][2]=vdata
[p
][2];
112 memcpy(ttt
,tris
[p
],sizeof(ttt
));
114 mid(tris
[q
++],ttt
[0],ttt
[1]);
115 dup3(tris
[q
++],ttt
[1]);
116 mid(tris
[q
++],ttt
[1],ttt
[2]);
118 dup3(tris
[q
++],ttt
[0]);
119 mid(tris
[q
++],ttt
[0],ttt
[1]);
120 mid(tris
[q
++],ttt
[0],ttt
[2]);
122 mid(tris
[q
++],ttt
[1],ttt
[2]);
123 dup3(tris
[q
++],ttt
[2]);
124 mid(tris
[q
++],ttt
[0],ttt
[2]);
126 mid(tris
[q
++],ttt
[0],ttt
[1]);
127 mid(tris
[q
++],ttt
[1],ttt
[2]);
128 mid(tris
[q
++],ttt
[0],ttt
[2]);
132 glEnable(GL_NORMALIZE
);
134 glBegin(GL_TRIANGLES
);
137 norm2(tris
[p
],tris
[p
+1],tris
[p
+2]);
138 glVertex3f(tris
[p
][0]*scale
,tris
[p
][1]*scale
,tris
[p
][2]*scale
);
140 glVertex3f(tris
[p
][0]*scale
,tris
[p
][1]*scale
,tris
[p
][2]*scale
);
142 glVertex3f(tris
[p
][0]*scale
,tris
[p
][1]*scale
,tris
[p
][2]*scale
);