better mouse control, higher res

This commit is contained in:
Evert Prants 2021-11-06 15:11:55 +02:00
parent b90dd89e2e
commit f830812964
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 18 additions and 8 deletions

View File

@ -20,7 +20,7 @@
#include "planet/Planet.h"
Application::Application() : m_width(1080), m_height(720)
Application::Application() : m_width(1920), m_height(1080), m_lock(true)
{
}
@ -116,12 +116,13 @@ void Application::handleEvents()
}
glm::vec2 mousepos = Input::getInstance().getMouseCoords();
// Force mouse to the center of the screen
SDL_SetWindowGrab(m_window, SDL_TRUE);
SDL_WarpMouseInWindow(m_window, m_width/2, m_height/2);
if (m_lock || Input::getInstance().isKeyDown(SDL_BUTTON_RIGHT)) {
// Force mouse to the center of the screen
SDL_WarpMouseInWindow(m_window, m_width/2, m_height/2);
// Handle Camera Movement
m_camera->processMouseMovement(-(m_width/2 - mousepos.x), m_height/2 - mousepos.y, GL_TRUE);
// Handle Camera Movement
m_camera->processMouseMovement(-(m_width/2 - mousepos.x), m_height/2 - mousepos.y, GL_TRUE);
}
// Handle Camera Movement Keys
if(Input::getInstance().isKeyDown(SDLK_w))
@ -148,8 +149,16 @@ void Application::handleEvents()
m_wireframe = !m_wireframe;
// Exit game on Esc
if(Input::getInstance().isKeyPressed(SDLK_ESCAPE))
exit();
if(Input::getInstance().isKeyPressed(SDLK_ESCAPE)) {
m_lock = !m_lock;
if (m_lock) {
SDL_SetWindowGrab(m_window, SDL_TRUE);
SDL_ShowCursor(SDL_DISABLE);
} else {
SDL_SetWindowGrab(m_window, SDL_FALSE);
SDL_ShowCursor(SDL_ENABLE);
}
}
}

View File

@ -46,6 +46,7 @@ class Application : public Singleton<Application>
bool m_run;
bool m_wireframe;
bool m_lock;
void handleEvents();
void run();