Game Input mouse filtering
Posted
by
aaron
on Game Development
See other posts from Game Development
or by aaron
Published on 2012-11-06T06:08:47Z
Indexed on
2012/11/06
11:23 UTC
Read the original article
Hit count: 280
I'm having a problem with filtering mouse inputs, the method I am doing right know moves the cursor back to the center of the screen each frame. But I cant do this because it messes with other things. Does anyone know how to implement this with delta mouse movement. Here is the relevant code.
void update() {
static float oldX = 0;
static float oldY = 0;
static float walkSpeed = .05f;
static float sensitivity = 0.002f;//mouse sensitivity
static float smooth = 0.7f;//mouse smoothing (0.0 - 0.99)
float w = ScreenResolution.x/2.0f;
float h = ScreenResolution.y/2.0f;
Vec2f scrc(w,h);
Vec2f mpos(getMouseX(),getMouseY());
float x = scrc.x-mpos.x;
float y = scrc.y-mpos.y;
oldX = (oldX*smooth + x*(1.0-smooth));
oldY = (oldY*smooth + y*(1.0-smooth));
x = oldX * sensitivity;
y = oldY * sensitivity;
camera->rotate(Vec3f(y,0,0));
transform->setRotation(transform->getRotation()*Quaternionf::fromAxisAngle(0.0f,1.0f,0.0f,-x));
setMousePosition((int)scrc.x,(int)scrc.y);//THIS IS THE PROBLEM LINE HOW CAN I AVOID THIS
....
}
© Game Development or respective owner