PDA

View Full Version : problem trying to sync motion...



zukko
01-12-2006, 04:41 PM
Hi, i have a class to sync the movement in my opengl apps (different pc's, same speed...), suddenly it doesnt work right with computers faster than mine, can anyone help me find out the mistake?


class sync
{
public:
float targetfps;
float fps;
LARGE_INTEGER tickspersecond;
LARGE_INTEGER currentticks;
LARGE_INTEGER framedelay;

float speedfactor;
void init(float);
void SetSpeedFactor();
};

void sync::init(float tfps)
{
targetfps=tfps;
QueryPerformanceCounter(&framedelay);
QueryPerformanceCounter(&tickspersecond);
}

void sync::SetSpeedFactor()
{
QueryPerformanceCounter(&currentticks);
speedfactor=(float)(currentticks.QuadPart-framedelay.QuadPart)/((float)tickspersecond.QuadPart/targetfps);
fps=targetfps/speedfactor;
if (speedfactor <= 0)
speedfactor=1;
framedelay=currentticks;
}
thanks!
[edit]
i call init at the beginning of the program and setspeedfactor, every frame, then i multiply everything by speedfactor, for example:
glTranslatef(movement*sync.speedfactor,0,0);

songho
01-12-2006, 06:38 PM
zukko,
I don't know about the detail of your code, but I think the following line should be:

QueryPerformanceCounter(&tickspersecond);

to

QueryPerformanceFrequency(&tickspersecond);

==song==

jide
01-13-2006, 12:00 AM
This is vague. Can you explain what you are doing instead of putting such codes we know nothing about how it really does and how it is used in the network ?

zukko
01-13-2006, 10:53 AM
thanks songho!! it was a very dumb mistake :p
jide, its a class for time based movement instead of frame based movement.