Skip to content

Commit

Permalink
Try scaling input values by time
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 3, 2023
1 parent 8595e5f commit cb34a49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/gui/inputcontroller/qgs3dgamepadcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/

#include "qgs3dgamepadcontroller.h"
#include "qgslogger.h"

#ifdef HAVE_QTGAMEPAD

Expand Down Expand Up @@ -96,6 +97,8 @@ void QgsGamepad3DMapController::updateNavigation()
disconnect( mGamepad.data(), &QGamepad::buttonR2Changed, this, &QgsGamepad3DMapController::updateNavigation );

mTimer->start( 50 );
mElapsedTimer.restart();

navigationTimeout();
}
}
Expand All @@ -114,6 +117,14 @@ void QgsGamepad3DMapController::navigationTimeout()
return;
}

const qint64 elapsed = mElapsedTimer.elapsed();
mElapsedTimer.restart();

const double scale = std::min( 2.0, static_cast< double >( elapsed ) / 50 );
if ( !qgsDoubleNear( scale, 1 ))
{
// QgsDebugError( QStringLiteral("%1").arg( scale ));
}
constexpr double maxPitchYaw = 5;
constexpr double expPitchYaw = 3;

Expand Down Expand Up @@ -141,9 +152,9 @@ void QgsGamepad3DMapController::navigationTimeout()
moveZ = scaleExp( mGamepad->buttonL2(), 0, 1, 0, 1, expMovement ) * -1 + scaleExp( mGamepad->buttonR2(), 0, 1, 0, 1, expMovement );
}

if ( moveX != 0.0 || moveY != 0.0 || moveZ != 0.0 )
if ( !qgsDoubleNear( moveX * scale, 0.0 ) || qgsDoubleNear( moveY * scale, 0.0 ) || !qgsDoubleNear( moveZ * scale, 0.0 ) )
{
emit walkView( moveX, moveY, moveZ );
emit walkView( scale * moveX, scale* moveY,scale* moveZ );
}

double pitch = 0.0;
Expand All @@ -156,7 +167,8 @@ void QgsGamepad3DMapController::navigationTimeout()
{
yaw = scaleExp( std::fabs( mGamepad->axisRightX() ), 0, 1, 0, maxPitchYaw, expPitchYaw ) * ( mGamepad->axisRightX() > 0 ? -1 : 1 );
}
emit rotateCamera( pitch, yaw );
if ( !qgsDoubleNear( scale * pitch, 0 ) || !qgsDoubleNear( scale * yaw, 0 ) )
emit rotateCamera( scale * pitch, scale * yaw );
}

double QgsGamepad3DMapController::axisMax()
Expand Down
2 changes: 2 additions & 0 deletions src/gui/inputcontroller/qgs3dgamepadcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SIP_IF_MODULE( HAVE_QTGAMEPAD )
#include "qgs3dmapcontroller.h"

#include <QPointer>
#include <QElapsedTimer>

#ifdef SIP_RUN
// this is needed for the "convert to subclass" code below to compile
Expand Down Expand Up @@ -380,6 +381,7 @@ class GUI_EXPORT QgsGamepad3DMapController : public QgsAbstract3DMapController
int mGamepadDeviceId = -1;
QPointer< QGamepad> mGamepad;
QTimer *mTimer = nullptr;
QElapsedTimer mElapsedTimer;
};


Expand Down

0 comments on commit cb34a49

Please sign in to comment.