Fixed a build problem.
[gljewel.git] / bucky.c
blob90f16718b317b059a98a6e2951803b34cc095458
1 /**
2 * @file bucky.c
3 * @brief The buckyball-ish 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
21 #include "bucky.h"
23 #if defined(_WIN32) && !defined(__CYGWIN__)
24 # define WIN32_LEAN_AND_MEAN 1
25 # include <windows.h>
26 #endif
28 #include <GL/gl.h>
30 /**
31 * Special predefined values for drawing buckyballs.
33 static GLfloat coords[60][3] = {
34 {-0.449358f,0.730026f,0.514918f},
35 {-0.277718f,0.201774f,0.939234f},
36 {-0.277718f,-0.201774f,0.939234f},
37 {-0.555436f,0.403548f,0.727076f},
38 {-0.555436f,-0.403548f,0.727076f},
39 {-0.833155f,0.201774f,0.514918f},
40 {-0.833155f,-0.201774f,0.514918f},
41 {0.106079f,-0.326477f,0.939234f},
42 {0.212158f,-0.652955f,0.727076f},
43 {-0.449358f,-0.730026f,0.514918f},
44 {-0.065560f,-0.854729f,0.514918f},
45 {0.343279f,0.000000f,0.939234f},
46 {0.686557f,0.000000f,0.727076f},
47 {0.555436f,-0.652955f,0.514918f},
48 {0.792636f,-0.326477f,0.514918f},
49 {0.661515f,0.730026f,-0.171639f},
50 {0.898715f,0.403548f,-0.171639f},
51 {0.489876f,0.854729f,0.171639f},
52 {0.964275f,0.201774f,0.171639f},
53 {0.555436f,0.652955f,0.514918f},
54 {0.792636f,0.326477f,0.514918f},
55 {-0.489876f,0.854729f,-0.171639f},
56 {-0.106079f,0.979432f,-0.171639f},
57 {-0.661515f,0.730026f,0.171639f},
58 {0.106079f,0.979432f,0.171639f},
59 {-0.065560f,0.854729f,0.514918f},
60 {-0.964275f,-0.201774f,-0.171639f},
61 {-0.964275f,0.201774f,-0.171639f},
62 {-0.898715f,-0.403548f,0.171639f},
63 {-0.898715f,0.403548f,0.171639f},
64 {-0.106079f,-0.979432f,-0.171639f},
65 {-0.489876f,-0.854729f,-0.171639f},
66 {0.106079f,-0.979432f,0.171639f},
67 {-0.661515f,-0.730026f,0.171639f},
68 {0.898715f,-0.403548f,-0.171639f},
69 {0.661515f,-0.730026f,-0.171639f},
70 {0.964275f,-0.201774f,0.171639f},
71 {0.489876f,-0.854729f,0.171639f},
72 {0.065560f,0.854729f,-0.514918f},
73 {0.449358f,0.730026f,-0.514918f},
74 {-0.792636f,0.326477f,-0.514918f},
75 {-0.555436f,0.652955f,-0.514918f},
76 {-0.555436f,-0.652955f,-0.514918f},
77 {-0.792636f,-0.326477f,-0.514918f},
78 {0.449358f,-0.730026f,-0.514918f},
79 {0.065560f,-0.854729f,-0.514918f},
80 {0.833155f,0.201774f,-0.514918f},
81 {0.833155f,-0.201774f,-0.514918f},
82 {0.277718f,0.201774f,-0.939234f},
83 {-0.106079f,0.326477f,-0.939234f},
84 {0.555436f,0.403548f,-0.727076f},
85 {-0.212158f,0.652955f,-0.727076f},
86 {-0.343279f,0.000000f,-0.939234f},
87 {-0.686557f,0.000000f,-0.727076f},
88 {-0.106079f,-0.326477f,-0.939234f},
89 {-0.212158f,-0.652955f,-0.727076f},
90 {0.277718f,-0.201774f,-0.939234f},
91 {0.555436f,-0.403548f,-0.727076f},
92 {0.106079f,0.326477f,0.939234f},
93 {0.212158f,0.652955f,0.727076f}
96 /**
97 * Special adjustment value. Only used to draw buckyballs.
99 static float buckyfix;
102 * Generates an OpenGL 1.1 vertex from an index into the bucky coord table.
103 * Only used to draw buckyballs.
105 static void point(int n)
107 glVertex3f(coords[n][0]*buckyfix,coords[n][1]*buckyfix,coords[n][2]*buckyfix);
111 * Calculates the normal of a plane defined by three points? Only used to draw
112 * buckyballs.
114 static void norm(int p1,int p2,int p3)
116 float nx,ny,nz;
117 float x1,y1,z1;
118 float x2,y2,z2;
120 x1=coords[p2][0]-coords[p1][0];
121 y1=coords[p2][1]-coords[p1][1];
122 z1=coords[p2][2]-coords[p1][2];
124 x2=coords[p3][0]-coords[p1][0];
125 y2=coords[p3][1]-coords[p1][1];
126 z2=coords[p3][2]-coords[p1][2];
128 nx=y1*z2-y2*z1;
129 ny=x2*z1-x1*z2;
130 nz=x1*y2-x2*y1;
131 glNormal3f(nx,ny,nz);
136 * Draws a hexagon defined by 6 points. Only used to draw buckyballs.
138 static void hex(int p1,int p2,int p3,int p4,int p5,int p6)
140 norm(p1,p3,p2);
141 glPolygonMode(GL_FRONT,GL_FILL);
142 glBegin(GL_POLYGON);
143 point(p6);
144 point(p5);
145 point(p4);
146 point(p3);
147 point(p2);
148 point(p1);
149 glEnd();
150 glPolygonMode(GL_FRONT,GL_FILL);
154 * Draws a pentagon defined by 5 points. Only used to draw buckyballs.
156 static void pent(int p1,int p2,int p3,int p4,int p5)
158 glBegin(GL_TRIANGLE_STRIP);
159 norm(p1,p3,p2);
160 point(p1);
161 point(p5);
162 point(p2);
163 point(p4);
164 point(p3);
165 glEnd();
169 * Draws a buckyball-ish (a buckyball is 60-sided, this baby is 32-sided).
171 void makebucky(float size)
173 buckyfix=size;
175 glEnable(GL_NORMALIZE);
176 glDisable(GL_TEXTURE_2D);
178 hex(2,7,8,10,9,4);
179 hex(1,2,4,6,5,3);
180 hex(7,11,12,14,13,8);
181 hex(9,10,32,30,31,33);
182 hex(5,6,28,26,27,29);
183 hex(0,25,59,58,1,3);
184 hex(11,58,59,19,20,12);
185 hex(21,22,24,25,00,23);
186 hex(30,32,37,35,44,45);
187 hex(26,28,33,31,42,43);
188 hex(15,17,24,22,38,39);
189 hex(15,16,18,20,19,17);
190 hex(38,51,49,48,50,39);
191 hex(13,14,36,34,35,37);
192 hex(16,46,47,34,36,18);
193 hex(21,23,29,27,40,41);
194 hex(40,53,52,49,51,41);
195 hex(44,57,56,54,55,45);
196 hex(46,50,48,56,57,47);
197 hex(42,55,54,52,53,43);
201 pent(1,58,11,7,2);
202 pent(8,13,37,32,10);
203 pent(4,9,33,28,6);
204 pent(0,3,5,29,23);
205 pent(17,19,59,25,24);
206 pent(12,20,18,36,14);
207 pent(30,45,55,42,31);
208 pent(21,41,51,38,22);
209 pent(48,49,52,54,56);
210 pent(15,39,50,46,16);
211 pent(34,47,57,44,35);
212 pent(26,43,53,40,27);