title: GLFW 3: How to get delta of the mouse scroll wheel with ScrollCallback (LWJGL 3)
body: <p>I am following <a href="https://www.youtube.com/watch?v=PoxDDZmctnU&amp;list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP&amp;index=19" rel="nofollow noreferrer">this tutorial</a> on 3D game development with LWJGL and OpenGL. And in the series, the instructor is using LWJGL 2 while I'm using LWJGL 3 with GLFW. And in a certain section he uses LWJGL's input implementations only available in LWJGL 2, so I am forced to use GLFW's callback system. I was able to add input functionality for key input, cursor movement, and mouse button input, but when I tried to add a scrolling callback, it seemed that the offsets only return -1 and 1 for the scrolling directions, and when added, the (3rd person) camera translated forward and backwards indefinitely, and the intention was for every scroll movement the camera translates forward or backward a certain distance. In actuality I was expecting to get delta values for each scrolling movement. Previously I was messing around trying to see if I could set the offset values for an amount of delay time then set them back to 0 but to no avail. I tried searching for an answer, but I found nothing related to my problem. I may be stupid, but here's the code.</p>
  
  <p>MouseScroll callback class:</p>
  
  <pre><code>import org.lwjgl.glfw.GLFWScrollCallback;
  
      public class MouseScroll extends GLFWScrollCallback {
  
          private static float XScroll;
          private static float YScroll;
          private static float DXScroll;
          private static float DYScroll;
  
          @Override
          public void invoke(long window, double xoffset, double yoffset) {
              XScroll = (float) xoffset;
              YScroll = (float) yoffset;
              // Don't know how to achieve this here
          }
  
          /* Returns raw offset values */
          public float getXScroll() {
              return XScroll;
          }
  
          public float getYScroll() {
              return YScroll;
          }
  
          /* Returns the rate of each scrolling movement */
          public float getDXScroll() {
              return DXScroll;
          }
  
          public float getDYScroll() {
              return DYScroll;
          }
  
      }
  </code></pre>
  
  <p>Method for getting YScroll in Input class:</p>
  
  <pre><code>public static float getMouseYScroll() {
      return mouseScroll.getYScroll(); // mouseScroll is reference to MouseScroll callback
  }
  </code></pre>
  
  <p>Method using the callback in Camera.java:</p>
  
  <pre><code>private void calculateZoom() {
          float zoomLevel =  Input.getMouseYScroll() * 0.1f;
          distanceFromPlayer -= zoomLevel;
      }
  </code></pre>
  
  <p>Update method in Camera.java:</p>
  
  <pre><code>public void move() {
          calculateZoom();
          calculatePitch();
          calculateAngleAroundPlayer();
          float horizontalDistance = calculateHorizontalDistance();
          float verticalDistance = calculateVerticalDistance();
          calculateCameraPosition(horizontalDistance, verticalDistance);
          this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
      } 
  </code></pre>
  
  <p>And finally there is <code>camera.move()</code> that gets called every loop iteration</p>