#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <math.h>
#ifdef WIN32
static int WIDTH = 640;
static int HEIGHT = 480;
-#define FRAME 50
+static GLint T0 = 0;
+static GLint Frames = 0;
#define BASESIZE 7.5f
#define SPHERE_RADIUS 0.75f
#define clamp255(a) ( (a)<(0.0f) ? (0.0f) : ((a)>(255.0f) ? (255.0f) : (a)) )
+#ifndef fabs
#define fabs(x) ((x)<0.0f?-(x):(x))
+#endif
#define vequ(a,b) { (a)[0]=(b)[0]; (a)[1]=(b)[1]; (a)[2]=(b)[2]; }
#define vsub(a,b,c) { (a)[0]=(b)[0]-(c)[0]; (a)[1]=(b)[1]-(c)[1]; (a)[2]=(b)[2]-(c)[2]; }
static int joyavailable = 0;
static int joyactive = 0;
-static float
-gettime(void)
-{
- static float told = 0.0f;
- float tnew, ris;
-
- tnew = glutGet(GLUT_ELAPSED_TIME);
-
- ris = tnew - told;
-
- told = tnew;
-
- return ris / 1000.0;
-}
-
static void
calcposobs(void)
{
dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0);
dir[2] = cos(beta * M_PI / 180.0);
+ if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5)
+ dir[0] = 0;
+ if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5)
+ dir[1] = 0;
+ if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5)
+ dir[2] = 0;
+
obs[0] += v * dir[0];
obs[1] += v * dir[1];
obs[2] += v * dir[2];
printstring(GLUT_BITMAP_HELVETICA_18, "Help");
glRasterPos2i(60, 390);
- printstring(GLUT_BITMAP_HELVETICA_12, "h - Togle Help");
+ printstring(GLUT_BITMAP_HELVETICA_12, "h - Toggle Help");
glRasterPos2i(60, 370);
- printstring(GLUT_BITMAP_HELVETICA_12, "f - Togle Fog");
+ printstring(GLUT_BITMAP_HELVETICA_12, "f - Toggle Fog");
glRasterPos2i(60, 350);
- printstring(GLUT_BITMAP_HELVETICA_12, "b - Togle Back face culling");
+ printstring(GLUT_BITMAP_HELVETICA_12, "b - Toggle Back face culling");
glRasterPos2i(60, 330);
- printstring(GLUT_BITMAP_HELVETICA_12, "p - Togle Wire frame");
+ printstring(GLUT_BITMAP_HELVETICA_12, "p - Toggle Wire frame");
glRasterPos2i(60, 310);
printstring(GLUT_BITMAP_HELVETICA_12, "Arrow Keys - Rotate");
glRasterPos2i(60, 290);
glRasterPos2i(60, 250);
if (joyavailable)
printstring(GLUT_BITMAP_HELVETICA_12,
- "j - Togle jostick control (Joystick control available)");
+ "j - Toggle jostick control (Joystick control available)");
else
printstring(GLUT_BITMAP_HELVETICA_12,
"(No Joystick control available)");
glRasterPos2i(60, 190);
printstring(GLUT_BITMAP_HELVETICA_12,
- "1 - Togle the plane texture map window");
+ "1 - Toggle the plane texture map window");
glRasterPos2i(60, 170);
printstring(GLUT_BITMAP_HELVETICA_12,
- "2 - Togle the sphere texture map window");
+ "2 - Toggle the sphere texture map window");
}
static GLboolean
h[1] = 0.5f * (vdir[1] + ldir[1]);
h[2] = 0.5f * (vdir[2] + ldir[2]);
kfact = dprod(h, norm);
- kfact =
- kfact * kfact * kfact * kfact * kfact * kfact * kfact * 7.0f * 255.0f;
+ kfact = pow(kfact, 6.0) * 7.0 * 255.0;
r = r * dfact + kfact;
g = g * dfact + kfact;
h[1] = 0.5f * (vdir[1] + ldir[1]);
h[2] = 0.5f * (vdir[2] + ldir[2]);
kfact = dprod(h, norm);
- kfact *= kfact;
- kfact *= kfact;
- kfact *= kfact;
- kfact *= kfact;
- kfact *= 10.0f;
- }
+ kfact = pow(kfact, 4.0);
+ if (kfact < 1.0e-10)
+ kfact = 0.0;
+ }
r = dfact + kfact;
g = dfact + kfact;
static void
draw(void)
{
- static int count = 0;
- static char frbuf[80];
- float fr;
+ static char frbuf[80] = "";
dojoy();
glPopMatrix();
- if ((count % FRAME) == 0) {
- fr = gettime();
- sprintf(frbuf, "Frame rate: %f", FRAME / fr);
- }
-
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
glutSwapBuffers();
- count++;
+ Frames++;
+ {
+ GLint t = glutGet(GLUT_ELAPSED_TIME);
+ if (t - T0 >= 2000) {
+ GLfloat seconds = (t - T0) / 1000.0;
+ GLfloat fps = Frames / seconds;
+ sprintf(frbuf, "Frame rate: %f", fps);
+ T0 = t;
+ Frames = 0;
+ }
+ }
}
static void