Sign in to follow this  

Raw Input forces camera movement depending on frame time!

This topic is 2485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I'm working on a tutorial application shows how sorting by material works.

I use Raw Input system for handling keyboard and mouse input. For example, user can move the camera with WASD and rotate it with mouse; also can switch some special effects (SSAO, Camera Motion Blur etc.) on/off. As traditional, I'm getting and processing (for further use) the whole raw data from WM_INPUT message. I'm setting/resetting some booleans to check whether a mouse/keyboard button is pressed/held or released and using these boolean datas in rendering loop.

Because of showing "sorting by material" concept, it's quite normal to see the frame time increases when the user switches to normal (i.e. sorting by material is disabled) mode for a scene including ~1M tris and ~30 different materials and vice versa. User can toggle between normal and sorted-by-material (SbM) modes by pressing 'K'.

In normal mode, FPS is ~40, and it's so hard to rotate the camera 360 degrees or move the camera, say, 50 units. It's so so slow!
But in SbM mode, FPS is ~300, you can easily rotate the camera 360 degrees and also move it to the same distance. Movement is fast as I expected.

Here the pseudo-code:
[code]
float dr = 15.f;
if (Pressed (Left_Shift)) dr *= 3.f;
DWORD direction = 0x00;
if (Pressed (W)) direction |= FORWARD;
if (Pressed (S)) direction |= BACKWARDS;
if (Pressed (A)) direction |= LEFT;
if (Pressed (D)) direction |= RIGHT;

if (direction != 0) Camera.Move (direction, dr);


float mx = raw->data.mouse.lLastX / 25.f;
float my = raw->data.mouse.lLastY / 25.f;

if (mx || my) Camera.Rotate (my, mx, 0); //yaw / pitch / roll
[/code]

Why this movement depends on frame time with raw input system?

Is there any solution to fix it?

Thx. in advance.
-R

Share this post


Link to post
Share on other sites
One solution is to multiple the movement speed by the frame-time. So if you have 300 FPS, your frame-time is [b]dt = 1.0 / 300.0[/b], and if you have 40 FPS your frame-time is [b]dt = 1.0 / 40.0[/b]. Then you set [b]float dr = 300.0f * 15.f * dt;[/b] to correct the movement speed so you always get the same speed no matter how many frames you have.

Share this post


Link to post
Share on other sites

This topic is 2485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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