title: OpenGL: mouse move objects, object can't follow mouse
body: <p>After picking an object with the mouse, I want to be able to move the object using the mouse. First, I translate mouse position to world position, and use <code>glReadPixels()</code> to read the depth of the object as z's:</p>
  <pre><code>double xpos, ypos, zpos;
  glfwGetCursorPos(window_ptr, &amp;xpos, &amp;ypos);
  float xPercent = (xpos + 0.5f) / scr_width_ * 2.0f - 1;  // range is -1 to +1
  float yPercent = (ypos + 0.5f) / scr_height_ * 2.0f - 1;  // range is -1 to +1
  yPercent = -yPercent;
  
  glReadPixels(xpos, scr_height_ - ypos - 1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &amp;zPercent);
  </code></pre>
  <p>then we move the mouse until we want to release the mouse.</p>
  <pre><code>last_position = (xPercent, yPercent, zPercent);
  </code></pre>
  <hr />
  <p>Finally we use the same value as z's value and calculate the x's world position and y's position:</p>
  <pre><code>current_position = (xPercent, yPercent, zPercent);
  </code></pre>
  <p>then we translate the object model:</p>
  <pre><code>model = glm::translate(model, current_position - last_postion);
  </code></pre>
  <p>the issue is:</p>
  <ul>
  <li>the object's speed is not same as mouse's.</li>
  </ul>
  <p>waiting for your answer.</p>