Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. Orbit::Math::vec2 lastMousePos;
  2.  
  3. void Update() {
  4. this->obj->getComponent<Orbit::Mesh>()->Draw();
  5.  
  6. if (Orbit::Input::isMouseButtonDown(1)) {
  7.  
  8. // Camera scripting || Temp
  9. if (Orbit::Input::isKeyDown('W'))
  10. this->m_MainCamera->getComponent<Orbit::Camera>()->Forward(.1f);
  11. if (Orbit::Input::isKeyDown('S'))
  12. this->m_MainCamera->getComponent<Orbit::Camera>()->Backwards(.1f);
  13. if (Orbit::Input::isKeyDown('D'))
  14. this->m_MainCamera->getComponent<Orbit::Camera>()->Right(.1f);
  15. if (Orbit::Input::isKeyDown('A'))
  16. this->m_MainCamera->getComponent<Orbit::Camera>()->Left(.1f);
  17. if (Orbit::Input::isKeyDown('E'))
  18. this->m_MainCamera->getComponent<Orbit::Camera>()->addPosY(.1f);
  19. if (Orbit::Input::isKeyDown('Q'))
  20. this->m_MainCamera->getComponent<Orbit::Camera>()->addPosY(-.1f);
  21. if (Orbit::Input::isKeyDown(265)) // up arrow
  22. this->m_MainCamera->getComponent<Orbit::Camera>()->addPitch(.7f);
  23. if (Orbit::Input::isKeyDown(264)) // down
  24. this->m_MainCamera->getComponent<Orbit::Camera>()->addPitch(-.7f);
  25. if (Orbit::Input::isKeyDown(263)) // left
  26. this->m_MainCamera->getComponent<Orbit::Camera>()->addYaw(-.7f);
  27. if (Orbit::Input::isKeyDown(262)) // right
  28. this->m_MainCamera->getComponent<Orbit::Camera>()->addYaw(.7f);
  29.  
  30. Orbit::Math::vec2 MousePos = Orbit::Input::getMousePosition();
  31. if (lastMousePos != MousePos) {
  32.  
  33. double cursorX;
  34. double cursorY;
  35.  
  36. Orbit::Window* window = Application::getApplication()->getWindow().get();
  37. window->setCursorVisible(false);
  38. window->forceCursorCenter(true);
  39.  
  40. uint32_t screenWidth = window->getWidth();
  41. uint32_t screenHeight = window->getHeight();
  42.  
  43. if (this->m_FirstMouse == true) {
  44. cursorX = (screenWidth / 2);
  45. cursorY = (screenHeight / 2);
  46. this->m_FirstMouse = false;
  47. }
  48. else {
  49. lastMousePos = MousePos;
  50. cursorX = MousePos.x;
  51. cursorY = MousePos.y;
  52. }
  53. double mouseX = cursorX - (screenWidth / 2);
  54. double mouseY = (screenHeight / 2) - cursorY;
  55.  
  56.  
  57. mouseX *= 0.05f;
  58. mouseY *= 0.05f;
  59.  
  60. Orbit::Renderer::getActiveCamera()->addYaw(mouseX);
  61. Orbit::Renderer::getActiveCamera()->addPitch(mouseY);
  62. }
  63. }
  64. else {
  65. Orbit::Window* window = Application::getApplication()->getWindow().get();
  66. window->setCursorVisible(true);
  67. window->forceCursorCenter(false);
  68. this->m_FirstMouse = true;
  69. }
  70.  
  71. ORBIT_CORE_WARN("Camera: x: {0} y: {1} z: {2}", this->m_MainCamera->getComponent<Orbit::Camera>()->getPosition().x, this->m_MainCamera->getComponent<Orbit::Camera>()->getPosition().y, this->m_MainCamera->getComponent<Orbit::Camera>()->getPosition().z);
  72. ORBIT_CORE_WARN("Camera: Pitch {0}, Yaw {1}", this->m_MainCamera->getComponent<Orbit::Camera>()->getPitch(), this->m_MainCamera->getComponent<Orbit::Camera>()->getYaw());
  73. }
  74.  
  75.  
  76.  
  77. winWindow.cpp
  78. void winWindow::setCursorVisible(bool visible) {
  79.  
  80. if(visible)
  81. glfwSetInputMode(this->m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
  82. else
  83. glfwSetInputMode(this->m_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
  84. }
  85.  
  86. void winWindow::forceCursorCenter(bool center) {
  87. this->m_Data.cursor_center = center;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement