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.
18 /*---------------------------------------------------------------------------*/
20 static void section(int d
,
21 const double p0
[3], const double c0
[4],
22 const double p1
[3], const double c1
[4],
23 const double p2
[3], const double c2
[4])
41 double p01
[3], p12
[3], p20
[3];
42 double c01
[4], c12
[4], c20
[4];
52 c01
[0] = (c0
[0] + c1
[0]) / 2.0;
53 c01
[1] = (c0
[1] + c1
[1]) / 2.0;
54 c01
[2] = (c0
[2] + c1
[2]) / 2.0;
55 c01
[3] = (c0
[3] + c1
[3]) / 2.0;
57 c12
[0] = (c1
[0] + c2
[0]) / 2.0;
58 c12
[1] = (c1
[1] + c2
[1]) / 2.0;
59 c12
[2] = (c1
[2] + c2
[2]) / 2.0;
60 c12
[3] = (c1
[3] + c2
[3]) / 2.0;
62 c20
[0] = (c2
[0] + c0
[0]) / 2.0;
63 c20
[1] = (c2
[1] + c0
[1]) / 2.0;
64 c20
[2] = (c2
[2] + c0
[2]) / 2.0;
65 c20
[3] = (c2
[3] + c0
[3]) / 2.0;
67 section(d
- 1, p0
, c0
, p01
, c01
, p20
, c20
);
68 section(d
- 1, p01
, c01
, p1
, c1
, p12
, c12
);
69 section(d
- 1, p20
, c20
, p12
, c12
, p2
, c2
);
70 section(d
- 1, p01
, c01
, p12
, c12
, p20
, c20
);
74 GLuint
ball_init(int d
)
76 static const float s
[3] = { 1.0f
, 1.0f
, 1.0f
};
78 static const double p
[6][3] = {
86 static const double c
[2][4] = {
87 { 0.0, 0.0, 0.0, 0.5 },
88 { 1.0, 1.0, 1.0, 0.5 },
91 GLuint list
= glGenLists(1);
93 glNewList(list
, GL_COMPILE
);
94 glPushAttrib(GL_LIGHTING_BIT
);
96 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, s
);
97 glMaterialf (GL_FRONT_AND_BACK
, GL_SHININESS
, 64.0f
);
99 glEnable(GL_COLOR_MATERIAL
);
101 glBegin(GL_TRIANGLES
);
103 section(d
, p
[4], c
[0], p
[0], c
[0], p
[2], c
[0]);
104 section(d
, p
[0], c
[1], p
[5], c
[1], p
[2], c
[1]);
105 section(d
, p
[5], c
[0], p
[1], c
[0], p
[2], c
[0]);
106 section(d
, p
[1], c
[1], p
[4], c
[1], p
[2], c
[1]);
108 section(d
, p
[0], c
[1], p
[4], c
[1], p
[3], c
[1]);
109 section(d
, p
[5], c
[0], p
[0], c
[0], p
[3], c
[0]);
110 section(d
, p
[1], c
[1], p
[5], c
[1], p
[3], c
[1]);
111 section(d
, p
[4], c
[0], p
[1], c
[0], p
[3], c
[0]);
121 void ball_draw(GLuint list
, double r
,
123 const double e
[3][3])
127 m_basis(M
, e
[0], e
[1], e
[2]);
129 glPushAttrib(GL_DEPTH_BUFFER_BIT
);
131 glDepthMask(GL_FALSE
);
133 glDisable(GL_TEXTURE_2D
);
136 glTranslated(p
[0], p
[1], p
[2]);
140 glCullFace(GL_FRONT
);
146 glEnable(GL_TEXTURE_2D
);
151 /*---------------------------------------------------------------------------*/