d97791be5d4e23094f90a0c8e7b4536d5c449b56
1 /* $Id: bounce.c,v 1.3 2000/08/16 20:36:34 brianp Exp $ */
6 * This program is in the public domain
10 * Conversion to GLUT by Mark J. Kilgard
19 #define COS(X) cos( (X) * 3.14159/180.0 )
20 #define SIN(X) sin( (X) * 3.14159/180.0 )
26 GLboolean IndexMode
= GL_FALSE
;
29 GLfloat Zrot
= 0.0, Zstep
= 6.0;
30 GLfloat Xpos
= 0.0, Ypos
= 1.0;
31 GLfloat Xvel
= 0.2, Yvel
= 0.0;
32 GLfloat Xmin
= -4.0, Xmax
= 4.0;
33 GLfloat Ymin
= -3.8, Ymax
= 4.0;
41 GLfloat da
= 18.0, db
= 18.0;
48 glNewList(list
, GL_COMPILE
);
51 for (a
= -90.0; a
+ da
<= 90.0; a
+= da
) {
53 glBegin(GL_QUAD_STRIP
);
54 for (b
= 0.0; b
<= 360.0; b
+= db
) {
64 x
= radius
* COS(b
) * COS(a
);
65 y
= radius
* SIN(b
) * COS(a
);
69 x
= radius
* COS(b
) * COS(a
+ da
);
70 y
= radius
* SIN(b
) * COS(a
+ da
);
71 z
= radius
* SIN(a
+ da
);
86 reshape(int width
, int height
)
88 float aspect
= (float) width
/ (float) height
;
89 glViewport(0, 0, (GLint
) width
, (GLint
) height
);
90 glMatrixMode(GL_PROJECTION
);
92 glOrtho(-6.0 * aspect
, 6.0 * aspect
, -6.0, 6.0, -6.0, 6.0);
93 glMatrixMode(GL_MODELVIEW
);
98 key(unsigned char k
, int x
, int y
)
101 case 27: /* Escape */
111 glClear(GL_COLOR_BUFFER_BIT
);
116 for (i
= -5; i
<= 5; i
++) {
120 for (i
= -5; i
<= 5; i
++) {
124 for (i
= -5; i
<= 5; i
++) {
126 glVertex2f(i
* 1.15, -5.9);
128 glVertex2f(-5.3, -5.35);
129 glVertex2f(5.3, -5.35);
130 glVertex2f(-5.75, -5.9);
131 glVertex2f(5.75, -5.9);
135 glTranslatef(Xpos
, Ypos
, 0.0);
136 glScalef(2.0, 2.0, 2.0);
137 glRotatef(8.0, 0.0, 0.0, 1.0);
138 glRotatef(90.0, 1.0, 0.0, 0.0);
139 glRotatef(Zrot
, 0.0, 0.0, 1.0);
152 static float vel0
= -100.0;
181 if (vis
== GLUT_VISIBLE
)
187 int main(int argc
, char *argv
[])
189 glutInit(&argc
, argv
);
190 glutInitWindowPosition(0, 0);
191 glutInitWindowSize(600, 450);
194 IndexMode
= argc
> 1 && strcmp(argv
[1], "-ci") == 0;
196 glutInitDisplayMode(GLUT_INDEX
| GLUT_DOUBLE
);
198 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
200 glutCreateWindow("Bounce");
203 glEnable(GL_CULL_FACE
);
204 glDisable(GL_DITHER
);
205 glShadeModel(GL_FLAT
);
207 glutDisplayFunc(draw
);
208 glutReshapeFunc(reshape
);
209 glutVisibilityFunc(visible
);
210 glutKeyboardFunc(key
);
213 glutSetColor(RED
, 1.0, 0.0, 0.0);
214 glutSetColor(WHITE
, 1.0, 1.0, 1.0);
215 glutSetColor(CYAN
, 0.0, 1.0, 1.0);
219 return 0; /* ANSI C requires main to return int. */