Fixed a build problem.
[gljewel.git] / diamond.c
blob5748a223e84a8f2105f2f370640b2f973d00808e
1 /**
2 * @file diamond.c
3 * @brief The blood diamond 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 "diamond.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 /** Blood diamonds */
34 void makediamond(float size)
36 #define DSIDES 9
37 float x[DSIDES],z[DSIDES];
38 int i,j,t,o=0;
39 float a;
40 float c,s,d,h;
41 float p2;
42 for(i=0;i<DSIDES;++i)
44 a=i*PI*2.0f/DSIDES;
45 x[i]=cosf(a)*size;
46 z[i]=sinf(a)*size;
49 glEnable(GL_NORMALIZE);
51 p2=size*0.5f;
52 for(t=0;t<2;++t)
54 float p1=(t&1) ? -size : size;
56 glBegin(GL_TRIANGLE_FAN);
57 glVertex3f(0.0, p1, 0.0);
58 d=(!t) ? size-p2 : size+p2;
59 h=sqrtf(size*size+d*d);
60 c=(!t) ? size/h : -size/h;
61 s=d/h;
62 for(i=0;i<DSIDES+1;++i)
64 j=(i<DSIDES) ? i : i-DSIDES;
65 if(!t) j=DSIDES-1-j;
66 if(i)
67 glNormal3f((x[j]+x[o])/2.0f*s,size*c,(z[j]+z[o])/2.0f*s);
68 glVertex3f(x[j],p2,z[j]);
69 o=j;
71 glEnd();