-/* $Id: bounce.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
/*
- * Bouncing ball demo. Color index mode only!
+ * Bouncing ball demo.
*
* This program is in the public domain
*
* Brian Paul
- */
-
-/* Conversion to GLUT by Mark J. Kilgard */
-
-/*
- * $Log: bounce.c,v $
- * Revision 1.1 1999/08/19 00:55:40 jtg
- * Initial revision
- *
- * Revision 3.3 1999/03/18 08:16:14 joukj
- *
- * cmpstr needs string.h to included to avoid warnings
- *
- * Revision 3.2 1998/11/28 01:13:02 brianp
- * now sets an initial window position and size
- *
- * Revision 3.1 1998/11/28 01:06:57 brianp
- * now works in RGB mode by default
- *
- * Revision 3.0 1998/02/14 18:42:29 brianp
- * initial rev
*
+ * Conversion to GLUT by Mark J. Kilgard
*/
GLboolean IndexMode = GL_FALSE;
GLuint Ball;
GLenum Mode;
-GLfloat Zrot = 0.0, Zstep = 6.0;
+GLfloat Zrot = 0.0, Zstep = 180.0;
GLfloat Xpos = 0.0, Ypos = 1.0;
-GLfloat Xvel = 0.2, Yvel = 0.0;
+GLfloat Xvel = 2.0, Yvel = 0.0;
GLfloat Xmin = -4.0, Xmax = 4.0;
GLfloat Ymin = -3.8, Ymax = 4.0;
-GLfloat G = -0.1;
+GLfloat G = -9.8;
static GLuint
make_ball(void)
glColor3f(1, 1, 1);
}
- x = COS(b) * COS(a);
- y = SIN(b) * COS(a);
- z = SIN(a);
+ x = radius * COS(b) * COS(a);
+ y = radius * SIN(b) * COS(a);
+ z = radius * SIN(a);
glVertex3f(x, y, z);
x = radius * COS(b) * COS(a + da);
idle(void)
{
static float vel0 = -100.0;
+ static double t0 = -1.;
+ double t, dt;
+ t = glutGet(GLUT_ELAPSED_TIME) / 1000.;
+ if (t0 < 0.)
+ t0 = t;
+ dt = t - t0;
+ t0 = t;
- Zrot += Zstep;
+ Zrot += Zstep*dt;
- Xpos += Xvel;
+ Xpos += Xvel*dt;
if (Xpos >= Xmax) {
Xpos = Xmax;
Xvel = -Xvel;
Xvel = -Xvel;
Zstep = -Zstep;
}
- Ypos += Yvel;
- Yvel += G;
+ Ypos += Yvel*dt;
+ Yvel += G*dt;
if (Ypos < Ymin) {
Ypos = Ymin;
if (vel0 == -100.0)
glutPostRedisplay();
}
-void
+static void
visible(int vis)
{
if (vis == GLUT_VISIBLE)