Address PR comments

This commit is contained in:
Malin Ejdbo
2021-05-20 13:44:45 +02:00
parent 0d06c68f6f
commit 80eba3bdd9
7 changed files with 28 additions and 28 deletions
+9 -9
View File
@@ -82,11 +82,11 @@ local bindLocalRoll = function(axis)
-- We only want to store the current state in the first mode that is enabled, otherwise we will overwrite the backup
if not Joystick.State.IsInRollMode then
-- Save current axis state
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
end
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
Joystick.State.IsInRollMode = true
]]
end
@@ -96,11 +96,11 @@ local bindGlobalRoll = function(axis)
-- We only want to store the current state in the first mode that is enabled, otherwise we will overwrite the backup
if not Joystick.State.IsInRollMode then
-- Save current axis state
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
end
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
Joystick.State.IsInRollMode = true
]]
end
@@ -108,27 +108,27 @@ end
local permaBindLocalRoll = function(axis)
return [[
-- Save current axis state
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
]]
end
local permaBindGlobalRoll = function(axis)
return [[
-- Save current axis state
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
]]
end
local unbindRoll = function(axis)
return [[
-- Reset previous state
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Static, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. axis .. [[, Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
]]
end
@@ -63,8 +63,8 @@ public:
// The axis values can either go back to 0 when the joystick is released or it can
// stay at the value it was before the joystick was released.
// The latter is called a static axis, when the values don't go back to 0.
bool isStatic = false;
// The latter is called a sticky axis, when the values don't go back to 0.
bool isSticky = false;
float deadzone = 0.f;
@@ -79,7 +79,7 @@ public:
void setAxisMapping(int axis, AxisType mapping,
AxisInvert shouldInvert = AxisInvert::No,
AxisNormalize shouldNormalize = AxisNormalize::No,
bool isStatic = false, double sensitivity = 0.0
bool isSticky = false, double sensitivity = 0.0
);
AxisInformation axisMapping(int axis) const;
@@ -102,7 +102,7 @@ private:
std::array<AxisInformation, JoystickInputState::MaxAxes> _axisMapping;
// This array is used to store the old axis values from the previous frame,
// it is used to calculate the difference in the values in the case of a static axis
// it is used to calculate the difference in the values in the case of a sticky axis
std::array<float, JoystickInputState::MaxAxes> _prevAxisValues;
struct ButtonInformation {
@@ -73,8 +73,8 @@ struct JoystickInputState {
/// The axis values can either go back to 0 when the joystick is released or it can
/// stay at the value it was before the joystick was released.
/// The latter is called a static axis, when the values don't go back to 0.
bool isStatic = false;
/// The latter is called a sticky axis, when the values don't go back to 0.
bool isSticky = false;
/// The number of buttons that this joystick possesses
int nButtons = 0;
@@ -116,7 +116,7 @@ public:
JoystickCameraStates::AxisInvert::No,
JoystickCameraStates::AxisNormalize shouldNormalize =
JoystickCameraStates::AxisNormalize::No,
bool isStatic = false, double sensitivity = 0.0
bool isSticky = false, double sensitivity = 0.0
);
JoystickCameraStates::AxisInformation joystickAxisMapping(int axis) const;
+6 -6
View File
@@ -55,7 +55,7 @@ void JoystickCameraStates::updateStateFromInput(const InputState& inputState,
float rawValue = inputState.joystickAxis(i);
float value = rawValue;
if (t.isStatic) {
if (t.isSticky) {
value = rawValue - _prevAxisValues[i];
_prevAxisValues[i] = rawValue;
}
@@ -72,7 +72,7 @@ void JoystickCameraStates::updateStateFromInput(const InputState& inputState,
value *= -1.f;
}
if (std::fabs(t.sensitivity) > std::numeric_limits<double>().epsilon()) {
if (std::abs(t.sensitivity) > std::numeric_limits<double>::epsilon()) {
value = static_cast<float>(value * t.sensitivity * _sensitivity);
}
else {
@@ -179,7 +179,7 @@ void JoystickCameraStates::updateStateFromInput(const InputState& inputState,
void JoystickCameraStates::setAxisMapping(int axis, AxisType mapping,
AxisInvert shouldInvert,
AxisNormalize shouldNormalize,
bool isStatic,
bool isSticky,
double sensitivity)
{
ghoul_assert(axis < JoystickInputState::MaxAxes, "axis must be < MaxAxes");
@@ -187,11 +187,11 @@ void JoystickCameraStates::setAxisMapping(int axis, AxisType mapping,
_axisMapping[axis].type = mapping;
_axisMapping[axis].invert = shouldInvert;
_axisMapping[axis].normalize = shouldNormalize;
_axisMapping[axis].isStatic = isStatic;
_axisMapping[axis].isSticky = isSticky;
_axisMapping[axis].sensitivity = sensitivity;
if (isStatic) {
global::joystickInputStates->at(axis).isStatic = true;
if (isSticky) {
global::joystickInputStates->at(axis).isSticky = true;
}
_prevAxisValues[axis] = global::joystickInputStates->axis(axis);
+2 -2
View File
@@ -493,7 +493,7 @@ void NavigationHandler::setJoystickAxisMapping(int axis,
JoystickCameraStates::AxisType mapping,
JoystickCameraStates::AxisInvert shouldInvert,
JoystickCameraStates::AxisNormalize shouldNormalize,
bool isStatic,
bool isSticky,
double sensitivity)
{
_orbitalNavigator.joystickStates().setAxisMapping(
@@ -501,7 +501,7 @@ void NavigationHandler::setJoystickAxisMapping(int axis,
mapping,
shouldInvert,
shouldNormalize,
isStatic,
isSticky,
sensitivity
);
}
+4 -4
View File
@@ -199,7 +199,7 @@ int bindJoystickAxis(lua_State* L) {
const bool shouldInvert = n > 2 ? ghoul::lua::value<bool>(L, 3) : false;
const bool shouldNormalize = n > 3 ? ghoul::lua::value<bool>(L, 4) : false;
const bool isStatic = n > 4 ? ghoul::lua::value<bool>(L, 5) : false;
const bool isSticky = n > 4 ? ghoul::lua::value<bool>(L, 5) : false;
const double sensitivity = n > 5 ? ghoul::lua::value<double>(L, 6) : 0.0;
global::navigationHandler->setJoystickAxisMapping(
@@ -207,7 +207,7 @@ int bindJoystickAxis(lua_State* L) {
ghoul::from_string<interaction::JoystickCameraStates::AxisType>(axisType),
interaction::JoystickCameraStates::AxisInvert(shouldInvert),
interaction::JoystickCameraStates::AxisNormalize(shouldNormalize),
isStatic,
isSticky,
sensitivity
);
@@ -227,9 +227,9 @@ int joystickAxis(lua_State* L) {
lua_settop(L, 0);
const bool invert = info.invert;
const bool normalize = info.normalize;
const bool isStatic = info.isStatic;
const bool isSticky = info.isSticky;
const float sensitivity = info.sensitivity;
ghoul::lua::push(L, ghoul::to_string(info.type), invert, normalize, isStatic, sensitivity);
ghoul::lua::push(L, ghoul::to_string(info.type), invert, normalize, isSticky, sensitivity);
ghoul_assert(lua_gettop(L) == 5, "Incorrect number of items left on stack");
return 5;