2 * Copyright (C) 2003 Robert Kooima
4 * SUPER EMPTY BALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
28 /*---------------------------------------------------------------------------*/
30 #define COIN_S "data/png/coin.png"
32 static struct image coin_i
, *coin_p
= &coin_i
;
34 /*---------------------------------------------------------------------------*/
36 GLuint
coin_init(int n
)
38 GLuint list
= glGenLists(1);
40 image_load(coin_p
, COIN_S
);
42 glNewList(list
, GL_COMPILE
);
50 glBegin(GL_TRIANGLE_FAN
);
52 glNormal3d(0.0, 0.0, +1.0);
54 for (i
= 0; i
< n
; i
++)
56 x
= cos(+2.0 * PI
* i
/ n
);
57 y
= sin(+2.0 * PI
* i
/ n
);
59 glTexCoord2d(-0.5 * x
- 0.5, 0.5 * y
- 0.5);
60 glVertex3d(CR
* x
, CR
* y
, +DZ
);
65 glBegin(GL_TRIANGLE_FAN
);
67 glNormal3d(0.0, 0.0, -1.0);
69 for (i
= 0; i
< n
; i
++)
71 x
= cos(-2.0 * PI
* i
/ n
);
72 y
= sin(-2.0 * PI
* i
/ n
);
74 glTexCoord2d(+0.5 * x
- 0.5, 0.5 * y
- 0.5);
75 glVertex3d(CR
* x
, CR
* y
, +DZ
);
80 glBegin(GL_QUAD_STRIP
);
82 for (i
= 0; i
<= n
; i
++)
84 x
= cos(+2.0 * PI
* i
/ n
);
85 y
= sin(+2.0 * PI
* i
/ n
);
87 glNormal3d(x
, y
, 0.0);
88 glVertex3d(CR
* x
, CR
* y
, +DZ
);
89 glVertex3d(CR
* x
, CR
* y
, -DZ
);
99 void coin_draw(GLuint list
, const struct s_coin
*cv
, int cc
)
101 static const float c1
[4] = { 1.0f
, 1.0f
, 0.0f
, 1.0f
};
102 static const float c2
[4] = { 1.0f
, 0.2f
, 0.2f
, 1.0f
};
103 static const float c3
[4] = { 0.2f
, 0.2f
, 1.0f
, 1.0f
};
104 static const float s
[4] = { 1.0f
, 1.0f
, 1.0f
, 1.0f
};
106 double r
= 360.0 * fmod(time_state(), 1.0);
109 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, s
);
111 for (i
= 0; i
< cc
; i
++)
113 if (0 < cv
[i
].n
&& cv
[i
].n
< 5)
114 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, c1
);
116 if (4 < cv
[i
].n
&& cv
[i
].n
< 10)
117 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, c2
);
120 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, c3
);
126 glTranslated(cv
[i
].p
[0],
129 glRotated(r
, 0.0, 1.0, 0.0);
137 int coin_test(const struct s_ball
*up
, struct s_coin
*cv
, int cc
)
141 for (i
= 0; i
< cc
; i
++)
145 v_sub(r
, up
->p
, cv
[i
].p
);
147 if (v_len(r
) < CR
+ up
->r
)
157 /*---------------------------------------------------------------------------*/