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
)
111 if (iters_left
< 3) {
114 return (iters_left
-2)*t
/iters_left
;
121 static double t0
= -1.;
123 t
= glutGet(GLUT_ELAPSED_TIME
) / 1000.;
134 for (i
= 0; i
< RINGS
; i
++) {
136 for (j
= 0; j
< 3; j
++) {
137 offsets
[i
][j
] = Clamp(iters
[i
], offsets
[i
][j
]);
139 angs
[i
] = Clamp(iters
[i
], angs
[i
]);
150 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
151 gluLookAt(0,0,10, 0,0,0, 0,1,0);
153 for (i
= 0; i
< RINGS
; i
++) {
155 glColor3ubv(rgb_colors
[i
]);
157 glIndexi(mapped_colors
[i
]);
160 glTranslatef(dests
[i
][0]+offsets
[i
][0], dests
[i
][1]+offsets
[i
][1],
161 dests
[i
][2]+offsets
[i
][2]);
162 glRotatef(angs
[i
], rotAxis
[i
][0], rotAxis
[i
][1], rotAxis
[i
][2]);
163 glCallList(theTorus
);
177 return 10.0 * ( (float) rand() / (float) RAND_MAX
- 0.5 );
180 #if !defined(GLUTCALLBACK)
184 void GLUTCALLBACK
glut_post_redisplay_p(void)
194 deviation
= MyRand() / 2;
195 deviation
= deviation
* deviation
;
196 for (i
= 0; i
< RINGS
; i
++) {
197 offsets
[i
][0] = MyRand();
198 offsets
[i
][1] = MyRand();
199 offsets
[i
][2] = MyRand();
200 angs
[i
] = 260.0 * MyRand();
201 rotAxis
[i
][0] = MyRand();
202 rotAxis
[i
][1] = MyRand();
203 rotAxis
[i
][2] = MyRand();
204 iters
[i
] = (deviation
* MyRand() + 60.0);
206 glutIdleFunc(glut_post_redisplay_p
);
216 float bottom_y
= 0.0;
218 float bottom_z
= 0.69;
220 static float lmodel_ambient
[] = {0.0, 0.0, 0.0, 0.0};
221 static float lmodel_twoside
[] = {GL_FALSE
};
222 static float lmodel_local
[] = {GL_FALSE
};
223 static float light0_ambient
[] = {0.1, 0.1, 0.1, 1.0};
224 static float light0_diffuse
[] = {1.0, 1.0, 1.0, 0.0};
225 static float light0_position
[] = {0.8660254, 0.5, 1, 0};
226 static float light0_specular
[] = {1.0, 1.0, 1.0, 0.0};
227 static float bevel_mat_ambient
[] = {0.0, 0.0, 0.0, 1.0};
228 static float bevel_mat_shininess
[] = {40.0};
229 static float bevel_mat_specular
[] = {1.0, 1.0, 1.0, 0.0};
230 static float bevel_mat_diffuse
[] = {1.0, 0.0, 0.0, 0.0};
232 srand( (unsigned int) glutGet(GLUT_ELAPSED_TIME
) );
235 for (i
= 0; i
< RINGS
; i
++) {
236 rgb_colors
[i
][0] = rgb_colors
[i
][1] = rgb_colors
[i
][2] = 0;
238 rgb_colors
[BLUERING
][2] = 255;
239 rgb_colors
[REDRING
][0] = 255;
240 rgb_colors
[GREENRING
][1] = 255;
241 rgb_colors
[YELLOWRING
][0] = 255;
242 rgb_colors
[YELLOWRING
][1] = 255;
243 mapped_colors
[BLUERING
] = COLOR_BLUE
;
244 mapped_colors
[REDRING
] = COLOR_RED
;
245 mapped_colors
[GREENRING
] = COLOR_GREEN
;
246 mapped_colors
[YELLOWRING
] = COLOR_YELLOW
;
247 mapped_colors
[BLACKRING
] = COLOR_BLACK
;
249 dests
[BLUERING
][0] = -spacing
;
250 dests
[BLUERING
][1] = top_y
;
251 dests
[BLUERING
][2] = top_z
;
253 dests
[BLACKRING
][0] = 0.0;
254 dests
[BLACKRING
][1] = top_y
;
255 dests
[BLACKRING
][2] = top_z
;
257 dests
[REDRING
][0] = spacing
;
258 dests
[REDRING
][1] = top_y
;
259 dests
[REDRING
][2] = top_z
;
261 dests
[YELLOWRING
][0] = -spacing
/ 2.0;
262 dests
[YELLOWRING
][1] = bottom_y
;
263 dests
[YELLOWRING
][2] = bottom_z
;
265 dests
[GREENRING
][0] = spacing
/ 2.0;
266 dests
[GREENRING
][1] = bottom_y
;
267 dests
[GREENRING
][2] = bottom_z
;
271 theTorus
= glGenLists(1);
272 glNewList(theTorus
, GL_COMPILE
);
273 FillTorus(0.1, 8, 1.0, 25);
279 glEnable(GL_CULL_FACE
);
281 glEnable(GL_DEPTH_TEST
);
285 glClearColor(0.5, 0.5, 0.5, 0.0);
286 glLightfv(GL_LIGHT0
, GL_AMBIENT
, light0_ambient
);
287 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, light0_diffuse
);
288 glLightfv(GL_LIGHT0
, GL_SPECULAR
, light0_specular
);
289 glLightfv(GL_LIGHT0
, GL_POSITION
, light0_position
);
292 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER
, lmodel_local
);
293 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE
, lmodel_twoside
);
294 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, lmodel_ambient
);
295 glEnable(GL_LIGHTING
);
297 glMaterialfv(GL_FRONT
, GL_AMBIENT
, bevel_mat_ambient
);
298 glMaterialfv(GL_FRONT
, GL_SHININESS
, bevel_mat_shininess
);
299 glMaterialfv(GL_FRONT
, GL_SPECULAR
, bevel_mat_specular
);
300 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, bevel_mat_diffuse
);
302 glColorMaterial(GL_FRONT_AND_BACK
, GL_DIFFUSE
);
303 glEnable(GL_COLOR_MATERIAL
);
304 glShadeModel(GL_SMOOTH
);
306 glClearIndex(BACKGROUND
);
307 glShadeModel(GL_FLAT
);
310 glMatrixMode(GL_PROJECTION
);
311 gluPerspective(45, 1.33, 0.1, 100.0);
312 glMatrixMode(GL_MODELVIEW
);
315 void Reshape(int width
, int height
)
318 glViewport(0, 0, width
, height
);
321 void Key(unsigned char key
, int x
, int y
)
333 GLenum
Args(int argc
, char **argv
)
338 doubleBuffer
= GL_TRUE
;
340 for (i
= 1; i
< argc
; i
++) {
341 if (strcmp(argv
[i
], "-ci") == 0) {
343 } else if (strcmp(argv
[i
], "-rgb") == 0) {
345 } else if (strcmp(argv
[i
], "-sb") == 0) {
346 doubleBuffer
= GL_FALSE
;
347 } else if (strcmp(argv
[i
], "-db") == 0) {
348 doubleBuffer
= GL_TRUE
;
350 printf("%s (Bad option).\n", argv
[i
]);
357 int main(int argc
, char **argv
)
361 glutInit(&argc
, argv
);
363 if (Args(argc
, argv
) == GL_FALSE
) {
367 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 300);
370 type
|= (rgb
) ? GLUT_RGB
: GLUT_INDEX
;
371 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
372 glutInitDisplayMode(type
);
374 if (glutCreateWindow("Olympic") == GL_FALSE
) {
382 glutReshapeFunc(Reshape
);
383 glutKeyboardFunc(Key
);
384 glutDisplayFunc(DrawScene
);
385 glutIdleFunc(glut_post_redisplay_p
);