mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 19:50:03 -06:00
Interaction mode inertia is no longer dependent on the framerate.
This commit is contained in:
@@ -206,14 +206,15 @@ protected:
|
||||
will be updates as soon as it is set to a value (calling the set() function).
|
||||
*/
|
||||
template <typename T, typename ScaleType>
|
||||
class delayedVariable {
|
||||
class DelayedVariable {
|
||||
public:
|
||||
delayedVariable(ScaleType scale) {
|
||||
DelayedVariable(ScaleType scale) {
|
||||
_scale = scale;
|
||||
}
|
||||
void set(T value) {
|
||||
void set(T value, double dt) {
|
||||
_targetValue = value;
|
||||
_currentValue = _currentValue + (_targetValue - _currentValue) * _scale;
|
||||
_currentValue = _currentValue + (_targetValue - _currentValue) *
|
||||
min(_scale * dt, 1.0); // less or equal to 1.0 keeps it stable
|
||||
}
|
||||
T get() {
|
||||
return _currentValue;
|
||||
@@ -229,7 +230,7 @@ protected:
|
||||
: velocity(scale)
|
||||
, previousPosition(0.0, 0.0) {}
|
||||
glm::dvec2 previousPosition;
|
||||
delayedVariable<glm::dvec2, double> velocity;
|
||||
DelayedVariable<glm::dvec2, double> velocity;
|
||||
};
|
||||
|
||||
std::shared_ptr<InputState> _inputState;
|
||||
@@ -251,6 +252,12 @@ private:
|
||||
class OrbitalInteractionMode : public InteractionMode
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
\param inputState
|
||||
\param sensitivity
|
||||
\param velocityScalefactor can be set to 60 to remove the inertia of the
|
||||
interaction. Lower value will make it harder to move the camera.
|
||||
*/
|
||||
OrbitalInteractionMode(
|
||||
std::shared_ptr<InputState> inputState,
|
||||
double sensitivity,
|
||||
|
||||
@@ -778,44 +778,44 @@ void OrbitalInteractionMode::updateMouseStatesFromInput(double deltaTime) {
|
||||
if (keyCtrlPressed) {
|
||||
glm::dvec2 mousePositionDelta =
|
||||
_localRotationMouseState.previousPosition - mousePosition;
|
||||
_localRotationMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity);
|
||||
_localRotationMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity, deltaTime);
|
||||
|
||||
_globalRotationMouseState.previousPosition = mousePosition;
|
||||
_globalRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
_globalRotationMouseState.velocity.set(glm::dvec2(0, 0), deltaTime);
|
||||
}
|
||||
else {
|
||||
glm::dvec2 mousePositionDelta =
|
||||
_globalRotationMouseState.previousPosition - mousePosition;
|
||||
_globalRotationMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity);
|
||||
_globalRotationMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity, deltaTime);
|
||||
|
||||
_localRotationMouseState.previousPosition = mousePosition;
|
||||
_localRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
_localRotationMouseState.velocity.set(glm::dvec2(0, 0), deltaTime);
|
||||
}
|
||||
}
|
||||
else { // !button1Pressed
|
||||
_localRotationMouseState.previousPosition = mousePosition;
|
||||
_localRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
_localRotationMouseState.velocity.set(glm::dvec2(0, 0), deltaTime);
|
||||
|
||||
_globalRotationMouseState.previousPosition = mousePosition;
|
||||
_globalRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
_globalRotationMouseState.velocity.set(glm::dvec2(0, 0), deltaTime);
|
||||
}
|
||||
if (button2Pressed) {
|
||||
glm::dvec2 mousePositionDelta =
|
||||
_truckMovementMouseState.previousPosition - mousePosition;
|
||||
_truckMovementMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity);
|
||||
_truckMovementMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity, deltaTime);
|
||||
}
|
||||
else { // !button2Pressed
|
||||
_truckMovementMouseState.previousPosition = mousePosition;
|
||||
_truckMovementMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
_truckMovementMouseState.velocity.set(glm::dvec2(0, 0), deltaTime);
|
||||
}
|
||||
if (button3Pressed) {
|
||||
glm::dvec2 mousePositionDelta =
|
||||
_rollMouseState.previousPosition - mousePosition;
|
||||
_rollMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity);
|
||||
_rollMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity, deltaTime);
|
||||
}
|
||||
else { // !button3Pressed
|
||||
_rollMouseState.previousPosition = mousePosition;
|
||||
_rollMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
_rollMouseState.velocity.set(glm::dvec2(0, 0), deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1013,9 +1013,9 @@ InteractionHandler::InteractionHandler()
|
||||
// Create the interactionModes
|
||||
_inputState = std::shared_ptr<InputState>(new InputState());
|
||||
_orbitalInteractionMode = std::shared_ptr<OrbitalInteractionMode>(
|
||||
new OrbitalInteractionMode(_inputState, 0.002, 0.02));
|
||||
new OrbitalInteractionMode(_inputState, 0.002, 1));
|
||||
_globebrowsingInteractionMode = std::shared_ptr<GlobeBrowsingInteractionMode>(
|
||||
new GlobeBrowsingInteractionMode(_inputState, 0.002, 0.02));
|
||||
new GlobeBrowsingInteractionMode(_inputState, 0.002, 1));
|
||||
|
||||
// Set the interactionMode
|
||||
_currentInteractionMode = _orbitalInteractionMode;
|
||||
|
||||
Reference in New Issue
Block a user