Skip to content

Commit

Permalink
Rename "fly" navigation mode as "walk" mode
Browse files Browse the repository at this point in the history
Fly has a different meaning here, where motion has inertia and the
key presses affect the acceleration of motion instead of directly
move the camera.
  • Loading branch information
nyalldawson committed Jan 14, 2021
1 parent 93a3c6b commit 275a810
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/3d/qgs3dmapsettings.cpp
Expand Up @@ -105,8 +105,8 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
QString cameraNavigationMode = elemCamera.attribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "basic-navigation" ) );
if ( cameraNavigationMode == QStringLiteral( "terrain-based-navigation" ) )
mCameraNavigationMode = QgsCameraController::NavigationMode::TerrainBasedNavigation;
else if ( cameraNavigationMode == QStringLiteral( "fly-navigation" ) )
mCameraNavigationMode = QgsCameraController::NavigationMode::FlyNavigation;
else if ( cameraNavigationMode == QStringLiteral( "walk-navigation" ) )
mCameraNavigationMode = QgsCameraController::NavigationMode::WalkNavigation;
mCameraMovementSpeed = elemCamera.attribute( QStringLiteral( "camera-movement-speed" ), QStringLiteral( "5.0" ) ).toDouble();
}

Expand Down Expand Up @@ -306,8 +306,8 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
case QgsCameraController::TerrainBasedNavigation:
elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "terrain-based-navigation" ) );
break;
case QgsCameraController::FlyNavigation:
elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "fly-navigation" ) );
case QgsCameraController::WalkNavigation:
elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "walk-navigation" ) );
break;
}
elemCamera.setAttribute( QStringLiteral( "camera-movement-speed" ), mCameraMovementSpeed );
Expand Down
12 changes: 6 additions & 6 deletions src/3d/qgscameracontroller.cpp
Expand Up @@ -325,7 +325,7 @@ void QgsCameraController::moveCameraPositionBy( const QVector3D &posDiff )

void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
{
if ( mCameraNavigationMode == NavigationMode::FlyNavigation )
if ( mCameraNavigationMode == NavigationMode::WalkNavigation )
{
onPositionChangedFlyNavigation( mouse );
return;
Expand Down Expand Up @@ -394,7 +394,7 @@ void QgsCameraController::zoom( float factor )

void QgsCameraController::onWheel( Qt3DInput::QWheelEvent *wheel )
{
if ( mCameraNavigationMode == QgsCameraController::FlyNavigation )
if ( mCameraNavigationMode == QgsCameraController::WalkNavigation )
{
float scaling = ( ( wheel->modifiers() & Qt::ControlModifier ) ? 0.1f : 1.0f ) / 1000.f;
mCameraMovementSpeed += mCameraMovementSpeed * scaling * wheel->angleDelta().y();
Expand Down Expand Up @@ -437,11 +437,11 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
{
switch ( mCameraNavigationMode )
{
case NavigationMode::FlyNavigation:
case NavigationMode::WalkNavigation:
mCameraNavigationMode = NavigationMode::TerrainBasedNavigation;
break;
case NavigationMode::TerrainBasedNavigation:
mCameraNavigationMode = NavigationMode::FlyNavigation;
mCameraNavigationMode = NavigationMode::WalkNavigation;
break;
}
emit navigationModeHotKeyPressed( mCameraNavigationMode );
Expand All @@ -450,7 +450,7 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )

if ( event->key() == Qt::Key_QuoteLeft )
{
if ( mCameraNavigationMode == NavigationMode::FlyNavigation )
if ( mCameraNavigationMode == NavigationMode::WalkNavigation )
{
mCaptureFpsMouseMovements = !mCaptureFpsMouseMovements;
if ( mCaptureFpsMouseMovements )
Expand All @@ -467,7 +467,7 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
}
}

if ( mCameraNavigationMode == NavigationMode::FlyNavigation )
if ( mCameraNavigationMode == NavigationMode::WalkNavigation )
{
if ( event->isAutoRepeat() )
return;
Expand Down
3 changes: 2 additions & 1 deletion src/3d/qgscameracontroller.h
Expand Up @@ -63,11 +63,12 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
Q_PROPERTY( Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged )
Q_PROPERTY( QRect viewport READ viewport WRITE setViewport NOTIFY viewportChanged )
public:

//! The navigation mode used by the camera
enum NavigationMode
{
TerrainBasedNavigation, //! The default navigation based on the terrain
FlyNavigation //! uses WASD keys or arrows to navigate in flying manner
WalkNavigation //! Uses WASD keys or arrows to navigate in walking (first person) manner
};

public:
Expand Down
9 changes: 6 additions & 3 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Expand Up @@ -52,6 +52,9 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
const int iconSize = QgsGuiUtils::scaleIconSize( 20 );
m3DOptionsListWidget->setIconSize( QSize( iconSize, iconSize ) ) ;

mCameraNavigationModeCombo->addItem( tr( "Terrain Based" ), QgsCameraController::TerrainBasedNavigation );
mCameraNavigationModeCombo->addItem( tr( "Walk Mode (First Person)" ), QgsCameraController::WalkNavigation );

// get rid of annoying outer focus rect on Mac
m3DOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect, false );
m3DOptionsListWidget->setCurrentRow( settings.value( QStringLiteral( "Windows/3DMapConfig/Tab" ), 0 ).toInt() );
Expand Down Expand Up @@ -135,7 +138,7 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas

spinCameraFieldOfView->setValue( mMap->fieldOfView() );
cboCameraProjectionType->setCurrentIndex( cboCameraProjectionType->findData( mMap->projectionType() ) );
mCameraNavigationMode->setCurrentIndex( mMap->cameraNavigationMode() );
mCameraNavigationModeCombo->setCurrentIndex( mCameraNavigationModeCombo->findData( mMap->cameraNavigationMode() ) );
mCameraMovementSpeed->setValue( mMap->cameraMovementSpeed() );
spinTerrainScale->setValue( mMap->terrainVerticalScale() );
spinMapResolution->setValue( mMap->mapTileResolution() );
Expand Down Expand Up @@ -320,8 +323,8 @@ void Qgs3DMapConfigWidget::apply()

mMap->setFieldOfView( spinCameraFieldOfView->value() );
mMap->setProjectionType( cboCameraProjectionType->currentData().value< Qt3DRender::QCameraLens::ProjectionType >() );
mMap->setCameraNavigationMode( static_cast<QgsCameraController::NavigationMode>( mCameraNavigationMode->currentIndex() ) );
m3DMapCanvas->scene()->cameraController()->setCameraNavigationMode( static_cast<QgsCameraController::NavigationMode>( mCameraNavigationMode->currentIndex() ) );
mMap->setCameraNavigationMode( static_cast<QgsCameraController::NavigationMode>( mCameraNavigationModeCombo->currentData().toInt() ) );
m3DMapCanvas->scene()->cameraController()->setCameraNavigationMode( mMap->cameraNavigationMode() );
mMap->setCameraMovementSpeed( mCameraMovementSpeed->value() );
mMap->setTerrainVerticalScale( spinTerrainScale->value() );
mMap->setMapTileResolution( spinMapResolution->value() );
Expand Down
31 changes: 10 additions & 21 deletions src/ui/3d/map3dconfigwidget.ui
Expand Up @@ -205,8 +205,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>309</width>
<height>292</height>
<width>341</width>
<height>301</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayoutTerrain">
Expand Down Expand Up @@ -410,8 +410,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>77</width>
<height>45</height>
<width>98</width>
<height>47</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayoutLight">
Expand Down Expand Up @@ -494,8 +494,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>140</width>
<height>45</height>
<width>151</width>
<height>47</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayoutShadow">
Expand Down Expand Up @@ -584,7 +584,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>704</width>
<width>710</width>
<height>604</height>
</rect>
</property>
Expand Down Expand Up @@ -642,18 +642,7 @@
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="mCameraNavigationMode">
<item>
<property name="text">
<string>Terrain Based Navigation</string>
</property>
</item>
<item>
<property name="text">
<string>Fly Navigation</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="mCameraNavigationModeCombo"/>
</item>
<item row="4" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="mCameraMovementSpeed">
Expand Down Expand Up @@ -735,8 +724,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>277</width>
<height>681</height>
<width>304</width>
<height>701</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayoutAdvanced">
Expand Down

0 comments on commit 275a810

Please sign in to comment.