[SOLVED]GLFWScrollCallback "stuck"

I’m trying to use the GLFWScrollCallback for a zoom in and out feature and I’ve ran into the problem that the yoffset value never resets, it remains at the last received value.

I have a InputHandler class with a nested ScrollHandler class extending GLFWScrollCallback

ScrollHandler
public class ScrollHandler extends GLFWScrollCallback {
	@Override
	public void invoke(long window, double xoffset, double yoffset) {
		scrollDelta = (float) yoffset;
	}

}

From there I have a camera class with a calculateZoom function that uses the yoffset, and since the yoffset is never reset it will continually zoom in or out depending on last value.

calculateZoom
private void calculateZoom() {
	float zoomLevel = getScrollDelta() * 0.1f;
	distanceFromPlayer -= zoomLevel;
    		
}

So my question is, is that the intended result when using the scroll callback or is it possibly something I’m doing wrong?

What would be the best way to handle this?

Yes, this is intended result. Scroll callback with xoffset/yoffset is called only when scroll event is happening. When no scrolling is happening this callback won’t be called. Its similar to mouse move callback - it gets called only when mouse is moving, not when it is standing still.

You need to change logic in your code to adjust distanceFromPlayer depending on how much scroll callback was called, not what was last value it received.

I’m not sure how i could adjust the logic to adjust for a value that never returns to 0 unless there was a way to check if the wheel was actively scrolling.

However my fix for the meantime is my own reset method that just sets the value back to 0 when its retrieved allowing for a new calculation each time the wheel is scrolled not a continual calculation.

getScrollDelta
public static float getScrollDelta() {
	float sD = scrollDelta;
	scrollReset();
	return sD;
}
scrollReset
	public static void scrollReset() {
		scrollDelta = 0;
	}

You put your scrollZoom code inside ScrollHandler.invoke function directly:

@Override
	public void invoke(long window, double xoffset, double yoffset) {
		float zoomLevel = yoffset * 0.1f;
		distanceFromPlayer -= zoomLevel;
    }

haha, I have no idea why I didn’t think of that… Thank you.