Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Question for Jiia: Mouse filtering

This topic is 5242 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

This question is directed at Jiia, since it concerns his Collision Demo, but if anyone else has answers they would be appreciated. One of the things that really stood out to me in the demo is the smoothed mouse movement. Moving the mouse to look around gives a very smooth acceleration-based movement, rather than the typical precise jerky movement of the mouse. The camera doesn''t jump around, but rather glides from one angle to the next, giving a very professional feel. I''m assuming the demo uses mouse buffer filtering, possibly something similar to this on FlipCode, but even the demo provided there doesn''t have quite the same feel to it, its either too precise or lags behind the actual mouse movement too much. So, Jiia, if you''re there, how did you do it? How are you filtering the mouse while still keeping it responsive and accurate? Any tips (here or by email) would be greatly appreciated!

Share this post

Link to post
Share on other sites
The credit goes to PouyaCatnip and hplus0603 for explaining
weighted avarages to a total idiot such as myself.
See here

It's really simple. I defined two different ways of doing it
in my engine. They are:

Method 1: (used this for rotation in the demo)
A) Have a vector for the location you want the object.
B) Just do a weighted average each frame between that vector
and the current real vector to slowly get it there.

Method 2: (used this for movement in the demo)
A) Use velocities and force. The force is weighted into the
velocities each frame. The velocity is directly added to the
positions. This will speed it up smoothly.
B) Weight the Velocities against 0.0f after applying them
to the positions. This will slow the speed smoothly.

Here are some sections of code for method 2.

// "FDelay" is the time passed since last frame

// WFactor = 0.995f in my demo

FLOAT Factor = powf(WFactor, FDelay);

if(Force.x) Velocity.x = (Velocity.x * Factor) + ((Velocity.x + Force.x) * (1.0f - Factor));

if(Force.y) Velocity.y = (Velocity.y * Factor) + ((Velocity.y + Force.y) * (1.0f - Factor));

if(Force.z) Velocity.z = (Velocity.z * Factor) + ((Velocity.z + Force.z) * (1.0f - Factor));

// I then reset force to zero, because it is directly set each frame.

// This slows it down (SFactor = 0.005f in my demo) I reversed

// it because it made more sense as a "stopping" force.

Velocity *= powf(1.0f - SFactor, FDelay);

Let me know if I need to clear something up

[edited by - Jiia on May 18, 2004 3:16:19 PM]

Share this post

Link to post
Share on other sites
This may also be something to fill some gaps:

// Update Camera Attributes

VECTOR Move(0,0,0);

Move.z += 1.0f;
Move.z -= 1.0f;
Move.x -= 1.0f;
Move.x += 1.0f;

D3DXVec3Normalize(&Move, &Move);

Move *= 0.4f;
// CamForward / CamRight are just direction vectors

Camera.Position.Force = (Move.z * Camera.CamForward) + (Move.x * Camera.CamRight);
// Attempt is the vector "location I want to be at"

Camera.Rotation.Attempt.x += MOUSE_MY * 0.005f;
Camera.Rotation.Attempt.y += MOUSE_MX * 0.005f;
// Oh yeah, then this

Camera.LookAt = Camera.Position.Current + Camera.CamForward;

[edited by - Jiia on May 18, 2004 3:30:35 PM]

Share this post

Link to post
Share on other sites
Awesome, thanks!! So it uses separate vectors for the mouse movement and camera angle, and uses weighted averages to move the camera angle towards the mouse angle. Damn, that is simple. And thanks for that other link, it sure does explain a lot!

Share this post

Link to post
Share on other sites

  • 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!