Fix camera drift issues (#4576)
* remove some unused code in RenderViewportWidget and make viewing devicePixelRatioF easier Signed-off-by: hultonha <hultonha@amazon.co.uk> * updates to how cursor positions are calculate to handle the viewport widget moving Signed-off-by: hultonha <hultonha@amazon.co.uk> * remove optional for previous position Signed-off-by: hultonha <hultonha@amazon.co.uk> * add test to capture error with moving the widget Signed-off-by: hultonha <hultonha@amazon.co.uk> * minor comment updates before publishing PR Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
+10
-10
@@ -261,10 +261,10 @@ namespace AzToolsFramework
|
||||
// ensures cursor positions are refreshed correctly with context menu focus changes)
|
||||
if (eventType == QEvent::FocusIn)
|
||||
{
|
||||
const auto widgetCursorPosition = m_sourceWidget->mapFromGlobal(QCursor::pos());
|
||||
if (m_sourceWidget->geometry().contains(widgetCursorPosition))
|
||||
const auto globalCursorPosition = QCursor::pos();
|
||||
if (m_sourceWidget->geometry().contains(globalCursorPosition))
|
||||
{
|
||||
HandleMouseMoveEvent(widgetCursorPosition);
|
||||
HandleMouseMoveEvent(globalCursorPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ namespace AzToolsFramework
|
||||
else if (eventType == QEvent::Type::MouseMove)
|
||||
{
|
||||
auto mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
HandleMouseMoveEvent(mouseEvent->pos());
|
||||
HandleMouseMoveEvent(mouseEvent->globalPos());
|
||||
}
|
||||
// Map wheel events to the mouse Z movement channel.
|
||||
else if (eventType == QEvent::Type::Wheel)
|
||||
@@ -370,11 +370,12 @@ namespace AzToolsFramework
|
||||
return QPoint{ denormalizedX, denormalizedY };
|
||||
}
|
||||
|
||||
void QtEventToAzInputMapper::HandleMouseMoveEvent(const QPoint& cursorPosition)
|
||||
void QtEventToAzInputMapper::HandleMouseMoveEvent(const QPoint& globalCursorPosition)
|
||||
{
|
||||
const QPoint cursorDelta = cursorPosition - m_previousCursorPosition;
|
||||
const QPoint cursorDelta = globalCursorPosition - m_previousGlobalCursorPosition;
|
||||
|
||||
m_mouseDevice->m_cursorPositionData2D->m_normalizedPosition = WidgetPositionToNormalizedPosition(cursorPosition);
|
||||
m_mouseDevice->m_cursorPositionData2D->m_normalizedPosition =
|
||||
WidgetPositionToNormalizedPosition(m_sourceWidget->mapFromGlobal(globalCursorPosition));
|
||||
m_mouseDevice->m_cursorPositionData2D->m_normalizedPositionDelta = WidgetPositionToNormalizedPosition(cursorDelta);
|
||||
|
||||
ProcessPendingMouseEvents(cursorDelta);
|
||||
@@ -382,12 +383,11 @@ namespace AzToolsFramework
|
||||
if (m_capturingCursor)
|
||||
{
|
||||
// Reset our cursor position to the previous point
|
||||
const QPoint screenCursorPosition = m_sourceWidget->mapToGlobal(m_previousCursorPosition);
|
||||
AzQtComponents::SetCursorPos(screenCursorPosition);
|
||||
AzQtComponents::SetCursorPos(m_previousGlobalCursorPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_previousCursorPosition = cursorPosition;
|
||||
m_previousGlobalCursorPosition = globalCursorPosition;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace AzToolsFramework
|
||||
// Handle mouse click events.
|
||||
void HandleMouseButtonEvent(QMouseEvent* mouseEvent);
|
||||
// Handle mouse move events.
|
||||
void HandleMouseMoveEvent(const QPoint& cursorPosition);
|
||||
void HandleMouseMoveEvent(const QPoint& globalCursorPosition);
|
||||
// Handles key press / release events (or ShortcutOverride events for keys listed in m_highPriorityKeys).
|
||||
void HandleKeyEvent(QKeyEvent* keyEvent);
|
||||
// Handles mouse wheel events.
|
||||
@@ -156,8 +156,8 @@ namespace AzToolsFramework
|
||||
AZStd::unordered_set<Qt::Key> m_highPriorityKeys;
|
||||
// A lookup table for AZ input channel ID -> physical input channel on our mouse or keyboard device.
|
||||
AZStd::unordered_map<AzFramework::InputChannelId, AzFramework::InputChannel*> m_channels;
|
||||
// Where the position of the mouse cursor was at the last cursor event.
|
||||
QPoint m_previousCursorPosition;
|
||||
// Where the mouse cursor was at the last cursor event.
|
||||
QPoint m_previousGlobalCursorPosition;
|
||||
// The source widget to map events from, used to calculate the relative mouse position within the widget bounds.
|
||||
QWidget* m_sourceWidget;
|
||||
// Flags whether or not Qt events should currently be processed.
|
||||
|
||||
Reference in New Issue
Block a user