Merge branch 'feature/remove-duplicate-code'

This commit is contained in:
Emil Axelsson
2019-04-24 13:38:19 +02:00
4 changed files with 1 additions and 185 deletions

View File

@@ -1,81 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___INPUTDEVICESTATES___H__
#define __OPENSPACE_CORE___INPUTDEVICESTATES___H__
#include <openspace/interaction/delayedvariable.h>
#include <ghoul/glm.h>
namespace openspace::interaction {
class InputState;
class CameraInteractionStates {
public:
/**
* \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.
*/
CameraInteractionStates(double sensitivity, double velocityScaleFactor);
virtual ~CameraInteractionStates() = default;
virtual void updateStateFromInput(const InputState& inputState, double deltaTime) = 0;
void setRotationalFriction(double friction);
void setHorizontalFriction(double friction);
void setVerticalFriction(double friction);
void setSensitivity(double sensitivity);
void setVelocityScaleFactor(double scaleFactor);
glm::dvec2 globalRotationVelocity() const;
glm::dvec2 localRotationVelocity() const;
glm::dvec2 truckMovementVelocity() const;
glm::dvec2 localRollVelocity() const;
glm::dvec2 globalRollVelocity() const;
protected:
struct InteractionState {
InteractionState(double scaleFactor);
void setFriction(double friction);
void setVelocityScaleFactor(double scaleFactor);
glm::dvec2 previousPosition;
DelayedVariable<glm::dvec2, double> velocity;
};
double _sensitivity;
InteractionState _globalRotationState;
InteractionState _localRotationState;
InteractionState _truckMovementState;
InteractionState _localRollState;
InteractionState _globalRollState;
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___INPUTDEVICESTATES___H__

View File

@@ -45,7 +45,6 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/engine/virtualpropertymanager.cpp
${OPENSPACE_BASE_DIR}/src/interaction/camerainteractionstates.cpp
${OPENSPACE_BASE_DIR}/src/interaction/inputstate.cpp
${OPENSPACE_BASE_DIR}/src/interaction/inputdevicestates.cpp
${OPENSPACE_BASE_DIR}/src/interaction/joystickinputstate.cpp
${OPENSPACE_BASE_DIR}/src/interaction/joystickcamerastates.cpp
${OPENSPACE_BASE_DIR}/src/interaction/keybindingmanager.cpp
@@ -226,7 +225,6 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/interaction/delayedvariable.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/delayedvariable.inl
${OPENSPACE_BASE_DIR}/include/openspace/interaction/camerainteractionstates.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/inputdevicestates.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/inputstate.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/interpolator.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/interpolator.inl

View File

@@ -22,7 +22,7 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/interaction/inputdevicestates.h>
#include <openspace/interaction/camerainteractionstates.h>
#include <openspace/interaction/inputstate.h>

View File

@@ -1,101 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/interaction/camerainteractionstates.h>
#include <openspace/interaction/inputstate.h>
namespace openspace::interaction {
CameraInteractionStates::InteractionState::InteractionState(double scaleFactor)
: previousPosition(0.0, 0.0)
, velocity(scaleFactor, 1)
{}
void CameraInteractionStates::InteractionState::setFriction(double friction) {
velocity.setFriction(friction);
}
void CameraInteractionStates::InteractionState::setVelocityScaleFactor(double scaleFactor)
{
velocity.setScaleFactor(scaleFactor);
}
CameraInteractionStates::CameraInteractionStates(double sensitivity,
double velocityScaleFactor)
: _sensitivity(sensitivity)
, _globalRotationState(velocityScaleFactor)
, _localRotationState(velocityScaleFactor)
, _truckMovementState(velocityScaleFactor)
, _localRollState(velocityScaleFactor)
, _globalRollState(velocityScaleFactor)
{}
void CameraInteractionStates::setRotationalFriction(double friction) {
_localRotationState.setFriction(friction);
_localRollState.setFriction(friction);
_globalRollState.setFriction(friction);
}
void CameraInteractionStates::setHorizontalFriction(double friction) {
_globalRotationState.setFriction(friction);
}
void CameraInteractionStates::setVerticalFriction(double friction) {
_truckMovementState.setFriction(friction);
}
void CameraInteractionStates::setSensitivity(double sensitivity) {
_sensitivity = sensitivity;
}
void CameraInteractionStates::setVelocityScaleFactor(double scaleFactor) {
_globalRotationState.setVelocityScaleFactor(scaleFactor);
_localRotationState.setVelocityScaleFactor(scaleFactor);
_truckMovementState.setVelocityScaleFactor(scaleFactor);
_localRollState.setVelocityScaleFactor(scaleFactor);
_globalRollState.setVelocityScaleFactor(scaleFactor);
}
glm::dvec2 CameraInteractionStates::globalRotationVelocity() const{
return _globalRotationState.velocity.get();
}
glm::dvec2 CameraInteractionStates::localRotationVelocity() const{
return _localRotationState.velocity.get();
}
glm::dvec2 CameraInteractionStates::truckMovementVelocity() const{
return _truckMovementState.velocity.get();
}
glm::dvec2 CameraInteractionStates::localRollVelocity() const{
return _localRollState.velocity.get();
}
glm::dvec2 CameraInteractionStates::globalRollVelocity() const{
return _globalRollState.velocity.get();
}
} // namespace openspace::interaction