Separating Camera Movement for a first person camera into another thread?

Started by
5 comments, last by BlueSpud 10 years, 7 months ago

I had a camera working, but it would move every frame, so the higher the framerate, the faster you would be able to move. I made the camera movement so it depends on time, and now the movement is framerate independent. Unfortunately, the function only gets called in the glutMain Loop where the render is also done right after. At 60 FPS, the camera seems a bit jittery, but at 100 frames it seems fine. My question is: Would it make more sense to make a new thread in which there is another game loop where I update physics, etc so movement can be based on time and look nice, regardless of the framerate. (Unless its terrible < 10 because that means there is a code problem or the computer is slow). Any insight or help would be appreciated. Thanks.

Advertisement

seems like you might be doing something wrong... the general pseudo-code is as follows:

velocity = ( current_time - last_render_time ) * factor;

of course, it is best if this is done outside of the render function for precision and accuracy.. but it should still work smoothly regardless

is this basically what you're doing? Or something different?

seems like you might be doing something wrong... the general pseudo-code is as follows:

velocity = ( current_time - last_render_time ) * factor;

of course, it is best if this is done outside of the render function for precision and accuracy.. but it should still work smoothly regardless

is this basically what you're doing? Or something different?

Yes it is, and I believe that my time is being measured in nanoseconds.

note that current_time probably shouldn't be the actual time function call... you should have something like this:

...

last_render_time = current_time;

current_time = getTime();

...

velocity = ( current_time - last_render_time ) * factor;

...

If you don't have that - try it and see if that makes a difference

note that current_time probably shouldn't be the actual time function call... you should have something like this:

...

last_render_time = current_time;

current_time = getTime();

...

velocity = ( current_time - last_render_time ) * factor;

...

If you don't have that - try it and see if that makes a difference

Did you mean that last render time shouldn't be the function call? Because in your little example, current time is still a function call.

no. i mean that you should set is as a variable first before you use it in the `velocity` assignment, instead of putting the call right in the `velocity` assignment statement

no. i mean that you should set is as a variable first before you use it in the `velocity` assignment, instead of putting the call right in the `velocity` assignment statement

I see what you mean, in my code I do this.

This topic is closed to new replies.

Advertisement