mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
AppFwk: Added optional adaptive rotation sensitivity to CAD and Ceetron Plus navigation policies
This commit is contained in:
@@ -93,6 +93,8 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
}
|
||||
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
||||
m_roationSensitivityCalculator.init(me);
|
||||
|
||||
m_isNavigating = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
isEventHandled = true;
|
||||
@@ -137,6 +139,9 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
|
||||
if (m_isNavigating)
|
||||
{
|
||||
double sensitivity = m_roationSensitivityCalculator.calculateSensitivity(me);
|
||||
|
||||
m_trackball->setRotationSensitivity(sensitivity);
|
||||
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
||||
if(needRedraw)
|
||||
{
|
||||
|
||||
@@ -95,6 +95,8 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
}
|
||||
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
||||
m_roationSensitivityCalculator.init(me);
|
||||
|
||||
m_isNavigating = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
isEventHandled = true;
|
||||
@@ -174,7 +176,11 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
}
|
||||
else
|
||||
{
|
||||
double sensitivity = m_roationSensitivityCalculator.calculateSensitivity(me);
|
||||
|
||||
m_trackball->setRotationSensitivity(sensitivity);
|
||||
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
||||
|
||||
if (needRedraw)
|
||||
{
|
||||
m_viewer->navigationPolicyUpdate();
|
||||
|
||||
@@ -297,3 +297,66 @@ bool caf::TrackBallBasedNavigation::shouldRaytraceForNewPoiDuringWheelZoom(int z
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
//#include <windows.h>
|
||||
//
|
||||
//#pragma warning(disable:4996)
|
||||
//void openDebugWindow()
|
||||
//{
|
||||
// AllocConsole();
|
||||
// freopen("conin$", "r", stdin);
|
||||
// freopen("conout$", "w", stdout);
|
||||
// freopen("conout$", "w", stderr);
|
||||
//}
|
||||
//
|
||||
//#include <iostream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::RotationSensitivityCalculator::init(QMouseEvent* eventAtRotationStart)
|
||||
{
|
||||
m_lastPosX = eventAtRotationStart->x();
|
||||
m_lastPosY = eventAtRotationStart->y();
|
||||
m_lastTime = eventAtRotationStart->timestamp();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double caf::RotationSensitivityCalculator::calculateSensitivity(QMouseEvent* eventWhenRotating )
|
||||
{
|
||||
double sensitivity = 1.0;
|
||||
|
||||
if ( m_isEnabled )
|
||||
{
|
||||
auto presentTime = eventWhenRotating->timestamp();
|
||||
unsigned long timeSinceLast = presentTime - m_lastTime;
|
||||
if ( timeSinceLast == 0 ) timeSinceLast = 1; // one millisecond
|
||||
|
||||
int deltaX = eventWhenRotating->x() - m_lastPosX;
|
||||
int deltaY = eventWhenRotating->y() - m_lastPosY;
|
||||
|
||||
cvf::Vec2d mouseVelocity(deltaX, deltaY);
|
||||
mouseVelocity /= 1.0e-3*timeSinceLast;
|
||||
|
||||
double mouseVelocityLength = mouseVelocity.length();
|
||||
double mouseVelocityLengthCorr = 0.3*mouseVelocityLength + 0.7*m_lastMouseVelocityLenght;
|
||||
|
||||
double slowLimit = 170.0;
|
||||
|
||||
if ( mouseVelocityLengthCorr < slowLimit ) sensitivity = mouseVelocityLengthCorr*mouseVelocityLengthCorr/(slowLimit*slowLimit);
|
||||
|
||||
m_lastPosX = eventWhenRotating->x();
|
||||
m_lastPosY = eventWhenRotating->y();
|
||||
m_lastTime = eventWhenRotating->timestamp();
|
||||
m_lastMouseVelocityLenght = 0.8*mouseVelocityLength + 0.2*m_lastMouseVelocityLenght;
|
||||
|
||||
//openDebugWindow();
|
||||
//std::cout << sensitivity << " Speed: " << mouseVelocity.length() << " " << mouseVelocityLengthCorr << " \tDelta " << deltaX << ", " << deltaY << " "<< timeSinceLast << std::endl;
|
||||
}
|
||||
|
||||
return sensitivity;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,36 @@ namespace cvf {
|
||||
class Ray;
|
||||
}
|
||||
|
||||
class QMouseEvent;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class RotationSensitivityCalculator
|
||||
{
|
||||
public:
|
||||
RotationSensitivityCalculator()
|
||||
: m_lastPosX(0)
|
||||
, m_lastPosY(0)
|
||||
, m_lastMouseVelocityLenght(200)
|
||||
, m_isEnabled(false)
|
||||
{}
|
||||
|
||||
void enable(bool enable) { m_isEnabled = enable; }
|
||||
void init(QMouseEvent* eventAtRotationStart);
|
||||
|
||||
double calculateSensitivity(QMouseEvent* eventWhenRotating);
|
||||
|
||||
private:
|
||||
bool m_isEnabled;
|
||||
int m_lastPosX; /// Previous mouse position
|
||||
int m_lastPosY;
|
||||
unsigned long m_lastTime;
|
||||
double m_lastMouseVelocityLenght;
|
||||
};
|
||||
|
||||
} // End namespace caf
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -62,6 +92,7 @@ public:
|
||||
~TrackBallBasedNavigation() override;
|
||||
void enableEventEating(bool enable) { m_consumeEvents = enable; }
|
||||
void enableRotation(bool enable) { m_isRotationEnabled = enable; }
|
||||
void enableAdaptiveRotationSensitivity(bool enable) { m_roationSensitivityCalculator.enable(enable); }
|
||||
|
||||
protected:
|
||||
// General navigation policy overrides
|
||||
@@ -78,6 +109,7 @@ protected:
|
||||
cvf::ref<cvf::ManipulatorTrackball> m_trackball;
|
||||
bool m_isRotCenterInitialized;
|
||||
cvf::Vec3d m_pointOfInterest;
|
||||
RotationSensitivityCalculator m_roationSensitivityCalculator;
|
||||
|
||||
bool m_isNavigating;
|
||||
bool m_hasMovedMouseDuringNavigation;
|
||||
|
||||
Reference in New Issue
Block a user