Jump to content
  • Advertisement
Sign in to follow this  

Raw Input forces camera movement depending on frame time!

This topic is 2768 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:

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

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

Is there any solution to fix it?

Thx. in advance.

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 dt = 1.0 / 300.0, and if you have 40 FPS your frame-time is dt = 1.0 / 40.0. Then you set float dr = 300.0f * 15.f * dt; 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!