Qt: Implement "Free look"

This commit is contained in:
spycrab
2018-04-29 13:35:43 +02:00
parent e51cf8870e
commit bc51c34a96
2 changed files with 32 additions and 0 deletions

View File

@ -6,12 +6,16 @@
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPalette>
#include <QScreen>
#include <QTimer>
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoConfig.h"
#include "DolphinQt2/Host.h"
#include "DolphinQt2/RenderWidget.h"
#include "DolphinQt2/Settings.h"
@ -120,6 +124,10 @@ bool RenderWidget::event(QEvent* event)
break;
}
case QEvent::MouseMove:
if (g_Config.bFreeLook)
OnFreeLookMouseMove(static_cast<QMouseEvent*>(event));
// [[fallthrough]]
case QEvent::MouseButtonPress:
if (!Settings::Instance().GetHideCursor() && isActiveWindow())
{
@ -162,3 +170,22 @@ bool RenderWidget::event(QEvent* event)
}
return QWidget::event(event);
}
void RenderWidget::OnFreeLookMouseMove(QMouseEvent* event)
{
if (event->buttons() & Qt::MidButton)
{
// Mouse Move
VertexShaderManager::TranslateView((event->x() - m_last_mouse[0]) / 50.0f,
(event->y() - m_last_mouse[1]) / 50.0f);
}
else if (event->buttons() & Qt::RightButton)
{
// Mouse Look
VertexShaderManager::RotateView((event->x() - m_last_mouse[0]) / 200.0f,
(event->y() - m_last_mouse[1]) / 200.0f);
}
m_last_mouse[0] = event->x();
m_last_mouse[1] = event->y();
}