Sign in to follow this  
BlueSpud

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this