Hi all,
I’m trying to create a simulation where an objects position is updated based on points held in a text file. Reading the points and outputting them to the screen is fine but trying to slow the animation down using glutTimerFunc is just not working!! here is my code so far:
void timer(int flag)
{
glutPostRedisplay();
glutTimerFunc(200, timer, 1);
}
void readstr(FILE *f,char *string)
//this just extracts a 255 character line from my text file
{
do
{
fgets(string, 255, f);
} while ((string[0] == ‘/’) | | (string[0] == ’
'));
return;
}
void move(void)
{
int ver;
int i;
FILE *filein;
char oneline[255];
double pos;
filein = fopen(“frame.dat”, “rt”);
if(!filein)
{
printf("failed to open file: frame.dat
");
exit(0);
}
for (i=0;i<30;i++)
{
readstr(filein,oneline);
printf("%s", oneline);
//this converts the string to a double
pos = atof(oneline);
//updates object position
w_move = pos;
glutTimerFunc(200, timer, 1);
}
I think the problem is because the glutTimerFunc is being called within a for loop, but I need the for loop to iterate through the file!!! has anyone got any suggestions?!
Cheers
Chris