Fixed a build problem.
[gljewel.git] / sphere.c
blobbfce965b3537ee3b3d7f09f623079e93df43c9dc
1 /**
2 * @file sphere.c
3 * @brief The snowball 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 "sphere.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 void makeuvsphere(float size)
35 #define USIDES 15
36 #define VSIDES 9
37 float x[USIDES],z[USIDES];
38 int i,j,t,o;
39 float a;
40 float c1,s1,c2,s2;
41 for(i=0;i<USIDES;++i)
43 a=i*PI*2.0f/USIDES;
44 x[i]=cosf(a)*size;
45 z[i]=sinf(a)*size;
48 glEnable(GL_NORMALIZE);
50 for(i=0;i<VSIDES;++i)
52 a=i*PI/VSIDES;
53 c1=cosf(a);
54 s1=sinf(a);
55 a=(i+1)*PI/VSIDES;
56 c2=cosf(a);
57 s2=sinf(a);
58 glBegin(GL_QUAD_STRIP);
59 for(j=0;j<USIDES+1;++j)
61 t=(j<USIDES) ? j : j-USIDES;
62 if(j)
64 float s,c;
65 a=(i+0.5f)*PI/VSIDES;
66 c=cosf(a);
67 s=sinf(a);
68 a=(j-0.5f)*PI*2.0f/USIDES;
69 glNormal3f(cosf(a)*s,c,sinf(a)*s);
71 glVertex3f(x[t]*s2,c2*size,z[t]*s2);
72 glVertex3f(x[t]*s1,c1*size,z[t]*s1);
73 o=t;
75 glEnd();