mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 04:30:09 -05:00
Merge pull request #1641 from OpenSpace/feature/joysticks
Separate different joystick configurations
This commit is contained in:
@@ -10,7 +10,6 @@ asset.require('spice/base')
|
||||
-- Load default key bindings applicable to most scenes
|
||||
asset.require('dashboard/default_dashboard')
|
||||
asset.require('util/default_keybindings')
|
||||
asset.require('util/default_joystick')
|
||||
|
||||
-- Load web gui
|
||||
local webGui = asset.require('util/webgui')
|
||||
|
||||
@@ -8,7 +8,6 @@ asset.require('spice/base')
|
||||
|
||||
asset.require('util/default_keybindings')
|
||||
asset.require('util/default_dashboard')
|
||||
asset.require('util/default_joystick')
|
||||
|
||||
asset.require('util/webgui')
|
||||
local spheres = asset.require('examples/spheres')
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
local propertyHelper = asset.require('./property_helper')
|
||||
|
||||
-- Allowed values for the second parameter of bindJoystickAxis:
|
||||
-- "None"
|
||||
-- "Orbit X"
|
||||
-- "Orbit Y"
|
||||
-- "Zoom" -- both in and out
|
||||
-- "Zoom In"
|
||||
-- "Zoom Out"
|
||||
-- "LocalRoll X"
|
||||
-- "LocalRoll Y"
|
||||
-- "GlobalRoll X"
|
||||
-- "GlobalRoll Y"
|
||||
-- "Pan X"
|
||||
-- "Pan Y"
|
||||
-- Third parameter determines whether the axis should be inverted
|
||||
-- Fourth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
|
||||
|
||||
|
||||
local XBoxController = {
|
||||
LeftThumbStick = { 0 , 1 },
|
||||
RightThumbStick = { 2, 3 },
|
||||
LeftTrigger = 4,
|
||||
RightTrigger = 5,
|
||||
A = 0,
|
||||
B = 1,
|
||||
X = 2,
|
||||
Y = 3,
|
||||
LB = 4,
|
||||
RB = 5,
|
||||
Select = 6,
|
||||
Start = 7,
|
||||
LeftStick = 8,
|
||||
RightStick = 9,
|
||||
DPad = {
|
||||
Up = 10,
|
||||
Right = 11,
|
||||
Down = 12,
|
||||
Left = 13
|
||||
}
|
||||
}
|
||||
|
||||
local PS4Controller = {
|
||||
LeftThumbStick = { 0 , 1 },
|
||||
RightThumbStick = { 2, 5 },
|
||||
LeftTrigger = 3,
|
||||
RightTrigger = 4,
|
||||
A = 1, -- Cross
|
||||
B = 2, -- Circle
|
||||
X = 0, -- Square
|
||||
Y = 3, -- Triangle
|
||||
LB = 4,
|
||||
RB = 5,
|
||||
Select = 9, -- options
|
||||
Start = 12, -- PS button
|
||||
LeftStick = 10,
|
||||
RightStick = 11,
|
||||
DPad = {
|
||||
Up = 14,
|
||||
Right = 15,
|
||||
Down = 16,
|
||||
Left = 17
|
||||
}
|
||||
}
|
||||
|
||||
local SpaceMouse = {
|
||||
Push = {0, 1, 2}, -- left/right, back/forth, up/down
|
||||
Twist = {5}, -- left/right
|
||||
Tilt = {4, 3}, -- left/right, back/forth
|
||||
LeftButton = 0,
|
||||
RightButton = 1
|
||||
}
|
||||
|
||||
-- Variables to store the state of the joystick between frames
|
||||
Joystick = {}
|
||||
Joystick.State = {}
|
||||
Joystick.State.IsInRollMode = false
|
||||
Joystick.State.Axis = {}
|
||||
|
||||
local bindLocalRoll = function(axis)
|
||||
return [[
|
||||
-- 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 .. [[)
|
||||
end
|
||||
|
||||
-- Set new axis state
|
||||
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
|
||||
|
||||
local bindGlobalRoll = function(axis)
|
||||
return [[
|
||||
-- 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 .. [[)
|
||||
end
|
||||
|
||||
-- Set new axis state
|
||||
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
|
||||
|
||||
local permaBindLocalRoll = function(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 .. [[)
|
||||
|
||||
-- Set new axis state
|
||||
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.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.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.Sticky, Joystick.State.Axis.Sensitivity);
|
||||
]]
|
||||
end
|
||||
|
||||
asset.onInitialize(function()
|
||||
-- Set the controller to the connected controller
|
||||
-- Currently: XBoxController, PS4Controller or SpaceMouse
|
||||
local controller = XBoxController;
|
||||
|
||||
-- Case of XBoxController or PS4Controller
|
||||
if(controller.A ~= nil) then
|
||||
openspace.navigation.setAxisDeadZone(controller.LeftThumbStick[1], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.LeftThumbStick[2], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.RightThumbStick[1], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.RightThumbStick[2], 0.15)
|
||||
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftThumbStick[1], "Orbit X");
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftThumbStick[2], "Orbit Y", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightThumbStick[1], "Pan X", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightThumbStick[2], "Pan Y", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftTrigger, "Zoom Out", false, true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightTrigger, "Zoom In", false, true);
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.LB,
|
||||
bindLocalRoll(controller.RightThumbStick[1]),
|
||||
"Switch to local roll mode"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.LB,
|
||||
unbindRoll(controller.RightThumbStick[1]),
|
||||
"Switch back to normal mode",
|
||||
"Release"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.RB,
|
||||
bindGlobalRoll(controller.RightThumbStick[1]),
|
||||
"Switch to global roll mode"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.RB,
|
||||
unbindRoll(controller.RightThumbStick[1]),
|
||||
"Switch back to normal mode",
|
||||
"Release"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.A,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.ZoomFriction'),
|
||||
"Toggle zoom friction"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.B,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.RotationalFriction'),
|
||||
"Toggle rotational friction"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.DPad.Left,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.RollFriction'),
|
||||
"Toggle roll friction"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.X,
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Aim', '');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Anchor', 'Earth');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil);",
|
||||
"Switch target to Earth"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.Y,
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Aim', '');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Anchor', 'Mars');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil);",
|
||||
"Switch target to Mars"
|
||||
)
|
||||
-- Case of SpaceMouse
|
||||
elseif (controller.LeftButton ~= nil) then
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[1], "Orbit X", false, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[2], "Orbit Y", false, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Twist[1], "Pan X", true, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Tilt[2], "Pan Y", false, false, true, 35.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[3], "Zoom", false, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Tilt[1], "LocalRoll X", false, false, true, 35.0);
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.LeftButton,
|
||||
permaBindLocalRoll(controller.Tilt[1]),
|
||||
"Switch to local roll mode"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.RightButton,
|
||||
permaBindGlobalRoll(controller.Tilt[1]),
|
||||
"Switch to global roll mode"
|
||||
)
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,66 @@
|
||||
-- Variables to store the state of the joystick between frames
|
||||
Joystick = {}
|
||||
Joystick.State = {}
|
||||
Joystick.State.IsInRollMode = false
|
||||
Joystick.State.Axis = {}
|
||||
|
||||
local bindLocalRoll = function(axis)
|
||||
return [[
|
||||
-- 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 .. [[)
|
||||
end
|
||||
|
||||
-- Set new axis state
|
||||
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
|
||||
|
||||
local bindGlobalRoll = function(axis)
|
||||
return [[
|
||||
-- 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 .. [[)
|
||||
end
|
||||
|
||||
-- Set new axis state
|
||||
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
|
||||
|
||||
local permaBindLocalRoll = function(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 .. [[)
|
||||
|
||||
-- Set new axis state
|
||||
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.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.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.Sticky, Joystick.State.Axis.Sensitivity);
|
||||
]]
|
||||
end
|
||||
|
||||
asset.export("bindLocalRoll", bindLocalRoll)
|
||||
asset.export("bindGlobalRoll", bindGlobalRoll)
|
||||
asset.export("permaBindLocalRoll", permaBindLocalRoll)
|
||||
asset.export("permaBindGlobalRoll", permaBindGlobalRoll)
|
||||
asset.export("unbindRoll", unbindRoll)
|
||||
@@ -0,0 +1,118 @@
|
||||
local propertyHelper = asset.require('../property_helper')
|
||||
local joystickHelper = asset.require('./joystick_helper')
|
||||
|
||||
-- Allowed values for the second parameter of bindJoystickAxis:
|
||||
-- "None"
|
||||
-- "Orbit X"
|
||||
-- "Orbit Y"
|
||||
-- "Zoom" -- both in and out
|
||||
-- "Zoom In"
|
||||
-- "Zoom Out"
|
||||
-- "LocalRoll X"
|
||||
-- "LocalRoll Y"
|
||||
-- "GlobalRoll X"
|
||||
-- "GlobalRoll Y"
|
||||
-- "Pan X"
|
||||
-- "Pan Y"
|
||||
-- Third parameter determines whether the axis should be inverted
|
||||
-- Fourth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
|
||||
-- Fifth 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.
|
||||
-- The latter is called a sticky axis, when the values don't go back to 0.
|
||||
-- Sixth parameter is the sensitivity for the axis
|
||||
|
||||
local PS4Controller = {
|
||||
LeftThumbStick = { 0 , 1 },
|
||||
RightThumbStick = { 2, 5 },
|
||||
L2 = 3,
|
||||
R2 = 4,
|
||||
Cross = 1,
|
||||
Circle = 2,
|
||||
Square = 0,
|
||||
Triangle = 3,
|
||||
L1 = 4,
|
||||
R1 = 5,
|
||||
Share = 8,
|
||||
Options = 9,
|
||||
PS = 12,
|
||||
LeftStickButton = 10,
|
||||
RightStickButton = 11,
|
||||
TouchPad = 13,
|
||||
DPad = {
|
||||
Up = 14,
|
||||
Right = 15,
|
||||
Down = 16,
|
||||
Left = 17
|
||||
}
|
||||
}
|
||||
|
||||
asset.onInitialize(function()
|
||||
local controller = PS4Controller;
|
||||
|
||||
openspace.navigation.setAxisDeadZone(controller.LeftThumbStick[1], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.LeftThumbStick[2], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.RightThumbStick[1], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.RightThumbStick[2], 0.15)
|
||||
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftThumbStick[1], "Orbit X");
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftThumbStick[2], "Orbit Y", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightThumbStick[1], "Pan X", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightThumbStick[2], "Pan Y", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.L2, "Zoom Out", false, true);
|
||||
openspace.navigation.bindJoystickAxis(controller.R2, "Zoom In", false, true);
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.L1,
|
||||
joystickHelper.bindLocalRoll(controller.RightThumbStick[1]),
|
||||
"Switch to local roll mode"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.L1,
|
||||
joystickHelper.unbindRoll(controller.RightThumbStick[1]),
|
||||
"Switch back to normal mode",
|
||||
"Release"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.R1,
|
||||
joystickHelper.bindGlobalRoll(controller.RightThumbStick[1]),
|
||||
"Switch to global roll mode"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.R1,
|
||||
joystickHelper.unbindRoll(controller.RightThumbStick[1]),
|
||||
"Switch back to normal mode",
|
||||
"Release"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.Cross,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.ZoomFriction'),
|
||||
"Toggle zoom friction"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.Circle,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.RotationalFriction'),
|
||||
"Toggle rotational friction"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.DPad.Left,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.RollFriction'),
|
||||
"Toggle roll friction"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.Square,
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Aim', '');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Anchor', 'Earth');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil);",
|
||||
"Switch target to Earth"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.Triangle,
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Aim', '');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Anchor', 'Mars');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil);",
|
||||
"Switch target to Mars"
|
||||
)
|
||||
end)
|
||||
@@ -0,0 +1,55 @@
|
||||
local propertyHelper = asset.require('../property_helper')
|
||||
local joystickHelper = asset.require('./joystick_helper')
|
||||
|
||||
-- Allowed values for the second parameter of bindJoystickAxis:
|
||||
-- "None"
|
||||
-- "Orbit X"
|
||||
-- "Orbit Y"
|
||||
-- "Zoom" -- both in and out
|
||||
-- "Zoom In"
|
||||
-- "Zoom Out"
|
||||
-- "LocalRoll X"
|
||||
-- "LocalRoll Y"
|
||||
-- "GlobalRoll X"
|
||||
-- "GlobalRoll Y"
|
||||
-- "Pan X"
|
||||
-- "Pan Y"
|
||||
-- Third parameter determines whether the axis should be inverted
|
||||
-- Fourth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
|
||||
-- Fifth 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.
|
||||
-- The latter is called a sticky axis, when the values don't go back to 0.
|
||||
-- This version of the SpaceMouse is NOT Sticky.
|
||||
-- Sixth parameter is the sensitivity for the axis
|
||||
|
||||
local SpaceMouse = {
|
||||
Push = {0, 1, 2}, -- left/right, back/forth, up/down
|
||||
Twist = {5}, -- left/right
|
||||
Tilt = {4, 3}, -- left/right, back/forth
|
||||
LeftButton = 0,
|
||||
RightButton = 1
|
||||
}
|
||||
|
||||
asset.onInitialize(function()
|
||||
local controller = SpaceMouse;
|
||||
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[1], "Orbit X", false);
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[2], "Orbit Y", false);
|
||||
openspace.navigation.bindJoystickAxis(controller.Twist[1], "Pan X", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.Tilt[2], "Pan Y", false);
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[3], "Zoom", false);
|
||||
openspace.navigation.bindJoystickAxis(controller.Tilt[1], "LocalRoll X", false);
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.LeftButton,
|
||||
joystickHelper.permaBindLocalRoll(controller.Tilt[1]),
|
||||
"Switch to local roll mode"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.RightButton,
|
||||
joystickHelper.permaBindGlobalRoll(controller.Tilt[1]),
|
||||
"Switch to global roll mode"
|
||||
)
|
||||
end)
|
||||
@@ -0,0 +1,55 @@
|
||||
local propertyHelper = asset.require('../property_helper')
|
||||
local joystickHelper = asset.require('./joystick_helper')
|
||||
|
||||
-- Allowed values for the second parameter of bindJoystickAxis:
|
||||
-- "None"
|
||||
-- "Orbit X"
|
||||
-- "Orbit Y"
|
||||
-- "Zoom" -- both in and out
|
||||
-- "Zoom In"
|
||||
-- "Zoom Out"
|
||||
-- "LocalRoll X"
|
||||
-- "LocalRoll Y"
|
||||
-- "GlobalRoll X"
|
||||
-- "GlobalRoll Y"
|
||||
-- "Pan X"
|
||||
-- "Pan Y"
|
||||
-- Third parameter determines whether the axis should be inverted
|
||||
-- Fourth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
|
||||
-- Fifth 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.
|
||||
-- The latter is called a sticky axis, when the values don't go back to 0.
|
||||
-- This version of the SpaceMouse IS Sticky.
|
||||
-- Sixth parameter is the sensitivity for the axis
|
||||
|
||||
local SpaceMouse = {
|
||||
Push = {0, 1, 2}, -- left/right, back/forth, up/down
|
||||
Twist = {5}, -- left/right
|
||||
Tilt = {4, 3}, -- left/right, back/forth
|
||||
LeftButton = 0,
|
||||
RightButton = 1
|
||||
}
|
||||
|
||||
asset.onInitialize(function()
|
||||
local controller = SpaceMouse;
|
||||
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[1], "Orbit X", false, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[2], "Orbit Y", false, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Twist[1], "Pan X", true, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Tilt[2], "Pan Y", false, false, true, 35.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Push[3], "Zoom", false, false, true, 40.0);
|
||||
openspace.navigation.bindJoystickAxis(controller.Tilt[1], "LocalRoll X", false, false, true, 35.0);
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.LeftButton,
|
||||
joystickHelper.permaBindLocalRoll(controller.Tilt[1]),
|
||||
"Switch to local roll mode"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.RightButton,
|
||||
joystickHelper.permaBindGlobalRoll(controller.Tilt[1]),
|
||||
"Switch to global roll mode"
|
||||
)
|
||||
end)
|
||||
@@ -0,0 +1,116 @@
|
||||
local propertyHelper = asset.require('../property_helper')
|
||||
local joystickHelper = asset.require('./joystick_helper')
|
||||
|
||||
-- Allowed values for the second parameter of bindJoystickAxis:
|
||||
-- "None"
|
||||
-- "Orbit X"
|
||||
-- "Orbit Y"
|
||||
-- "Zoom" -- both in and out
|
||||
-- "Zoom In"
|
||||
-- "Zoom Out"
|
||||
-- "LocalRoll X"
|
||||
-- "LocalRoll Y"
|
||||
-- "GlobalRoll X"
|
||||
-- "GlobalRoll Y"
|
||||
-- "Pan X"
|
||||
-- "Pan Y"
|
||||
-- Third parameter determines whether the axis should be inverted
|
||||
-- Fourth parameter determines whether the axis should be normalized from [-1,1] to [0,1]
|
||||
-- Fifth 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.
|
||||
-- The latter is called a sticky axis, when the values don't go back to 0.
|
||||
-- Sixth parameter is the sensitivity for the axis
|
||||
|
||||
local XBoxController = {
|
||||
LeftThumbStick = { 0 , 1 },
|
||||
RightThumbStick = { 2, 3 },
|
||||
LeftTrigger = 4,
|
||||
RightTrigger = 5,
|
||||
A = 0,
|
||||
B = 1,
|
||||
X = 2,
|
||||
Y = 3,
|
||||
LB = 4,
|
||||
RB = 5,
|
||||
Select = 6,
|
||||
Start = 7,
|
||||
LeftStickButton = 8,
|
||||
RightStickButton = 9,
|
||||
DPad = {
|
||||
Up = 10,
|
||||
Right = 11,
|
||||
Down = 12,
|
||||
Left = 13
|
||||
}
|
||||
}
|
||||
|
||||
asset.onInitialize(function()
|
||||
local controller = XBoxController;
|
||||
|
||||
openspace.navigation.setAxisDeadZone(controller.LeftThumbStick[1], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.LeftThumbStick[2], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.RightThumbStick[1], 0.15)
|
||||
openspace.navigation.setAxisDeadZone(controller.RightThumbStick[2], 0.15)
|
||||
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftThumbStick[1], "Orbit X");
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftThumbStick[2], "Orbit Y", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightThumbStick[1], "Pan X", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightThumbStick[2], "Pan Y", true);
|
||||
openspace.navigation.bindJoystickAxis(controller.LeftTrigger, "Zoom Out", false, true);
|
||||
openspace.navigation.bindJoystickAxis(controller.RightTrigger, "Zoom In", false, true);
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.LB,
|
||||
joystickHelper.bindLocalRoll(controller.RightThumbStick[1]),
|
||||
"Switch to local roll mode"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.LB,
|
||||
joystickHelper.unbindRoll(controller.RightThumbStick[1]),
|
||||
"Switch back to normal mode",
|
||||
"Release"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.RB,
|
||||
joystickHelper.bindGlobalRoll(controller.RightThumbStick[1]),
|
||||
"Switch to global roll mode"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.RB,
|
||||
joystickHelper.unbindRoll(controller.RightThumbStick[1]),
|
||||
"Switch back to normal mode",
|
||||
"Release"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.A,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.ZoomFriction'),
|
||||
"Toggle zoom friction"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.B,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.RotationalFriction'),
|
||||
"Toggle rotational friction"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.DPad.Left,
|
||||
propertyHelper.invert('NavigationHandler.OrbitalNavigator.Friction.RollFriction'),
|
||||
"Toggle roll friction"
|
||||
)
|
||||
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.X,
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Aim', '');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Anchor', 'Earth');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil);",
|
||||
"Switch target to Earth"
|
||||
)
|
||||
openspace.navigation.bindJoystickButton(
|
||||
controller.Y,
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Aim', '');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Anchor', 'Mars');" ..
|
||||
"openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil);",
|
||||
"Switch target to Mars"
|
||||
)
|
||||
end)
|
||||
Reference in New Issue
Block a user