title: Implementing a camera that can pan in OpenGL
body: <p>I'm wondering how you would implement a camera that can pan in OpenGL. This is my current code and basic idea:</p>
  <pre><code>        mouseSlope.first = mousePressedPos.first - xpos;
          mouseSlope.second = mousePressedPos.second - ypos;
  
          float d, z;
          d = (glm::dot(cameraFront, (-cameraRight)));
  
          if (cameraFront.y != 0.0f) {
              z = (d + (mouseSlope.first * cameraFront.x + mouseSlope.second * cameraFront.y)) / -cameraFront.y;
          }
          else{
              z = (d + (mouseSlope.first * cameraFront.x + mouseSlope.second * cameraFront.y));
          }
          glm::vec3 translation(mouseSlope.first, mouseSlope.second, z);
          cameraPos -= 0.05f * glm::normalize(translation);
  
        glm::vec3 direction;
        direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
        direction.y = sin(pitch);
        direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
        cameraFront = glm::normalize(direction);
  
      cameraRight = glm::cross(cameraFront, worldUp);
      cameraUp = glm::cross(cameraFront, cameraRight);
  </code></pre>
  <p>In this code, I'm taking the mouse position whenever the pan button is pressed and subtracting it by the current mouse position. This should give me the x and y coordinates between the current mouse position and the position of the mouse when the pan button was pressed. From there, I find the equation for the plane, intersecting the camera in the direction of the right vector, using the right vector and the orthogonal front vector of the camera. Then, using the previously calculated x and y coordinates, I can calculate the z position that the new translation must go to and construct and implement it from there. The problem is, is that the glm translation vector at some point will turn into -nan(ind). Am I going in the right direction, or, is there a much more efficient and optimized way of doing this?</p>
  <p>Side note:
  I do end up calling:</p>
  <pre><code>glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
  </code></pre>
  <p>In other places in my code.</p>