2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 * Nov 20, 1995 use stdlib's rand()/srand() instead of random()/srand48(), etc.
30 * Modified by Li Wei(liwei@aiar.xjtu.edu.cn) to be able to run in Windows
33 * Modified by Brian Paul to compile with Windows OR Unix. 7/23/97
46 # define RAND_MAX 32767
63 GLenum rgb
, doubleBuffer
;
67 unsigned char rgb_colors
[RINGS
][3];
68 int mapped_colors
[RINGS
];
69 float dests
[RINGS
][3];
70 float offsets
[RINGS
][3];
72 float rotAxis
[RINGS
][3];
77 void FillTorus(float rc
, int numc
, float rt
, int numt
)
84 pi
= 3.14159265358979323846;
87 for (i
= 0; i
< numc
; i
++) {
88 glBegin(GL_QUAD_STRIP
);
89 for (j
= 0; j
<= numt
; j
++) {
90 for (k
= 1; k
>= 0; k
--) {
91 s
= (i
+ k
) % numc
+ 0.5;
94 x
= cos(t
*twopi
/numt
) * cos(s
*twopi
/numc
);
95 y
= sin(t
*twopi
/numt
) * cos(s
*twopi
/numc
);
96 z
= sin(s
*twopi
/numc
);
99 x
= (rt
+ rc
* cos(s
*twopi
/numc
)) * cos(t
*twopi
/numt
);
100 y
= (rt
+ rc
* cos(s
*twopi
/numc
)) * sin(t
*twopi
/numt
);
101 z
= rc
* sin(s
*twopi
/numc
);
109 float Clamp(int iters_left
, float t
)
112 if (iters_left
< 3) {
115 return (iters_left
-2)*t
/iters_left
;
124 for (i
= 0; i
< RINGS
; i
++) {
126 for (j
= 0; j
< 3; j
++) {
127 offsets
[i
][j
] = Clamp(iters
[i
], offsets
[i
][j
]);
129 angs
[i
] = Clamp(iters
[i
], angs
[i
]);
140 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
141 gluLookAt(0,0,10, 0,0,0, 0,1,0);
143 for (i
= 0; i
< RINGS
; i
++) {
145 glColor3ubv(rgb_colors
[i
]);
147 glIndexi(mapped_colors
[i
]);
150 glTranslatef(dests
[i
][0]+offsets
[i
][0], dests
[i
][1]+offsets
[i
][1],
151 dests
[i
][2]+offsets
[i
][2]);
152 glRotatef(angs
[i
], rotAxis
[i
][0], rotAxis
[i
][1], rotAxis
[i
][2]);
153 glCallList(theTorus
);
167 return 10.0 * ( (float) rand() / (float) RAND_MAX
- 0.5 );
170 void GLUTCALLBACK
glut_post_redisplay_p(void)
180 deviation
= MyRand() / 2;
181 deviation
= deviation
* deviation
;
182 for (i
= 0; i
< RINGS
; i
++) {
183 offsets
[i
][0] = MyRand();
184 offsets
[i
][1] = MyRand();
185 offsets
[i
][2] = MyRand();
186 angs
[i
] = 260.0 * MyRand();
187 rotAxis
[i
][0] = MyRand();
188 rotAxis
[i
][1] = MyRand();
189 rotAxis
[i
][2] = MyRand();
190 iters
[i
] = (deviation
* MyRand() + 60.0);
192 glutIdleFunc(glut_post_redisplay_p
);
202 float bottom_y
= 0.0;
204 float bottom_z
= 0.69;
206 static float lmodel_ambient
[] = {0.0, 0.0, 0.0, 0.0};
207 static float lmodel_twoside
[] = {GL_FALSE
};
208 static float lmodel_local
[] = {GL_FALSE
};
209 static float light0_ambient
[] = {0.1, 0.1, 0.1, 1.0};
210 static float light0_diffuse
[] = {1.0, 1.0, 1.0, 0.0};
211 static float light0_position
[] = {0.8660254, 0.5, 1, 0};
212 static float light0_specular
[] = {1.0, 1.0, 1.0, 0.0};
213 static float bevel_mat_ambient
[] = {0.0, 0.0, 0.0, 1.0};
214 static float bevel_mat_shininess
[] = {40.0};
215 static float bevel_mat_specular
[] = {1.0, 1.0, 1.0, 0.0};
216 static float bevel_mat_diffuse
[] = {1.0, 0.0, 0.0, 0.0};
218 srand( (unsigned int) glutGet(GLUT_ELAPSED_TIME
) );
221 for (i
= 0; i
< RINGS
; i
++) {
222 rgb_colors
[i
][0] = rgb_colors
[i
][1] = rgb_colors
[i
][2] = 0;
224 rgb_colors
[BLUERING
][2] = 255;
225 rgb_colors
[REDRING
][0] = 255;
226 rgb_colors
[GREENRING
][1] = 255;
227 rgb_colors
[YELLOWRING
][0] = 255;
228 rgb_colors
[YELLOWRING
][1] = 255;
229 mapped_colors
[BLUERING
] = COLOR_BLUE
;
230 mapped_colors
[REDRING
] = COLOR_RED
;
231 mapped_colors
[GREENRING
] = COLOR_GREEN
;
232 mapped_colors
[YELLOWRING
] = COLOR_YELLOW
;
233 mapped_colors
[BLACKRING
] = COLOR_BLACK
;
235 dests
[BLUERING
][0] = -spacing
;
236 dests
[BLUERING
][1] = top_y
;
237 dests
[BLUERING
][2] = top_z
;
239 dests
[BLACKRING
][0] = 0.0;
240 dests
[BLACKRING
][1] = top_y
;
241 dests
[BLACKRING
][2] = top_z
;
243 dests
[REDRING
][0] = spacing
;
244 dests
[REDRING
][1] = top_y
;
245 dests
[REDRING
][2] = top_z
;
247 dests
[YELLOWRING
][0] = -spacing
/ 2.0;
248 dests
[YELLOWRING
][1] = bottom_y
;
249 dests
[YELLOWRING
][2] = bottom_z
;
251 dests
[GREENRING
][0] = spacing
/ 2.0;
252 dests
[GREENRING
][1] = bottom_y
;
253 dests
[GREENRING
][2] = bottom_z
;
257 theTorus
= glGenLists(1);
258 glNewList(theTorus
, GL_COMPILE
);
259 FillTorus(0.1, 8, 1.0, 25);
265 glEnable(GL_CULL_FACE
);
267 glEnable(GL_DEPTH_TEST
);
271 glClearColor(0.5, 0.5, 0.5, 0.0);
272 glLightfv(GL_LIGHT0
, GL_AMBIENT
, light0_ambient
);
273 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, light0_diffuse
);
274 glLightfv(GL_LIGHT0
, GL_SPECULAR
, light0_specular
);
275 glLightfv(GL_LIGHT0
, GL_POSITION
, light0_position
);
278 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER
, lmodel_local
);
279 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE
, lmodel_twoside
);
280 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, lmodel_ambient
);
281 glEnable(GL_LIGHTING
);
283 glMaterialfv(GL_FRONT
, GL_AMBIENT
, bevel_mat_ambient
);
284 glMaterialfv(GL_FRONT
, GL_SHININESS
, bevel_mat_shininess
);
285 glMaterialfv(GL_FRONT
, GL_SPECULAR
, bevel_mat_specular
);
286 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, bevel_mat_diffuse
);
288 glColorMaterial(GL_FRONT_AND_BACK
, GL_DIFFUSE
);
289 glEnable(GL_COLOR_MATERIAL
);
290 glShadeModel(GL_SMOOTH
);
292 glClearIndex(BACKGROUND
);
293 glShadeModel(GL_FLAT
);
296 glMatrixMode(GL_PROJECTION
);
297 gluPerspective(45, 1.33, 0.1, 100.0);
298 glMatrixMode(GL_MODELVIEW
);
301 void Reshape(int width
, int height
)
304 glViewport(0, 0, width
, height
);
307 void Key(unsigned char key
, int x
, int y
)
319 GLenum
Args(int argc
, char **argv
)
324 doubleBuffer
= GL_TRUE
;
326 for (i
= 1; i
< argc
; i
++) {
327 if (strcmp(argv
[i
], "-ci") == 0) {
329 } else if (strcmp(argv
[i
], "-rgb") == 0) {
331 } else if (strcmp(argv
[i
], "-sb") == 0) {
332 doubleBuffer
= GL_FALSE
;
333 } else if (strcmp(argv
[i
], "-db") == 0) {
334 doubleBuffer
= GL_TRUE
;
336 printf("%s (Bad option).\n", argv
[i
]);
343 int main(int argc
, char **argv
)
347 glutInit(&argc
, argv
);
349 if (Args(argc
, argv
) == GL_FALSE
) {
353 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 300);
356 type
|= (rgb
) ? GLUT_RGB
: GLUT_INDEX
;
357 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
358 glutInitDisplayMode(type
);
360 if (glutCreateWindow("Olympic") == GL_FALSE
) {
368 glutReshapeFunc(Reshape
);
369 glutKeyboardFunc(Key
);
370 glutDisplayFunc(DrawScene
);
371 glutIdleFunc(glut_post_redisplay_p
);