Skip to content
Permalink
Browse files

Experiment with capturing cursor via ~ press

  • Loading branch information
nyalldawson committed Jan 13, 2021
1 parent 3d9afb5 commit 2b9d77281c49d7f4f662138678210e059f66b506
Showing with 25 additions and 3 deletions.
  1. +24 −3 src/3d/qgscameracontroller.cpp
  2. +1 −0 src/3d/qgscameracontroller.h
@@ -430,6 +430,19 @@ void QgsCameraController::onMouseReleased( Qt3DInput::QMouseEvent *mouse )

void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
{
if ( event->key() == Qt::Key_QuoteLeft )
{
if ( mCameraNavigationMode == NavigationMode::FlyNavigation )
{
mCaptureFpsMouseMovements = !mCaptureFpsMouseMovements;
if ( mCaptureFpsMouseMovements )
qApp->setOverrideCursor( QCursor( Qt::BlankCursor ) );
else
qApp->restoreOverrideCursor();
return;
}
}

if ( mCameraNavigationMode == NavigationMode::FlyNavigation )
{
if ( event->isAutoRepeat() )
@@ -550,11 +563,12 @@ void QgsCameraController::onKeyPressedFlyNavigation()

void QgsCameraController::onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse )
{
if ( !mMousePressed )
if ( !mMousePressed && !mCaptureFpsMouseMovements )
return;

double dx = mouse->x() - mMousePos.x();
double dy = mouse->y() - mMousePos.y();
if ( mPressedButton == Qt3DInput::QMouseEvent::LeftButton || mPressedButton == Qt3DInput::QMouseEvent::MiddleButton )
if ( mPressedButton == Qt3DInput::QMouseEvent::LeftButton || mPressedButton == Qt3DInput::QMouseEvent::MiddleButton || ( mCaptureFpsMouseMovements && mPressedButton != Qt3DInput::QMouseEvent::RightButton ) )
{
float diffPitch = 0.2f * dy;
float diffYaw = - 0.2f * dx;
@@ -570,7 +584,14 @@ void QgsCameraController::onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent
moveCameraPositionBy( 5.0 * mCameraMovementSpeed * cameraPosDiff );
}

mMousePos = QPoint( mouse->x(), mouse->y() );
if ( mCaptureFpsMouseMovements )
{
QCursor::setPos( QCursor::pos().x() - dx, QCursor::pos().y() - dy );
}
else
{
mMousePos = QPoint( mouse->x(), mouse->y() );
}
}

void QgsCameraController::onKeyReleased( Qt3DInput::QKeyEvent *event )
@@ -234,6 +234,7 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
double mCameraMovementSpeed = 5.0;

QSet< int > mDepressedKeys;
bool mCaptureFpsMouseMovements = false;
QTimer *mFpsNavTimer = nullptr;
};

0 comments on commit 2b9d772

Please sign in to comment.
You can’t perform that action at this time.