Advertisement
nezvers

Mouse euler

Sep 9th, 2020
1,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement