mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 05:03:41 +02:00
Fixing line endings
This commit is contained in:
parent
edd2ce27f8
commit
22602fb6f6
4 changed files with 1006 additions and 1006 deletions
|
@ -1,218 +1,218 @@
|
|||
import QtQuick 2.3
|
||||
import QtQuick.Controls 1.2
|
||||
import QtQuick.Layouts 1.0
|
||||
import QtQuick.Dialogs 1.0
|
||||
|
||||
import "controller"
|
||||
import "controls" as HifiControls
|
||||
import "styles"
|
||||
|
||||
HifiControls.VrDialog {
|
||||
id: root
|
||||
HifiConstants { id: hifi }
|
||||
title: "Controller Test"
|
||||
resizable: true
|
||||
contentImplicitWidth: clientArea.implicitWidth
|
||||
contentImplicitHeight: clientArea.implicitHeight
|
||||
backgroundColor: "beige"
|
||||
|
||||
property var actions: Controller.Actions
|
||||
property var standard: Controller.Standard
|
||||
property var hydra: null
|
||||
property var testMapping: null
|
||||
property var xbox: null
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
enabled = true
|
||||
var xboxRegex = /^X360Controller/;
|
||||
var hydraRegex = /^Hydra/;
|
||||
for (var prop in Controller.Hardware) {
|
||||
if(xboxRegex.test(prop)) {
|
||||
root.xbox = Controller.Hardware[prop]
|
||||
print("found xbox")
|
||||
continue
|
||||
}
|
||||
if (hydraRegex.test(prop)) {
|
||||
root.hydra = Controller.Hardware[prop]
|
||||
print("found hydra")
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: clientArea
|
||||
spacing: 12
|
||||
x: root.clientX
|
||||
y: root.clientY
|
||||
|
||||
Row {
|
||||
spacing: 8
|
||||
Button {
|
||||
text: "Standard Mapping"
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping("Default");
|
||||
mapping.from(standard.LX).to(actions.TranslateX);
|
||||
mapping.from(standard.LY).to(actions.TranslateZ);
|
||||
mapping.from(standard.RY).to(actions.Pitch);
|
||||
mapping.from(standard.RX).to(actions.Yaw);
|
||||
mapping.from(standard.DU).scale(0.5).to(actions.LONGITUDINAL_FORWARD);
|
||||
mapping.from(standard.DD).scale(0.5).to(actions.LONGITUDINAL_BACKWARD);
|
||||
mapping.from(standard.DL).scale(0.5).to(actions.LATERAL_LEFT);
|
||||
mapping.from(standard.DR).scale(0.5).to(actions.LATERAL_RIGHT);
|
||||
mapping.from(standard.X).to(actions.VERTICAL_DOWN);
|
||||
mapping.from(standard.Y).to(actions.VERTICAL_UP);
|
||||
mapping.from(standard.RT).scale(0.1).to(actions.BOOM_IN);
|
||||
mapping.from(standard.LT).scale(0.1).to(actions.BOOM_OUT);
|
||||
mapping.from(standard.B).to(actions.ACTION1);
|
||||
mapping.from(standard.A).to(actions.ACTION2);
|
||||
mapping.from(standard.RB).to(actions.SHIFT);
|
||||
mapping.from(standard.Back).to(actions.TOGGLE_MUTE);
|
||||
mapping.from(standard.Start).to(actions.CONTEXT_MENU);
|
||||
Controller.enableMapping("Default");
|
||||
enabled = false;
|
||||
text = "Standard Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: root.xbox ? "XBox Mapping" : "XBox not found"
|
||||
property bool built: false
|
||||
enabled: root.xbox && !built
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping();
|
||||
mapping.from(xbox.A).to(standard.A);
|
||||
mapping.from(xbox.B).to(standard.B);
|
||||
mapping.from(xbox.X).to(standard.X);
|
||||
mapping.from(xbox.Y).to(standard.Y);
|
||||
mapping.from(xbox.Up).to(standard.DU);
|
||||
mapping.from(xbox.Down).to(standard.DD);
|
||||
mapping.from(xbox.Left).to(standard.DL);
|
||||
mapping.from(xbox.Right).to(standard.Right);
|
||||
mapping.from(xbox.LB).to(standard.LB);
|
||||
mapping.from(xbox.RB).to(standard.RB);
|
||||
mapping.from(xbox.LS).to(standard.LS);
|
||||
mapping.from(xbox.RS).to(standard.RS);
|
||||
mapping.from(xbox.Start).to(standard.Start);
|
||||
mapping.from(xbox.Back).to(standard.Back);
|
||||
mapping.from(xbox.LY).to(standard.LY);
|
||||
mapping.from(xbox.LX).to(standard.LX);
|
||||
mapping.from(xbox.RY).to(standard.RY);
|
||||
mapping.from(xbox.RX).to(standard.RX);
|
||||
mapping.from(xbox.LT).to(standard.LT);
|
||||
mapping.from(xbox.RT).to(standard.RT);
|
||||
mapping.enable();
|
||||
built = false;
|
||||
text = "XBox Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: root.hydra ? "Hydra Mapping" : "Hydra Not Found"
|
||||
property bool built: false
|
||||
enabled: root.hydra && !built
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping();
|
||||
mapping.from(hydra.LY).invert().to(standard.LY);
|
||||
mapping.from(hydra.LX).to(standard.LX);
|
||||
mapping.from(hydra.RY).invert().to(standard.RY);
|
||||
mapping.from(hydra.RX).to(standard.RX);
|
||||
mapping.from(hydra.LT).to(standard.LT);
|
||||
mapping.from(hydra.RT).to(standard.RT);
|
||||
mapping.enable();
|
||||
built = false;
|
||||
text = "Hydra Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Test Mapping"
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping();
|
||||
// Inverting a value
|
||||
mapping.from(hydra.RY).invert().to(standard.RY);
|
||||
mapping.from(hydra.RX).to(standard.RX);
|
||||
mapping.from(hydra.LY).to(standard.LY);
|
||||
mapping.from(hydra.LX).to(standard.LX);
|
||||
// Assigning a value from a function
|
||||
// mapping.from(function() { return Math.sin(Date.now() / 250); }).to(standard.RX);
|
||||
// Constrainting a value to -1, 0, or 1, with a deadzone
|
||||
// mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY);
|
||||
mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
|
||||
// mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT);
|
||||
// mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT);
|
||||
// mapping.modifier(keyboard.Ctrl).scale(2.0)
|
||||
// mapping.from(keyboard.A).to(actions.TranslateLeft)
|
||||
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
|
||||
// mapping.from(keyboard.A, keyboard.Shift, keyboard.Ctrl).scale(2.0).to(actions.TurnLeft)
|
||||
// // First loopbacks
|
||||
// // Then non-loopbacks by constraint level (number of inputs)
|
||||
// mapping.from(xbox.RX).deadZone(0.2).to(xbox.RX)
|
||||
// mapping.from(standard.RB, standard.LB, keyboard.Shift).to(actions.TurnLeft)
|
||||
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
|
||||
// mapping.from(keyboard.W).when(keyboard.Shift).to(actions.Forward)
|
||||
testMapping = mapping;
|
||||
enabled = false
|
||||
text = "Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Enable Mapping"
|
||||
onClicked: root.testMapping.enable()
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Disable Mapping"
|
||||
onClicked: root.testMapping.disable()
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Enable Mapping"
|
||||
onClicked: print(Controller.getValue(root.xbox.LY));
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
Xbox { device: root.standard; label: "Standard"; width: 360 }
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 8
|
||||
Xbox { device: root.xbox; label: "XBox"; width: 360 }
|
||||
Hydra { device: root.hydra; width: 360 }
|
||||
}
|
||||
// Row {
|
||||
// spacing: 8
|
||||
// ScrollingGraph {
|
||||
// controlId: Controller.Actions.Yaw
|
||||
// label: "Yaw"
|
||||
// min: -3.0
|
||||
// max: 3.0
|
||||
// size: 128
|
||||
// }
|
||||
//
|
||||
// ScrollingGraph {
|
||||
// controlId: Controller.Actions.YAW_LEFT
|
||||
// label: "Yaw Left"
|
||||
// min: -3.0
|
||||
// max: 3.0
|
||||
// size: 128
|
||||
// }
|
||||
//
|
||||
// ScrollingGraph {
|
||||
// controlId: Controller.Actions.YAW_RIGHT
|
||||
// label: "Yaw Right"
|
||||
// min: -3.0
|
||||
// max: 3.0
|
||||
// size: 128
|
||||
// }
|
||||
// }
|
||||
}
|
||||
} // dialog
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import QtQuick 2.3
|
||||
import QtQuick.Controls 1.2
|
||||
import QtQuick.Layouts 1.0
|
||||
import QtQuick.Dialogs 1.0
|
||||
|
||||
import "controller"
|
||||
import "controls" as HifiControls
|
||||
import "styles"
|
||||
|
||||
HifiControls.VrDialog {
|
||||
id: root
|
||||
HifiConstants { id: hifi }
|
||||
title: "Controller Test"
|
||||
resizable: true
|
||||
contentImplicitWidth: clientArea.implicitWidth
|
||||
contentImplicitHeight: clientArea.implicitHeight
|
||||
backgroundColor: "beige"
|
||||
|
||||
property var actions: Controller.Actions
|
||||
property var standard: Controller.Standard
|
||||
property var hydra: null
|
||||
property var testMapping: null
|
||||
property var xbox: null
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
enabled = true
|
||||
var xboxRegex = /^X360Controller/;
|
||||
var hydraRegex = /^Hydra/;
|
||||
for (var prop in Controller.Hardware) {
|
||||
if(xboxRegex.test(prop)) {
|
||||
root.xbox = Controller.Hardware[prop]
|
||||
print("found xbox")
|
||||
continue
|
||||
}
|
||||
if (hydraRegex.test(prop)) {
|
||||
root.hydra = Controller.Hardware[prop]
|
||||
print("found hydra")
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: clientArea
|
||||
spacing: 12
|
||||
x: root.clientX
|
||||
y: root.clientY
|
||||
|
||||
Row {
|
||||
spacing: 8
|
||||
Button {
|
||||
text: "Standard Mapping"
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping("Default");
|
||||
mapping.from(standard.LX).to(actions.TranslateX);
|
||||
mapping.from(standard.LY).to(actions.TranslateZ);
|
||||
mapping.from(standard.RY).to(actions.Pitch);
|
||||
mapping.from(standard.RX).to(actions.Yaw);
|
||||
mapping.from(standard.DU).scale(0.5).to(actions.LONGITUDINAL_FORWARD);
|
||||
mapping.from(standard.DD).scale(0.5).to(actions.LONGITUDINAL_BACKWARD);
|
||||
mapping.from(standard.DL).scale(0.5).to(actions.LATERAL_LEFT);
|
||||
mapping.from(standard.DR).scale(0.5).to(actions.LATERAL_RIGHT);
|
||||
mapping.from(standard.X).to(actions.VERTICAL_DOWN);
|
||||
mapping.from(standard.Y).to(actions.VERTICAL_UP);
|
||||
mapping.from(standard.RT).scale(0.1).to(actions.BOOM_IN);
|
||||
mapping.from(standard.LT).scale(0.1).to(actions.BOOM_OUT);
|
||||
mapping.from(standard.B).to(actions.ACTION1);
|
||||
mapping.from(standard.A).to(actions.ACTION2);
|
||||
mapping.from(standard.RB).to(actions.SHIFT);
|
||||
mapping.from(standard.Back).to(actions.TOGGLE_MUTE);
|
||||
mapping.from(standard.Start).to(actions.CONTEXT_MENU);
|
||||
Controller.enableMapping("Default");
|
||||
enabled = false;
|
||||
text = "Standard Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: root.xbox ? "XBox Mapping" : "XBox not found"
|
||||
property bool built: false
|
||||
enabled: root.xbox && !built
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping();
|
||||
mapping.from(xbox.A).to(standard.A);
|
||||
mapping.from(xbox.B).to(standard.B);
|
||||
mapping.from(xbox.X).to(standard.X);
|
||||
mapping.from(xbox.Y).to(standard.Y);
|
||||
mapping.from(xbox.Up).to(standard.DU);
|
||||
mapping.from(xbox.Down).to(standard.DD);
|
||||
mapping.from(xbox.Left).to(standard.DL);
|
||||
mapping.from(xbox.Right).to(standard.Right);
|
||||
mapping.from(xbox.LB).to(standard.LB);
|
||||
mapping.from(xbox.RB).to(standard.RB);
|
||||
mapping.from(xbox.LS).to(standard.LS);
|
||||
mapping.from(xbox.RS).to(standard.RS);
|
||||
mapping.from(xbox.Start).to(standard.Start);
|
||||
mapping.from(xbox.Back).to(standard.Back);
|
||||
mapping.from(xbox.LY).to(standard.LY);
|
||||
mapping.from(xbox.LX).to(standard.LX);
|
||||
mapping.from(xbox.RY).to(standard.RY);
|
||||
mapping.from(xbox.RX).to(standard.RX);
|
||||
mapping.from(xbox.LT).to(standard.LT);
|
||||
mapping.from(xbox.RT).to(standard.RT);
|
||||
mapping.enable();
|
||||
built = false;
|
||||
text = "XBox Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: root.hydra ? "Hydra Mapping" : "Hydra Not Found"
|
||||
property bool built: false
|
||||
enabled: root.hydra && !built
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping();
|
||||
mapping.from(hydra.LY).invert().to(standard.LY);
|
||||
mapping.from(hydra.LX).to(standard.LX);
|
||||
mapping.from(hydra.RY).invert().to(standard.RY);
|
||||
mapping.from(hydra.RX).to(standard.RX);
|
||||
mapping.from(hydra.LT).to(standard.LT);
|
||||
mapping.from(hydra.RT).to(standard.RT);
|
||||
mapping.enable();
|
||||
built = false;
|
||||
text = "Hydra Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Test Mapping"
|
||||
onClicked: {
|
||||
var mapping = Controller.newMapping();
|
||||
// Inverting a value
|
||||
mapping.from(hydra.RY).invert().to(standard.RY);
|
||||
mapping.from(hydra.RX).to(standard.RX);
|
||||
mapping.from(hydra.LY).to(standard.LY);
|
||||
mapping.from(hydra.LX).to(standard.LX);
|
||||
// Assigning a value from a function
|
||||
// mapping.from(function() { return Math.sin(Date.now() / 250); }).to(standard.RX);
|
||||
// Constrainting a value to -1, 0, or 1, with a deadzone
|
||||
// mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY);
|
||||
mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
|
||||
// mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT);
|
||||
// mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT);
|
||||
// mapping.modifier(keyboard.Ctrl).scale(2.0)
|
||||
// mapping.from(keyboard.A).to(actions.TranslateLeft)
|
||||
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
|
||||
// mapping.from(keyboard.A, keyboard.Shift, keyboard.Ctrl).scale(2.0).to(actions.TurnLeft)
|
||||
// // First loopbacks
|
||||
// // Then non-loopbacks by constraint level (number of inputs)
|
||||
// mapping.from(xbox.RX).deadZone(0.2).to(xbox.RX)
|
||||
// mapping.from(standard.RB, standard.LB, keyboard.Shift).to(actions.TurnLeft)
|
||||
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
|
||||
// mapping.from(keyboard.W).when(keyboard.Shift).to(actions.Forward)
|
||||
testMapping = mapping;
|
||||
enabled = false
|
||||
text = "Built"
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Enable Mapping"
|
||||
onClicked: root.testMapping.enable()
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Disable Mapping"
|
||||
onClicked: root.testMapping.disable()
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Enable Mapping"
|
||||
onClicked: print(Controller.getValue(root.xbox.LY));
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
Xbox { device: root.standard; label: "Standard"; width: 360 }
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: 8
|
||||
Xbox { device: root.xbox; label: "XBox"; width: 360 }
|
||||
Hydra { device: root.hydra; width: 360 }
|
||||
}
|
||||
// Row {
|
||||
// spacing: 8
|
||||
// ScrollingGraph {
|
||||
// controlId: Controller.Actions.Yaw
|
||||
// label: "Yaw"
|
||||
// min: -3.0
|
||||
// max: 3.0
|
||||
// size: 128
|
||||
// }
|
||||
//
|
||||
// ScrollingGraph {
|
||||
// controlId: Controller.Actions.YAW_LEFT
|
||||
// label: "Yaw Left"
|
||||
// min: -3.0
|
||||
// max: 3.0
|
||||
// size: 128
|
||||
// }
|
||||
//
|
||||
// ScrollingGraph {
|
||||
// controlId: Controller.Actions.YAW_RIGHT
|
||||
// label: "Yaw Right"
|
||||
// min: -3.0
|
||||
// max: 3.0
|
||||
// size: 128
|
||||
// }
|
||||
// }
|
||||
}
|
||||
} // dialog
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,207 +1,207 @@
|
|||
//
|
||||
// Joystick.cpp
|
||||
// input-plugins/src/input-plugins
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-23.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "Joystick.h"
|
||||
|
||||
#include <limits>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
const float CONTROLLER_THRESHOLD = 0.3f;
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
const float MAX_AXIS = 32768.0f;
|
||||
|
||||
Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) :
|
||||
InputDevice(name),
|
||||
_sdlGameController(sdlGameController),
|
||||
_sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)),
|
||||
_instanceId(instanceId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Joystick::~Joystick() {
|
||||
closeJoystick();
|
||||
}
|
||||
|
||||
void Joystick::closeJoystick() {
|
||||
#ifdef HAVE_SDL2
|
||||
SDL_GameControllerClose(_sdlGameController);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Joystick::update(float deltaTime, bool jointsCaptured) {
|
||||
for (auto axisState : _axisStateMap) {
|
||||
if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) {
|
||||
_axisStateMap[axisState.first] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Joystick::focusOutEvent() {
|
||||
_axisStateMap.clear();
|
||||
_buttonPressedMap.clear();
|
||||
};
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
|
||||
void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) {
|
||||
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis;
|
||||
_axisStateMap[makeInput((controller::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS;
|
||||
}
|
||||
|
||||
void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
|
||||
auto input = makeInput((controller::StandardButtonChannel)event.button);
|
||||
bool newValue = event.state == SDL_PRESSED;
|
||||
if (newValue) {
|
||||
_buttonPressedMap.insert(input.getChannel());
|
||||
} else {
|
||||
_buttonPressedMap.erase(input.getChannel());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void Joystick::registerToUserInputMapper(UserInputMapper& mapper) {
|
||||
// Grab the current free device ID
|
||||
_deviceID = mapper.getFreeDeviceID();
|
||||
|
||||
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
|
||||
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
||||
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
|
||||
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
|
||||
QVector<UserInputMapper::InputPair> availableInputs;
|
||||
// Buttons
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y"));
|
||||
|
||||
// DPad
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR"));
|
||||
|
||||
// Bumpers
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB"));
|
||||
|
||||
// Stick press
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS"));
|
||||
|
||||
// Center buttons
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back"));
|
||||
|
||||
// Analog sticks
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX"));
|
||||
|
||||
// Triggers
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT"));
|
||||
|
||||
// Aliases, PlayStation style names
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right"));
|
||||
|
||||
return availableInputs;
|
||||
};
|
||||
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
|
||||
mapper.removeAllInputChannelsForDevice(_deviceID);
|
||||
this->assignDefaultInputMapping(mapper);
|
||||
return true;
|
||||
};
|
||||
mapper.registerDevice(_deviceID, proxy);
|
||||
}
|
||||
|
||||
|
||||
void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
|
||||
#if 0
|
||||
#ifdef HAVE_SDL2
|
||||
const float JOYSTICK_MOVE_SPEED = 1.0f;
|
||||
const float DPAD_MOVE_SPEED = 0.5f;
|
||||
const float JOYSTICK_YAW_SPEED = 0.5f;
|
||||
const float JOYSTICK_PITCH_SPEED = 0.25f;
|
||||
const float BOOM_SPEED = 0.1f;
|
||||
|
||||
// Y axes are flipped (up is negative)
|
||||
// Left Joystick: Movement, strafing
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), JOYSTICK_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LX), JOYSTICK_MOVE_SPEED);
|
||||
// Right Joystick: Camera orientation
|
||||
mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), JOYSTICK_YAW_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), JOYSTICK_PITCH_SPEED);
|
||||
|
||||
// Dpad movement
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), DPAD_MOVE_SPEED);
|
||||
|
||||
// Button controls
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), DPAD_MOVE_SPEED);
|
||||
|
||||
// Zoom
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), BOOM_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), BOOM_SPEED);
|
||||
|
||||
// Hold front right shoulder button for precision controls
|
||||
// Left Joystick: Movement, strafing
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f);
|
||||
|
||||
// Right Joystick: Camera orientation
|
||||
mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), makeInput(controller::RB), JOYSTICK_YAW_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), makeInput(controller::RB), JOYSTICK_PITCH_SPEED / 2.0f);
|
||||
|
||||
// Dpad movement
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
|
||||
// Button controls
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
|
||||
// Zoom
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), makeInput(controller::RB), BOOM_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), makeInput(controller::RB), BOOM_SPEED / 2.0f);
|
||||
|
||||
mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(controller::RB));
|
||||
|
||||
mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(controller::B));
|
||||
mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(controller::A));
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
// Joystick.cpp
|
||||
// input-plugins/src/input-plugins
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-23.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "Joystick.h"
|
||||
|
||||
#include <limits>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
const float CONTROLLER_THRESHOLD = 0.3f;
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
const float MAX_AXIS = 32768.0f;
|
||||
|
||||
Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) :
|
||||
InputDevice(name),
|
||||
_sdlGameController(sdlGameController),
|
||||
_sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)),
|
||||
_instanceId(instanceId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Joystick::~Joystick() {
|
||||
closeJoystick();
|
||||
}
|
||||
|
||||
void Joystick::closeJoystick() {
|
||||
#ifdef HAVE_SDL2
|
||||
SDL_GameControllerClose(_sdlGameController);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Joystick::update(float deltaTime, bool jointsCaptured) {
|
||||
for (auto axisState : _axisStateMap) {
|
||||
if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) {
|
||||
_axisStateMap[axisState.first] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Joystick::focusOutEvent() {
|
||||
_axisStateMap.clear();
|
||||
_buttonPressedMap.clear();
|
||||
};
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
|
||||
void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) {
|
||||
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis;
|
||||
_axisStateMap[makeInput((controller::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS;
|
||||
}
|
||||
|
||||
void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
|
||||
auto input = makeInput((controller::StandardButtonChannel)event.button);
|
||||
bool newValue = event.state == SDL_PRESSED;
|
||||
if (newValue) {
|
||||
_buttonPressedMap.insert(input.getChannel());
|
||||
} else {
|
||||
_buttonPressedMap.erase(input.getChannel());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void Joystick::registerToUserInputMapper(UserInputMapper& mapper) {
|
||||
// Grab the current free device ID
|
||||
_deviceID = mapper.getFreeDeviceID();
|
||||
|
||||
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
|
||||
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
||||
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
|
||||
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
|
||||
QVector<UserInputMapper::InputPair> availableInputs;
|
||||
// Buttons
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y"));
|
||||
|
||||
// DPad
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR"));
|
||||
|
||||
// Bumpers
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB"));
|
||||
|
||||
// Stick press
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS"));
|
||||
|
||||
// Center buttons
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back"));
|
||||
|
||||
// Analog sticks
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX"));
|
||||
|
||||
// Triggers
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT"));
|
||||
|
||||
// Aliases, PlayStation style names
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left"));
|
||||
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right"));
|
||||
|
||||
return availableInputs;
|
||||
};
|
||||
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
|
||||
mapper.removeAllInputChannelsForDevice(_deviceID);
|
||||
this->assignDefaultInputMapping(mapper);
|
||||
return true;
|
||||
};
|
||||
mapper.registerDevice(_deviceID, proxy);
|
||||
}
|
||||
|
||||
|
||||
void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
|
||||
#if 0
|
||||
#ifdef HAVE_SDL2
|
||||
const float JOYSTICK_MOVE_SPEED = 1.0f;
|
||||
const float DPAD_MOVE_SPEED = 0.5f;
|
||||
const float JOYSTICK_YAW_SPEED = 0.5f;
|
||||
const float JOYSTICK_PITCH_SPEED = 0.25f;
|
||||
const float BOOM_SPEED = 0.1f;
|
||||
|
||||
// Y axes are flipped (up is negative)
|
||||
// Left Joystick: Movement, strafing
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), JOYSTICK_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LX), JOYSTICK_MOVE_SPEED);
|
||||
// Right Joystick: Camera orientation
|
||||
mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), JOYSTICK_YAW_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), JOYSTICK_PITCH_SPEED);
|
||||
|
||||
// Dpad movement
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), DPAD_MOVE_SPEED);
|
||||
|
||||
// Button controls
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), DPAD_MOVE_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), DPAD_MOVE_SPEED);
|
||||
|
||||
// Zoom
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), BOOM_SPEED);
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), BOOM_SPEED);
|
||||
|
||||
// Hold front right shoulder button for precision controls
|
||||
// Left Joystick: Movement, strafing
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f);
|
||||
|
||||
// Right Joystick: Camera orientation
|
||||
mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), makeInput(controller::RB), JOYSTICK_YAW_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), makeInput(controller::RB), JOYSTICK_PITCH_SPEED / 2.0f);
|
||||
|
||||
// Dpad movement
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
|
||||
// Button controls
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
|
||||
|
||||
// Zoom
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), makeInput(controller::RB), BOOM_SPEED / 2.0f);
|
||||
mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), makeInput(controller::RB), BOOM_SPEED / 2.0f);
|
||||
|
||||
mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(controller::RB));
|
||||
|
||||
mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(controller::B));
|
||||
mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(controller::A));
|
||||
#endif
|
||||
#endif
|
||||
}
|
|
@ -1,70 +1,70 @@
|
|||
//
|
||||
// Joystick.h
|
||||
// input-plugins/src/input-plugins
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-23.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_Joystick_h
|
||||
#define hifi_Joystick_h
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qvector.h>
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
#include <SDL.h>
|
||||
#undef main
|
||||
#endif
|
||||
|
||||
#include <controllers/InputDevice.h>
|
||||
#include <controllers/StandardControls.h>
|
||||
|
||||
class Joystick : public QObject, public InputDevice {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ getName)
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
Q_PROPERTY(int instanceId READ getInstanceId)
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
const QString& getName() const { return _name; }
|
||||
|
||||
// Device functions
|
||||
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
|
||||
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
|
||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||
virtual void focusOutEvent() override;
|
||||
|
||||
Joystick() : InputDevice("Joystick") {}
|
||||
~Joystick();
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController);
|
||||
#endif
|
||||
|
||||
void closeJoystick();
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
void handleAxisEvent(const SDL_ControllerAxisEvent& event);
|
||||
void handleButtonEvent(const SDL_ControllerButtonEvent& event);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
int getInstanceId() const { return _instanceId; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifdef HAVE_SDL2
|
||||
SDL_GameController* _sdlGameController;
|
||||
SDL_Joystick* _sdlJoystick;
|
||||
SDL_JoystickID _instanceId;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // hifi_Joystick_h
|
||||
//
|
||||
// Joystick.h
|
||||
// input-plugins/src/input-plugins
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-23.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_Joystick_h
|
||||
#define hifi_Joystick_h
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qvector.h>
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
#include <SDL.h>
|
||||
#undef main
|
||||
#endif
|
||||
|
||||
#include <controllers/InputDevice.h>
|
||||
#include <controllers/StandardControls.h>
|
||||
|
||||
class Joystick : public QObject, public InputDevice {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ getName)
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
Q_PROPERTY(int instanceId READ getInstanceId)
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
const QString& getName() const { return _name; }
|
||||
|
||||
// Device functions
|
||||
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
|
||||
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
|
||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||
virtual void focusOutEvent() override;
|
||||
|
||||
Joystick() : InputDevice("Joystick") {}
|
||||
~Joystick();
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController);
|
||||
#endif
|
||||
|
||||
void closeJoystick();
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
void handleAxisEvent(const SDL_ControllerAxisEvent& event);
|
||||
void handleButtonEvent(const SDL_ControllerButtonEvent& event);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
int getInstanceId() const { return _instanceId; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifdef HAVE_SDL2
|
||||
SDL_GameController* _sdlGameController;
|
||||
SDL_Joystick* _sdlJoystick;
|
||||
SDL_JoystickID _instanceId;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // hifi_Joystick_h
|
||||
|
|
Loading…
Reference in a new issue