Fixed a build problem.
[gljewel.git] / cylinder.c
blob6d79be2d2393dfb4a076280f09f34b5f5ec35005
1 /**
2 * @file cylinder.c
3 * @brief The celerey 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 "cylinder.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>
29 #include <math.h>
30 #include "misc.h"
33 /** Celery stalks */
34 #define CSQUEEZE 0.8f
35 void makecylinder(float size)
37 #define CSIDES 12
38 float x[CSIDES],z[CSIDES];
39 int i,j,k;
40 float a;
41 for(i=0;i<CSIDES;++i)
43 a=i*PI*2.0f/CSIDES;
44 x[i]=cosf(a)*size*CSQUEEZE;
45 z[i]=sinf(a)*size*CSQUEEZE;
48 glEnable(GL_NORMALIZE);
49 for(j=0;j<2;++j)
51 float p=(j&1) ? -size : size;
52 glNormal3f(0.0, p, 0.0);
53 glBegin(GL_POLYGON);
54 for(i=0;i<CSIDES;++i)
56 k=(j&1) ? i : (CSIDES-1-i);
57 glVertex3f(x[k],p,z[k]);
59 glEnd();
61 glBegin(GL_QUAD_STRIP);
62 for(i=0;i<CSIDES+1;++i)
64 j=(i<CSIDES) ? i : i-CSIDES;
65 if(i)
66 glNormal3f((x[j]+x[k])/2.0f,0.0f,(z[j]+z[k])/2.0f);
67 glVertex3f(x[j],-size,z[j]);
68 glVertex3f(x[j], size,z[j]);
69 k=j;
71 glEnd();