Move abstract function updateStateFromInput to the concrete classes

This commit is contained in:
Malin E
2021-11-03 14:41:29 +01:00
parent 24ce66aad4
commit 23eed7f023
9 changed files with 17 additions and 15 deletions

View File

@@ -42,8 +42,6 @@ public:
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);

View File

@@ -74,7 +74,8 @@ public:
JoystickCameraStates(double sensitivity, double velocityScaleFactor);
void updateStateFromInput(const InputState& inputState, double deltaTime) override;
void updateStateFromInput(
const JoystickInputStates& joystickInputStates, double deltaTime);
void setAxisMapping(int axis, AxisType mapping,
AxisInvert shouldInvert = AxisInvert::No,

View File

@@ -33,7 +33,7 @@ class MouseCameraStates : public CameraInteractionStates {
public:
MouseCameraStates(double sensitivity, double velocityScaleFactor);
void updateStateFromInput(const InputState& inputState, double deltaTime) override;
void updateStateFromInput(const InputState& inputState, double deltaTime);
void setInvertMouseButton(bool value);

View File

@@ -33,7 +33,7 @@ class ScriptCameraStates : public CameraInteractionStates {
public:
ScriptCameraStates();
void updateStateFromInput(const InputState& inputState, double deltaTime) override;
void updateStateFromInput(double deltaTime);
void addLocalRotation(const glm::dvec2& delta);
void addGlobalRotation(const glm::dvec2& delta);

View File

@@ -65,7 +65,8 @@ public:
WebsocketCameraStates(double sensitivity, double velocityScaleFactor);
void updateStateFromInput(const InputState& inputState, double deltaTime) override;
void updateStateFromInput(
const WebsocketInputStates& websocketInputStates, double deltaTime);
void setAxisMapping(int axis, AxisType mapping,
AxisInvert shouldInvert = AxisInvert::No,

View File

@@ -37,7 +37,8 @@ JoystickCameraStates::JoystickCameraStates(double sensitivity, double velocitySc
: CameraInteractionStates(sensitivity, velocityScaleFactor)
{}
void JoystickCameraStates::updateStateFromInput(const InputState& inputState,
void JoystickCameraStates::updateStateFromInput(
const JoystickInputStates& joystickInputStates,
double deltaTime)
{
std::pair<bool, glm::dvec2> globalRotation = { false, glm::dvec2(0.0) };
@@ -52,7 +53,7 @@ void JoystickCameraStates::updateStateFromInput(const InputState& inputState,
continue;
}
float rawValue = inputState.joystickAxis(i);
float rawValue = joystickInputStates.axis(i);
float value = rawValue;
if (t.isSticky) {

View File

@@ -30,7 +30,7 @@ namespace openspace::interaction {
ScriptCameraStates::ScriptCameraStates() : CameraInteractionStates(1.0, 1.0) {}
void ScriptCameraStates::updateStateFromInput(const InputState&, double deltaTime) {
void ScriptCameraStates::updateStateFromInput(double deltaTime) {
if (_localRotation != glm::dvec2(0.0)) {
_localRotationState.velocity.set(
_localRotation * _sensitivity,

View File

@@ -39,7 +39,8 @@ WebsocketCameraStates::WebsocketCameraStates(double sensitivity,
: CameraInteractionStates(sensitivity, velocityScaleFactor)
{}
void WebsocketCameraStates::updateStateFromInput(const InputState& inputState,
void WebsocketCameraStates::updateStateFromInput(
const WebsocketInputStates& websocketInputStates,
double deltaTime)
{
std::pair<bool, glm::dvec2> globalRotation = { false, glm::dvec2(0.0) };
@@ -48,14 +49,14 @@ void WebsocketCameraStates::updateStateFromInput(const InputState& inputState,
std::pair<bool, glm::dvec2> globalRoll = { false, glm::dvec2(0.0) };
std::pair<bool, glm::dvec2> localRotation = { false, glm::dvec2(0.0) };
if (inputState.hasWebsocketStates()) {
if (!websocketInputStates.empty()) {
for (int i = 0; i < WebsocketInputState::MaxAxes; ++i) {
AxisInformation t = _axisMapping[i];
if (t.type == AxisType::None) {
continue;
}
float value = inputState.websocketAxis(i);
float value = websocketInputStates.axis(i);
bool hasValue = std::fabs(value) > t.deadzone;
if (!hasValue) {

View File

@@ -547,9 +547,9 @@ void OrbitalNavigator::updateStatesFromInput(const InputState& inputState,
double deltaTime)
{
_mouseStates.updateStateFromInput(inputState, deltaTime);
_joystickStates.updateStateFromInput(inputState, deltaTime);
_websocketStates.updateStateFromInput(inputState, deltaTime);
_scriptStates.updateStateFromInput(inputState, deltaTime);
_joystickStates.updateStateFromInput(*global::joystickInputStates, deltaTime);
_websocketStates.updateStateFromInput(*global::websocketInputStates, deltaTime);
_scriptStates.updateStateFromInput(deltaTime);
bool interactionHappened = _mouseStates.hasNonZeroVelocities() ||
_joystickStates.hasNonZeroVelocities() ||