Skip to content

Commit

Permalink
Experiment with capturing cursor via ~ press
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 13, 2021
1 parent 3d9afb5 commit 2b9d772
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/3d/qgscameracontroller.cpp
Expand Up @@ -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() )
Expand Down Expand Up @@ -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;
Expand All @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/3d/qgscameracontroller.h
Expand Up @@ -234,6 +234,7 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
double mCameraMovementSpeed = 5.0;

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

Expand Down

0 comments on commit 2b9d772

Please sign in to comment.