Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

    ....
}
share|improve this question
What is the problem right now with not centering the mouse? Keep last mouse position and calculate delta using the new mouse position. You might need to "grab" the mouse cursor for your window so that you get proper mouse motion events, even when the mouse is at the window edge. – Ankit Nov 6 '12 at 7:43
The real problem is that i cant come up with a smoothing algorithm that does not change the state of the mouse, the resource that i don't want to change the state is because it is a hack this piece of code should not ever change the systems state it is part the "specification". – aaron Nov 6 '12 at 7:54

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.