[Application|Camera] Better mouse handling.

This commit is contained in:
Quentin Bazin 2018-06-05 17:17:09 +02:00
parent 5a969f055a
commit 96bd9c590a
3 changed files with 15 additions and 8 deletions

View File

@ -42,6 +42,8 @@ class Window {
void close() { m_isOpen = false; }
bool isOpen() const { return m_isOpen; }
SDL_Window *window() const { return m_window.get(); }
private:
using SDL_WindowPtr = std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)>;
using SDL_GLContextPtr = std::unique_ptr<void, decltype(&SDL_GL_DeleteContext)>;

View File

@ -18,14 +18,13 @@
#include <cstdlib>
#include <ctime>
#include <SFML/Window/Event.hpp>
#include "Application.hpp"
#include "Config.hpp"
#include "Exception.hpp"
#include "GameState.hpp"
#include "Mouse.hpp"
#include "OpenGL.hpp"
#include "SDLHeaders.hpp"
Application::Application() : m_stateStack(ApplicationStateStack::getInstance()) {
srand(time(NULL));
@ -55,7 +54,13 @@ void Application::handleEvents() {
}
break;
case SDL_MOUSEMOTION:
Mouse::update(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel);
// Mouse::update(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel);
if(SCREEN_WIDTH / 2 != event.motion.x || SCREEN_HEIGHT / 2 != event.motion.y) {
Camera::getInstance().turnH(event.motion.xrel * 0.06);
Camera::getInstance().turnV(-event.motion.yrel * 0.06);
SDL_WarpMouseInWindow(m_window.window(), SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
}
break;
default:
break;

View File

@ -69,11 +69,11 @@ void Camera::move(float direction) {
}
glm::mat4 Camera::processInputs() {
if(Mouse::getDX() != 0 || Mouse::getDY() != 0) {
turnH(Mouse::getDX() * 0.2f);//0.02);
turnV(-Mouse::getDY() * 0.2f);//0.02);
// m_viewMatrix = update();
}
// if(Mouse::getDX() != 0 || Mouse::getDY() != 0) {
// turnH(Mouse::getDX() * 0.2f);//0.02);
// turnV(-Mouse::getDY() * 0.2f);//0.02);
// // m_viewMatrix = update();
// }
if(Keyboard::isKeyPressed(Keyboard::Space)) {
m_y += 0.1;