Exchange normalisation property for joysticks to JoystickType

* Joysticks can either be "JoystickLike" or "TriggerLike", where the
  triggers are normalized and have the deadzone close to -1 instead to 0

* Solves issue with zoom friction not to turn off for controllers
This commit is contained in:
Malin E
2021-11-12 11:46:17 +01:00
parent e075f8ae82
commit 3fdae48092
10 changed files with 93 additions and 53 deletions

View File

@@ -9,11 +9,11 @@ local bindLocalRoll = function(name, 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.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
end
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
Joystick.State.IsInRollMode = true
]]
end
@@ -23,11 +23,11 @@ local bindGlobalRoll = function(name, 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.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
end
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
Joystick.State.IsInRollMode = true
]]
end
@@ -35,27 +35,27 @@ end
local permaBindLocalRoll = function(name, axis)
return [[
-- Save current axis state
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "LocalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
]]
end
local permaBindGlobalRoll = function(name, axis)
return [[
-- Save current axis state
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity = openspace.navigation.joystickAxis(]] .. axis .. [[)
-- Set new axis state
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, "GlobalRoll X", Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
]]
end
local unbindRoll = function(name, axis)
return [[
-- Reset previous state
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.Normalized, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
openspace.navigation.bindJoystickAxis(]] .. name .. ", " .. axis .. [[, Joystick.State.Axis.Type, Joystick.State.Axis.Inverted, Joystick.State.Axis.JoystickType, Joystick.State.Axis.Sticky, Joystick.State.Axis.Sensitivity);
]]
end

View File

@@ -15,7 +15,8 @@ local joystickHelper = asset.require('./joystick_helper')
-- "Pan X"
-- "Pan Y"
-- Fourth parameter determines whether the axis should be inverted
-- Fifth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
-- Fifth parameter determines whether the axis behaves like a joystick or a Trigger.
-- Allowed values are "JoystickLike" and "TriggerLike", the first one is the default
-- Sixth parameters determins if the axis should be "Sticky" or not.
-- 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.
@@ -55,13 +56,15 @@ asset.onInitialize(function()
openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], 0.15)
openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], 0.15)
openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], 0.15)
openspace.navigation.setAxisDeadZone(name, controller.L2, 0.05)
openspace.navigation.setAxisDeadZone(name, controller.R2, 0.05)
openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[1], "Orbit X");
openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[2], "Orbit Y", true);
openspace.navigation.bindJoystickAxis(name, controller.RightThumbStick[1], "Pan X", true);
openspace.navigation.bindJoystickAxis(name, controller.RightThumbStick[2], "Pan Y", true);
openspace.navigation.bindJoystickAxis(name, controller.L2, "Zoom Out", false, true);
openspace.navigation.bindJoystickAxis(name, controller.R2, "Zoom In", false, true);
openspace.navigation.bindJoystickAxis(name, controller.L2, "Zoom Out", false, "TriggerLike");
openspace.navigation.bindJoystickAxis(name, controller.R2, "Zoom In", false, "TriggerLike");
openspace.navigation.bindJoystickButton(
name,

View File

@@ -15,7 +15,8 @@ local joystickHelper = asset.require('./joystick_helper')
-- "Pan X"
-- "Pan Y"
-- Fourth parameter determines whether the axis should be inverted
-- Fifth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
-- Fifth parameter determines whether the axis behaves like a joystick or a Trigger.
-- Allowed values are "JoystickLike" and "TriggerLike", the first one is the default
-- Sixth parameters determins if the axis should be "Sticky" or not.
-- 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.

View File

@@ -15,7 +15,8 @@ local joystickHelper = asset.require('./joystick_helper')
-- "Pan X"
-- "Pan Y"
-- Fourth parameter determines whether the axis should be inverted
-- Fifth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
-- Fifth parameter determines whether the axis behaves like a joystick or a Trigger.
-- Allowed values are "JoystickLike" and "TriggerLike", the first one is the default
-- Sixth parameters determins if the axis should be "Sticky" or not.
-- 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.
@@ -35,12 +36,12 @@ asset.onInitialize(function()
local controller = SpaceMouse;
local name = "SpaceNavigator";
openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X", false, false, true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y", false, false, true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Twist[1], "Pan X", true, false, true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Tilt[2], "Pan Y", false, false, true, 35.0);
openspace.navigation.bindJoystickAxis(name, controller.Push[3], "Zoom", false, false, true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Tilt[1], "LocalRoll X", false, false, true, 35.0);
openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X", false, "JoystickLike", true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y", false, "JoystickLike", true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Twist[1], "Pan X", true, "JoystickLike", true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Tilt[2], "Pan Y", false, "JoystickLike", true, 35.0);
openspace.navigation.bindJoystickAxis(name, controller.Push[3], "Zoom", false, "JoystickLike", true, 40.0);
openspace.navigation.bindJoystickAxis(name, controller.Tilt[1], "LocalRoll X", "JoystickLike", false, true, 35.0);
openspace.navigation.bindJoystickButton(
name,

View File

@@ -15,7 +15,8 @@ local joystickHelper = asset.require('./joystick_helper')
-- "Pan X"
-- "Pan Y"
-- Fourth parameter determines whether the axis should be inverted
-- Fifth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
-- Fifth parameter determines whether the axis behaves like a joystick or a Trigger.
-- Allowed values are "JoystickLike" and "TriggerLike", the first one is the default
-- Sixth parameters determins if the axis should be "Sticky" or not.
-- 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.
@@ -52,14 +53,16 @@ asset.onInitialize(function()
openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], 0.15)
openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], 0.15)
openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], 0.15)
openspace.navigation.setAxisDeadZone(controller.RightThumbStick[2], 0.15)
openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], 0.15)
openspace.navigation.setAxisDeadZone(name, controller.LeftTrigger, 0.05)
openspace.navigation.setAxisDeadZone(name, controller.RightTrigger, 0.05)
openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[1], "Orbit X");
openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[2], "Orbit Y", true);
openspace.navigation.bindJoystickAxis(name, controller.RightThumbStick[1], "Pan X", true);
openspace.navigation.bindJoystickAxis(name, controller.RightThumbStick[2], "Pan Y", true);
openspace.navigation.bindJoystickAxis(name, controller.LeftTrigger, "Zoom Out", false, true);
openspace.navigation.bindJoystickAxis(name, controller.RightTrigger, "Zoom In", false, true);
openspace.navigation.bindJoystickAxis(name, controller.LeftTrigger, "Zoom Out", false, "TriggerLike");
openspace.navigation.bindJoystickAxis(name, controller.RightTrigger, "Zoom In", false, "TriggerLike");
openspace.navigation.bindJoystickButton(
name,

View File

@@ -53,14 +53,18 @@ public:
Property
};
enum class JoystickType {
JoystickLike = 0,
TriggerLike
};
BooleanType(AxisInvert);
BooleanType(AxisNormalize);
BooleanType(ButtonCommandRemote);
struct AxisInformation {
AxisType type = AxisType::None;
AxisInvert invert = AxisInvert::No;
AxisNormalize normalize = AxisNormalize::No;
JoystickType joystickType = JoystickType::JoystickLike;
// 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.
@@ -86,7 +90,7 @@ public:
void setAxisMapping(const std::string& joystickName, int axis, AxisType mapping,
AxisInvert shouldInvert = AxisInvert::No,
AxisNormalize shouldNormalize = AxisNormalize::No,
JoystickType joystickType = JoystickType::JoystickLike,
bool isSticky = false, double sensitivity = 0.0
);
@@ -194,6 +198,30 @@ from_string(std::string_view string)
throw RuntimeError("Unkonwn axis type '" + std::string(string) + "'");
}
template <>
inline std::string to_string(
const openspace::interaction::JoystickCameraStates::JoystickType& value)
{
using T = openspace::interaction::JoystickCameraStates::JoystickType;
switch (value) {
case T::JoystickLike: return "JoystickLike";
case T::TriggerLike: return "TriggerLike";
default: return "";
}
}
template <>
constexpr openspace::interaction::JoystickCameraStates::JoystickType
from_string(std::string_view string)
{
using T = openspace::interaction::JoystickCameraStates::JoystickType;
if (string == "JoystickLike") { return T::JoystickLike; }
if (string == "TriggerLike") { return T::TriggerLike; }
throw RuntimeError("Unkonwn joystick type '" + std::string(string) + "'");
}
} // namespace ghoul
#endif // __OPENSPACE_CORE___JOYSTICKCAMERASTATES___H__

View File

@@ -102,8 +102,8 @@ public:
int axis, JoystickCameraStates::AxisType mapping,
JoystickCameraStates::AxisInvert shouldInvert =
JoystickCameraStates::AxisInvert::No,
JoystickCameraStates::AxisNormalize shouldNormalize =
JoystickCameraStates::AxisNormalize::No,
JoystickCameraStates::JoystickType joystickType =
JoystickCameraStates::JoystickType::JoystickLike,
bool isSticky = false, double sensitivity = 0.0
);

View File

@@ -77,7 +77,10 @@ void JoystickCameraStates::updateStateFromInput(
joystickCameraState->prevAxisValues[i] = rawValue;
}
if (std::fabs(value) <= t.deadzone) {
if ((t.joystickType == JoystickType::JoystickLike &&
std::fabs(value) <= t.deadzone) ||
(t.joystickType == JoystickType::TriggerLike && value <= -1 + t.deadzone))
{
continue;
}
@@ -85,7 +88,9 @@ void JoystickCameraStates::updateStateFromInput(
value *= -1.f;
}
if (t.normalize || t.type == AxisType::Property) {
if (t.joystickType == JoystickType::TriggerLike ||
t.type == AxisType::Property)
{
value = (value + 1.f) / 2.f;
}
@@ -214,7 +219,7 @@ void JoystickCameraStates::updateStateFromInput(
void JoystickCameraStates::setAxisMapping(const std::string& joystickName,
int axis, AxisType mapping,
AxisInvert shouldInvert,
AxisNormalize shouldNormalize,
JoystickType joystickType,
bool isSticky,
double sensitivity)
{
@@ -227,7 +232,7 @@ void JoystickCameraStates::setAxisMapping(const std::string& joystickName,
joystickCameraState->axisMapping[axis].type = mapping;
joystickCameraState->axisMapping[axis].invert = shouldInvert;
joystickCameraState->axisMapping[axis].normalize = shouldNormalize;
joystickCameraState->axisMapping[axis].joystickType = joystickType;
joystickCameraState->axisMapping[axis].isSticky = isSticky;
joystickCameraState->axisMapping[axis].sensitivity = sensitivity;

View File

@@ -501,7 +501,7 @@ void NavigationHandler::loadNavigationState(const std::string& filepath) {
void NavigationHandler::setJoystickAxisMapping(const std::string& joystickName, int axis,
JoystickCameraStates::AxisType mapping,
JoystickCameraStates::AxisInvert shouldInvert,
JoystickCameraStates::AxisNormalize shouldNormalize,
JoystickCameraStates::JoystickType joystickType,
bool isSticky,
double sensitivity)
{
@@ -510,7 +510,7 @@ void NavigationHandler::setJoystickAxisMapping(const std::string& joystickName,
axis,
mapping,
shouldInvert,
shouldNormalize,
joystickType,
isSticky,
sensitivity
);
@@ -652,15 +652,15 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() {
{
"bindJoystickAxis",
&luascriptfunctions::bindJoystickAxis,
"name, axis, axisType [, isInverted, isNormalized, isSticky, sensitivity]",
"name, axis, axisType [, isInverted, joystickType, isSticky, sensitivity]",
"Finds the input joystick with the given 'name' and binds the axis "
"identified by the second argument to be used as the type identified by "
"the third argument. If 'isInverted' is 'true', the axis value is "
"inverted, if 'isNormalized' is true the axis value is normalized from "
"[-1, 1] to [0,1]. If 'isSticky' is 'true', the value is calculated "
"relative to the previous value. If 'sensitivity' is given then that "
"value will affect the sensitivity of the axis together with "
"the global sensitivity."
"inverted. 'joystickType' is if the joystick behaves more like a "
"joystick or a trigger, where the first is the default. If 'isSticky' is "
"'true', the value is calculated relative to the previous value. If "
"'sensitivity' is given then that value will affect the sensitivity of "
"the axis together with the global sensitivity."
},
{
"bindJoystickAxisProperty",
@@ -686,11 +686,11 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() {
"Finds the input joystick with the given 'name' and returns the joystick "
"axis information for the passed axis. The information that is returned "
"is the current axis binding as a string, whether the values are "
"inverted as bool, whether the value are normalized as a bool, whether "
"the axis is sticky as bool, the sensitivity as number, the property uri "
"bound to the axis as string (empty is type is not Property), the min "
"and max values for the property as numbers and whether the property "
"change will be executed remotly as bool."
"inverted as bool, the joystick type as a string, whether the axis is "
"sticky as bool, the sensitivity as number, the property uri bound to "
"the axis as string (empty is type is not Property), the min and max "
"values for the property as numbers and whether the property change will "
"be executed remotly as bool."
},
{
"setAxisDeadZone",

View File

@@ -152,23 +152,22 @@ int retargetAim(lua_State* L) {
int bindJoystickAxis(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, { 3, 7 }, "lua::bindJoystickAxis");
auto [joystickName, axis, axisType, shouldInvert, shouldNormalize, isSticky,
auto [joystickName, axis, axisType, shouldInvert, joystickType, isSticky,
sensitivity] =
ghoul::lua::values<
std::string, int, std::string, std::optional<bool>, std::optional<bool>,
std::optional<bool>, std::optional<double>
std::string, int, std::string, std::optional<bool>,
std::optional<std::string>, std::optional<bool>, std::optional<double>
>(L);
shouldInvert = shouldInvert.value_or(false);
shouldNormalize = shouldNormalize.value_or(false);
isSticky = isSticky.value_or(false);
sensitivity = sensitivity.value_or(0.0);
joystickType = joystickType.value_or("JoystickLike");
global::navigationHandler->setJoystickAxisMapping(
joystickName,
axis,
ghoul::from_string<interaction::JoystickCameraStates::AxisType>(axisType),
interaction::JoystickCameraStates::AxisInvert(*shouldInvert),
interaction::JoystickCameraStates::AxisNormalize(*shouldNormalize),
ghoul::from_string<interaction::JoystickCameraStates::JoystickType>(*joystickType),
*isSticky,
*sensitivity
);
@@ -216,7 +215,7 @@ int joystickAxis(lua_State* L) {
L,
ghoul::to_string(info.type),
static_cast<bool>(info.invert),
static_cast<bool>(info.normalize),
ghoul::to_string(info.joystickType),
info.isSticky,
info.sensitivity,
info.propertyUri,