nezvers

Mouse euler

Sep 9th, 2020
573
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void mouse_callback(GLFWwindow* window, double xpos, double ypos)
  2. {
  3.     if (firstMouse)
  4.     {
  5.         lastX = xpos;
  6.         lastY = ypos;
  7.         firstMouse = false;
  8.     }
  9.  
  10.     float xoffset = xpos - lastX;
  11.     float yoffset = lastY - ypos;
  12.     lastX = xpos;
  13.     lastY = ypos;
  14.  
  15.     float sensitivity = 0.1f;
  16.     xoffset *= sensitivity;
  17.     yoffset *= sensitivity;
  18.  
  19.     yaw   += xoffset;
  20.     pitch += yoffset;
  21.  
  22.     if(pitch > 89.0f)
  23.         pitch = 89.0f;
  24.     if(pitch < -89.0f)
  25.         pitch = -89.0f;
  26.  
  27.     glm::vec3 direction;
  28.     direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
  29.     direction.y = sin(glm::radians(pitch));
  30.     direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
  31.     cameraFront = glm::normalize(direction);
RAW Paste Data