Merge pull request #7870 from jordan-woyak/free-look-roll
VideoCommon: Change free-look's middle-mouse action to roll the camera.
This commit is contained in:
commit
9e951819d5
|
@ -74,7 +74,7 @@ static Common::Event g_compressAndDumpStateSyncEvent;
|
||||||
static std::thread g_save_thread;
|
static std::thread g_save_thread;
|
||||||
|
|
||||||
// Don't forget to increase this after doing changes on the savestate system
|
// Don't forget to increase this after doing changes on the savestate system
|
||||||
static const u32 STATE_VERSION = 107; // Last changed in PR 7952
|
static const u32 STATE_VERSION = 108; // Last changed in PR 7870
|
||||||
|
|
||||||
// Maps savestate versions to Dolphin versions.
|
// Maps savestate versions to Dolphin versions.
|
||||||
// Versions after 42 don't need to be added to this list,
|
// Versions after 42 don't need to be added to this list,
|
||||||
|
|
|
@ -191,7 +191,7 @@ void AdvancedWidget::AddDescriptions()
|
||||||
#endif
|
#endif
|
||||||
static const char TR_FREE_LOOK_DESCRIPTION[] = QT_TR_NOOP(
|
static const char TR_FREE_LOOK_DESCRIPTION[] = QT_TR_NOOP(
|
||||||
"Allows manipulation of the in-game camera. Move the mouse while holding the right button "
|
"Allows manipulation of the in-game camera. Move the mouse while holding the right button "
|
||||||
"to pan or middle button to move.\n\nUse the WASD keys while holding SHIFT to move the "
|
"to pan or middle button to roll.\n\nUse the WASD keys while holding SHIFT to move the "
|
||||||
"camera. Press SHIFT+2 to increase speed or SHIFT+1 to decrease speed. Press SHIFT+R "
|
"camera. Press SHIFT+2 to increase speed or SHIFT+1 to decrease speed. Press SHIFT+R "
|
||||||
"to reset the camera or SHIFT+F to reset the speed.\n\nIf unsure, leave this unchecked. ");
|
"to reset the camera or SHIFT+F to reset the speed.\n\nIf unsure, leave this unchecked. ");
|
||||||
static const char TR_CROPPING_DESCRIPTION[] =
|
static const char TR_CROPPING_DESCRIPTION[] =
|
||||||
|
|
|
@ -235,21 +235,19 @@ bool RenderWidget::event(QEvent* event)
|
||||||
|
|
||||||
void RenderWidget::OnFreeLookMouseMove(QMouseEvent* event)
|
void RenderWidget::OnFreeLookMouseMove(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (event->buttons() & Qt::MidButton)
|
const auto mouse_move = event->pos() - m_last_mouse;
|
||||||
{
|
m_last_mouse = event->pos();
|
||||||
// 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();
|
if (event->buttons() & Qt::RightButton)
|
||||||
m_last_mouse[1] = event->y();
|
{
|
||||||
|
// Camera Pitch and Yaw:
|
||||||
|
VertexShaderManager::RotateView(mouse_move.y() / 200.f, mouse_move.x() / 200.f, 0.f);
|
||||||
|
}
|
||||||
|
else if (event->buttons() & Qt::MidButton)
|
||||||
|
{
|
||||||
|
// Camera Roll:
|
||||||
|
VertexShaderManager::RotateView(0.f, 0.f, mouse_move.x() / 200.f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderWidget::PassEventToImGui(const QEvent* event)
|
void RenderWidget::PassEventToImGui(const QEvent* event)
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
@ -43,5 +41,5 @@ private:
|
||||||
|
|
||||||
static constexpr int MOUSE_HIDE_DELAY = 3000;
|
static constexpr int MOUSE_HIDE_DELAY = 3000;
|
||||||
QTimer* m_mouse_timer;
|
QTimer* m_mouse_timer;
|
||||||
std::array<float, 2> m_last_mouse{};
|
QPoint m_last_mouse{};
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,10 +39,7 @@ static int nPostTransformMatricesChanged[2]; // min,max
|
||||||
static int nLightsChanged[2]; // min,max
|
static int nLightsChanged[2]; // min,max
|
||||||
|
|
||||||
static Common::Matrix44 s_viewportCorrection;
|
static Common::Matrix44 s_viewportCorrection;
|
||||||
static Common::Matrix33 s_viewRotationMatrix;
|
static Common::Matrix44 s_freelook_matrix;
|
||||||
static Common::Matrix33 s_viewInvRotationMatrix;
|
|
||||||
static Common::Vec3 s_fViewTranslationVector;
|
|
||||||
static float s_fViewRotation[2];
|
|
||||||
|
|
||||||
VertexShaderConstants VertexShaderManager::constants;
|
VertexShaderConstants VertexShaderManager::constants;
|
||||||
bool VertexShaderManager::dirty;
|
bool VertexShaderManager::dirty;
|
||||||
|
@ -450,24 +447,12 @@ void VertexShaderManager::SetConstants()
|
||||||
PRIM_LOG("Projection: %f %f %f %f %f %f", rawProjection[0], rawProjection[1], rawProjection[2],
|
PRIM_LOG("Projection: %f %f %f %f %f %f", rawProjection[0], rawProjection[1], rawProjection[2],
|
||||||
rawProjection[3], rawProjection[4], rawProjection[5]);
|
rawProjection[3], rawProjection[4], rawProjection[5]);
|
||||||
|
|
||||||
|
auto corrected_matrix = s_viewportCorrection * Common::Matrix44::FromArray(g_fProjectionMatrix);
|
||||||
|
|
||||||
if (g_ActiveConfig.bFreeLook && xfmem.projection.type == GX_PERSPECTIVE)
|
if (g_ActiveConfig.bFreeLook && xfmem.projection.type == GX_PERSPECTIVE)
|
||||||
{
|
corrected_matrix *= s_freelook_matrix;
|
||||||
using Common::Matrix44;
|
|
||||||
|
|
||||||
auto mtxA = Matrix44::Translate(s_fViewTranslationVector);
|
memcpy(constants.projection.data(), corrected_matrix.data.data(), 4 * sizeof(float4));
|
||||||
auto mtxB = Matrix44::FromMatrix33(s_viewRotationMatrix);
|
|
||||||
const auto viewMtx = mtxB * mtxA; // view = rotation x translation
|
|
||||||
|
|
||||||
mtxA = Matrix44::FromArray(g_fProjectionMatrix) * viewMtx; // mtxA = projection x view
|
|
||||||
mtxB = s_viewportCorrection * mtxA; // mtxB = viewportCorrection x mtxA
|
|
||||||
memcpy(constants.projection.data(), mtxB.data.data(), 4 * sizeof(float4));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const auto projMtx = Common::Matrix44::FromArray(g_fProjectionMatrix);
|
|
||||||
const auto correctedMtx = s_viewportCorrection * projMtx;
|
|
||||||
memcpy(constants.projection.data(), correctedMtx.data.data(), 4 * sizeof(float4));
|
|
||||||
}
|
|
||||||
|
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -654,36 +639,25 @@ void VertexShaderManager::SetMaterialColorChanged(int index)
|
||||||
|
|
||||||
void VertexShaderManager::TranslateView(float x, float y, float z)
|
void VertexShaderManager::TranslateView(float x, float y, float z)
|
||||||
{
|
{
|
||||||
s_fViewTranslationVector += s_viewInvRotationMatrix * Common::Vec3{x, z, y};
|
s_freelook_matrix = Common::Matrix44::Translate({x, z, y}) * s_freelook_matrix;
|
||||||
|
|
||||||
bProjectionChanged = true;
|
bProjectionChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderManager::RotateView(float x, float y)
|
void VertexShaderManager::RotateView(float x, float y, float z)
|
||||||
{
|
{
|
||||||
using Common::Matrix33;
|
using Common::Matrix33;
|
||||||
|
|
||||||
s_fViewRotation[0] += x;
|
s_freelook_matrix = Common::Matrix44::FromMatrix33(Matrix33::RotateX(x) * Matrix33::RotateY(y) *
|
||||||
s_fViewRotation[1] += y;
|
Matrix33::RotateZ(z)) *
|
||||||
|
s_freelook_matrix;
|
||||||
s_viewRotationMatrix =
|
|
||||||
Matrix33::RotateX(s_fViewRotation[1]) * Matrix33::RotateY(s_fViewRotation[0]);
|
|
||||||
|
|
||||||
// reverse rotation
|
|
||||||
s_viewInvRotationMatrix =
|
|
||||||
Matrix33::RotateY(-s_fViewRotation[0]) * Matrix33::RotateX(-s_fViewRotation[1]);
|
|
||||||
|
|
||||||
bProjectionChanged = true;
|
bProjectionChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderManager::ResetView()
|
void VertexShaderManager::ResetView()
|
||||||
{
|
{
|
||||||
using Common::Matrix33;
|
s_freelook_matrix = Common::Matrix44::Identity();
|
||||||
|
|
||||||
s_fViewTranslationVector = {};
|
|
||||||
s_viewRotationMatrix = Matrix33::Identity();
|
|
||||||
s_viewInvRotationMatrix = Matrix33::Identity();
|
|
||||||
s_fViewRotation[0] = s_fViewRotation[1] = 0.0f;
|
|
||||||
|
|
||||||
bProjectionChanged = true;
|
bProjectionChanged = true;
|
||||||
}
|
}
|
||||||
|
@ -736,10 +710,7 @@ void VertexShaderManager::DoState(PointerWrap& p)
|
||||||
{
|
{
|
||||||
p.Do(g_fProjectionMatrix);
|
p.Do(g_fProjectionMatrix);
|
||||||
p.Do(s_viewportCorrection);
|
p.Do(s_viewportCorrection);
|
||||||
p.Do(s_viewRotationMatrix);
|
p.Do(s_freelook_matrix);
|
||||||
p.Do(s_viewInvRotationMatrix);
|
|
||||||
p.Do(s_fViewTranslationVector);
|
|
||||||
p.Do(s_fViewRotation);
|
|
||||||
|
|
||||||
p.Do(nTransformMatricesChanged);
|
p.Do(nTransformMatricesChanged);
|
||||||
p.Do(nNormalMatricesChanged);
|
p.Do(nNormalMatricesChanged);
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
static void SetMaterialColorChanged(int index);
|
static void SetMaterialColorChanged(int index);
|
||||||
|
|
||||||
static void TranslateView(float x, float y, float z = 0.0f);
|
static void TranslateView(float x, float y, float z = 0.0f);
|
||||||
static void RotateView(float x, float y);
|
static void RotateView(float x, float y, float z);
|
||||||
static void ResetView();
|
static void ResetView();
|
||||||
|
|
||||||
static void SetVertexFormat(u32 components);
|
static void SetVertexFormat(u32 components);
|
||||||
|
|
Loading…
Reference in New Issue