mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:49:05 +02:00
Fixing namespace usage in input-plugins
This commit is contained in:
parent
f051a84dc6
commit
619fce0d7f
5 changed files with 468 additions and 464 deletions
|
@ -1,167 +1,167 @@
|
||||||
//
|
//
|
||||||
// Joystick.cpp
|
// Joystick.cpp
|
||||||
// input-plugins/src/input-plugins
|
// input-plugins/src/input-plugins
|
||||||
//
|
//
|
||||||
// Created by Stephen Birarda on 2014-09-23.
|
// Created by Stephen Birarda on 2014-09-23.
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "Joystick.h"
|
#include "Joystick.h"
|
||||||
|
|
||||||
#include "StandardControls.h"
|
#include "StandardControls.h"
|
||||||
|
|
||||||
const float CONTROLLER_THRESHOLD = 0.3f;
|
const float CONTROLLER_THRESHOLD = 0.3f;
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
const float MAX_AXIS = 32768.0f;
|
const float MAX_AXIS = 32768.0f;
|
||||||
|
|
||||||
Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) :
|
Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) :
|
||||||
InputDevice(name),
|
InputDevice(name),
|
||||||
_sdlGameController(sdlGameController),
|
_sdlGameController(sdlGameController),
|
||||||
_sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)),
|
_sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)),
|
||||||
_instanceId(instanceId)
|
_instanceId(instanceId)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Joystick::~Joystick() {
|
Joystick::~Joystick() {
|
||||||
closeJoystick();
|
closeJoystick();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::closeJoystick() {
|
void Joystick::closeJoystick() {
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
SDL_GameControllerClose(_sdlGameController);
|
SDL_GameControllerClose(_sdlGameController);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::update(float deltaTime, bool jointsCaptured) {
|
void Joystick::update(float deltaTime, bool jointsCaptured) {
|
||||||
for (auto axisState : _axisStateMap) {
|
for (auto axisState : _axisStateMap) {
|
||||||
if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) {
|
if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) {
|
||||||
_axisStateMap[axisState.first] = 0.0f;
|
_axisStateMap[axisState.first] = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::focusOutEvent() {
|
void Joystick::focusOutEvent() {
|
||||||
_axisStateMap.clear();
|
_axisStateMap.clear();
|
||||||
_buttonPressedMap.clear();
|
_buttonPressedMap.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
|
|
||||||
void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) {
|
void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) {
|
||||||
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis;
|
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis;
|
||||||
_axisStateMap[makeInput((Controllers::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS;
|
_axisStateMap[makeInput((controller::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
|
void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
|
||||||
auto input = makeInput((Controllers::StandardButtonChannel)event.button);
|
auto input = makeInput((controller::StandardButtonChannel)event.button);
|
||||||
bool newValue = event.state == SDL_PRESSED;
|
bool newValue = event.state == SDL_PRESSED;
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
_buttonPressedMap.insert(input.getChannel());
|
_buttonPressedMap.insert(input.getChannel());
|
||||||
} else {
|
} else {
|
||||||
_buttonPressedMap.erase(input.getChannel());
|
_buttonPressedMap.erase(input.getChannel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void Joystick::registerToUserInputMapper(UserInputMapper& mapper) {
|
void Joystick::registerToUserInputMapper(UserInputMapper& mapper) {
|
||||||
// Grab the current free device ID
|
// Grab the current free device ID
|
||||||
_deviceID = mapper.getFreeDeviceID();
|
_deviceID = mapper.getFreeDeviceID();
|
||||||
|
|
||||||
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
|
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
|
||||||
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
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->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
|
||||||
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
|
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
|
||||||
QVector<UserInputMapper::InputPair> availableInputs;
|
QVector<UserInputMapper::InputPair> availableInputs;
|
||||||
// Buttons
|
// Buttons
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "A"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "B"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "X"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Y"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y"));
|
||||||
|
|
||||||
// DPad
|
// DPad
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "DU"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "DD"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "DL"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "DR"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR"));
|
||||||
|
|
||||||
// Bumpers
|
// Bumpers
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "LB"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "RB"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB"));
|
||||||
|
|
||||||
// Stick press
|
// Stick press
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "LS"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "RS"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS"));
|
||||||
|
|
||||||
// Center buttons
|
// Center buttons
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::START), "Start"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Back"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back"));
|
||||||
|
|
||||||
// Analog sticks
|
// Analog sticks
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LY), "LY"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LX), "LX"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RY), "RY"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RX), "RX"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX"));
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "LT"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "RT"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT"));
|
||||||
|
|
||||||
// Aliases, PlayStation style names
|
// Aliases, PlayStation style names
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "L1"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "R1"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "L2"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "R2"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "L3"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "R3"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Select"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "Cross"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "Circle"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "Square"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Triangle"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "Up"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "Down"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "Left"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "Right"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right"));
|
||||||
|
|
||||||
return availableInputs;
|
return availableInputs;
|
||||||
};
|
};
|
||||||
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
|
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
|
||||||
mapper.removeAllInputChannelsForDevice(_deviceID);
|
mapper.removeAllInputChannelsForDevice(_deviceID);
|
||||||
this->assignDefaultInputMapping(mapper);
|
this->assignDefaultInputMapping(mapper);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
mapper.registerDevice(_deviceID, proxy);
|
mapper.registerDevice(_deviceID, proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
|
void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
const float JOYSTICK_MOVE_SPEED = 1.0f;
|
const float JOYSTICK_MOVE_SPEED = 1.0f;
|
||||||
const float DPAD_MOVE_SPEED = 0.5f;
|
const float DPAD_MOVE_SPEED = 0.5f;
|
||||||
const float JOYSTICK_YAW_SPEED = 0.5f;
|
const float JOYSTICK_YAW_SPEED = 0.5f;
|
||||||
const float JOYSTICK_PITCH_SPEED = 0.25f;
|
const float JOYSTICK_PITCH_SPEED = 0.25f;
|
||||||
const float BOOM_SPEED = 0.1f;
|
const float BOOM_SPEED = 0.1f;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInputMapper::Input Joystick::makeInput(Controllers::StandardButtonChannel button) {
|
UserInputMapper::Input Joystick::makeInput(controller::StandardButtonChannel button) {
|
||||||
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
|
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInputMapper::Input Joystick::makeInput(Controllers::StandardAxisChannel axis) {
|
UserInputMapper::Input Joystick::makeInput(controller::StandardAxisChannel axis) {
|
||||||
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
|
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,73 +1,73 @@
|
||||||
//
|
//
|
||||||
// Joystick.h
|
// Joystick.h
|
||||||
// input-plugins/src/input-plugins
|
// input-plugins/src/input-plugins
|
||||||
//
|
//
|
||||||
// Created by Stephen Birarda on 2014-09-23.
|
// Created by Stephen Birarda on 2014-09-23.
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef hifi_Joystick_h
|
#ifndef hifi_Joystick_h
|
||||||
#define hifi_Joystick_h
|
#define hifi_Joystick_h
|
||||||
|
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
#include <qvector.h>
|
#include <qvector.h>
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#undef main
|
#undef main
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
#include "StandardControls.h"
|
#include "StandardControls.h"
|
||||||
|
|
||||||
class Joystick : public QObject, public InputDevice {
|
class Joystick : public QObject, public InputDevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString name READ getName)
|
Q_PROPERTY(QString name READ getName)
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
Q_PROPERTY(int instanceId READ getInstanceId)
|
Q_PROPERTY(int instanceId READ getInstanceId)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
|
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
|
||||||
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
|
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
Joystick() : InputDevice("Joystick") {}
|
Joystick() : InputDevice("Joystick") {}
|
||||||
~Joystick();
|
~Joystick();
|
||||||
|
|
||||||
UserInputMapper::Input makeInput(Controllers::StandardButtonChannel button);
|
UserInputMapper::Input makeInput(controller::StandardButtonChannel button);
|
||||||
UserInputMapper::Input makeInput(Controllers::StandardAxisChannel axis);
|
UserInputMapper::Input makeInput(controller::StandardAxisChannel axis);
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController);
|
Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void closeJoystick();
|
void closeJoystick();
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
void handleAxisEvent(const SDL_ControllerAxisEvent& event);
|
void handleAxisEvent(const SDL_ControllerAxisEvent& event);
|
||||||
void handleButtonEvent(const SDL_ControllerButtonEvent& event);
|
void handleButtonEvent(const SDL_ControllerButtonEvent& event);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
int getInstanceId() const { return _instanceId; }
|
int getInstanceId() const { return _instanceId; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
SDL_GameController* _sdlGameController;
|
SDL_GameController* _sdlGameController;
|
||||||
SDL_Joystick* _sdlJoystick;
|
SDL_Joystick* _sdlJoystick;
|
||||||
SDL_JoystickID _instanceId;
|
SDL_JoystickID _instanceId;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Joystick_h
|
#endif // hifi_Joystick_h
|
||||||
|
|
|
@ -1,121 +1,121 @@
|
||||||
//
|
//
|
||||||
// StandardController.cpp
|
// StandardController.cpp
|
||||||
// input-plugins/src/input-plugins
|
// input-plugins/src/input-plugins
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 2015-10-11.
|
// Created by Brad Hefta-Gaub on 2015-10-11.
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "StandardController.h"
|
#include "StandardController.h"
|
||||||
|
|
||||||
const float CONTROLLER_THRESHOLD = 0.3f;
|
const float CONTROLLER_THRESHOLD = 0.3f;
|
||||||
|
|
||||||
StandardController::~StandardController() {
|
StandardController::~StandardController() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardController::update(float deltaTime, bool jointsCaptured) {
|
void StandardController::update(float deltaTime, bool jointsCaptured) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardController::focusOutEvent() {
|
void StandardController::focusOutEvent() {
|
||||||
_axisStateMap.clear();
|
_axisStateMap.clear();
|
||||||
_buttonPressedMap.clear();
|
_buttonPressedMap.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
void StandardController::registerToUserInputMapper(UserInputMapper& mapper) {
|
void StandardController::registerToUserInputMapper(UserInputMapper& mapper) {
|
||||||
// Grab the current free device ID
|
// Grab the current free device ID
|
||||||
_deviceID = mapper.getStandardDeviceID();
|
_deviceID = mapper.getStandardDeviceID();
|
||||||
|
|
||||||
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
|
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
|
||||||
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
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->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
|
||||||
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
|
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
|
||||||
QVector<UserInputMapper::InputPair> availableInputs;
|
QVector<UserInputMapper::InputPair> availableInputs;
|
||||||
// Buttons
|
// Buttons
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "A"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "B"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "X"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Y"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y"));
|
||||||
|
|
||||||
// DPad
|
// DPad
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "DU"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "DD"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "DL"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "DR"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR"));
|
||||||
|
|
||||||
// Bumpers
|
// Bumpers
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "LB"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "RB"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB"));
|
||||||
|
|
||||||
// Stick press
|
// Stick press
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "LS"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "RS"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS"));
|
||||||
|
|
||||||
// Center buttons
|
// Center buttons
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::START), "Start"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Back"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back"));
|
||||||
|
|
||||||
// Analog sticks
|
// Analog sticks
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LY), "LY"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LX), "LX"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RY), "RY"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RX), "RX"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX"));
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "LT"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "RT"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT"));
|
||||||
|
|
||||||
// Poses
|
// Poses
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LeftPose), "LeftPose"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LEFT), "LeftPose"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RightPose), "RightPose"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RIGHT), "RightPose"));
|
||||||
|
|
||||||
// Aliases, PlayStation style names
|
// Aliases, PlayStation style names
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "L1"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "R1"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "L2"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "R2"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "L3"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "R3"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Select"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "Cross"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "Circle"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "Square"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Triangle"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "Up"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "Down"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "Left"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left"));
|
||||||
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "Right"));
|
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right"));
|
||||||
|
|
||||||
|
|
||||||
return availableInputs;
|
return availableInputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
|
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
|
||||||
mapper.removeAllInputChannelsForDevice(_deviceID);
|
mapper.removeAllInputChannelsForDevice(_deviceID);
|
||||||
this->assignDefaultInputMapping(mapper);
|
this->assignDefaultInputMapping(mapper);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
mapper.registerStandardDevice(proxy);
|
mapper.registerStandardDevice(proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardController::assignDefaultInputMapping(UserInputMapper& mapper) {
|
void StandardController::assignDefaultInputMapping(UserInputMapper& mapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInputMapper::Input StandardController::makeInput(Controllers::StandardButtonChannel button) {
|
UserInputMapper::Input StandardController::makeInput(controller::StandardButtonChannel button) {
|
||||||
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
|
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInputMapper::Input StandardController::makeInput(Controllers::StandardAxisChannel axis) {
|
UserInputMapper::Input StandardController::makeInput(controller::StandardAxisChannel axis) {
|
||||||
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
|
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInputMapper::Input StandardController::makeInput(Controllers::StandardPoseChannel pose) {
|
UserInputMapper::Input StandardController::makeInput(controller::StandardPoseChannel pose) {
|
||||||
return UserInputMapper::Input(_deviceID, pose, UserInputMapper::ChannelType::POSE);
|
return UserInputMapper::Input(_deviceID, pose, UserInputMapper::ChannelType::POSE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,48 @@
|
||||||
//
|
//
|
||||||
// StandardController.h
|
// StandardController.h
|
||||||
// input-plugins/src/input-plugins
|
// input-plugins/src/input-plugins
|
||||||
//
|
//
|
||||||
// Created by Brad Hefta-Gaub on 2015-10-11.
|
// Created by Brad Hefta-Gaub on 2015-10-11.
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef hifi_StandardController_h
|
#ifndef hifi_StandardController_h
|
||||||
#define hifi_StandardController_h
|
#define hifi_StandardController_h
|
||||||
|
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
#include <qvector.h>
|
#include <qvector.h>
|
||||||
|
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
|
|
||||||
#include "StandardControls.h"
|
#include "StandardControls.h"
|
||||||
|
|
||||||
typedef std::shared_ptr<StandardController> StandardControllerPointer;
|
typedef std::shared_ptr<StandardController> StandardControllerPointer;
|
||||||
|
|
||||||
class StandardController : public QObject, public InputDevice {
|
class StandardController : public QObject, public InputDevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString name READ getName)
|
Q_PROPERTY(QString name READ getName)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
|
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
|
||||||
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
|
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
StandardController() : InputDevice("Standard") {}
|
StandardController() : InputDevice("Standard") {}
|
||||||
~StandardController();
|
~StandardController();
|
||||||
|
|
||||||
UserInputMapper::Input makeInput(Controllers::StandardButtonChannel button);
|
UserInputMapper::Input makeInput(controller::StandardButtonChannel button);
|
||||||
UserInputMapper::Input makeInput(Controllers::StandardAxisChannel axis);
|
UserInputMapper::Input makeInput(controller::StandardAxisChannel axis);
|
||||||
UserInputMapper::Input makeInput(Controllers::StandardPoseChannel pose);
|
UserInputMapper::Input makeInput(controller::StandardPoseChannel pose);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_StandardController_h
|
#endif // hifi_StandardController_h
|
||||||
|
|
|
@ -1,55 +1,59 @@
|
||||||
//
|
//
|
||||||
// Created by Bradley Austin Davis 2015/10/09
|
// Created by Bradley Austin Davis 2015/10/09
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace Controllers {
|
namespace controller {
|
||||||
|
|
||||||
// Needs to match order and values of SDL_GameControllerButton
|
// Needs to match order and values of SDL_GameControllerButton
|
||||||
enum StandardButtonChannel {
|
enum StandardButtonChannel {
|
||||||
// Button quad
|
// Button quad
|
||||||
A = 0,
|
A = 0,
|
||||||
B,
|
B,
|
||||||
X,
|
X,
|
||||||
Y,
|
Y,
|
||||||
// Center buttons
|
// Center buttons
|
||||||
BACK,
|
BACK,
|
||||||
GUIDE,
|
GUIDE,
|
||||||
START,
|
START,
|
||||||
// Stick press
|
// Stick press
|
||||||
LS,
|
LS,
|
||||||
RS,
|
RS,
|
||||||
// Bumper press
|
// Bumper press
|
||||||
LB,
|
LB,
|
||||||
RB,
|
RB,
|
||||||
// DPad
|
// DPad
|
||||||
DU,
|
DU,
|
||||||
DD,
|
DD,
|
||||||
DL,
|
DL,
|
||||||
DR
|
DR,
|
||||||
};
|
NUM_STANDARD_BUTTONS
|
||||||
|
};
|
||||||
// Needs to match order and values of SDL_GameControllerAxis
|
|
||||||
enum StandardAxisChannel {
|
// Needs to match order and values of SDL_GameControllerAxis
|
||||||
// Left Analog stick
|
enum StandardAxisChannel {
|
||||||
LX = 0,
|
// Left Analog stick
|
||||||
LY,
|
LX = 0,
|
||||||
// Right Analog stick
|
LY,
|
||||||
RX,
|
// Right Analog stick
|
||||||
RY,
|
RX,
|
||||||
// Triggers
|
RY,
|
||||||
LT,
|
// Triggers
|
||||||
RT
|
LT,
|
||||||
};
|
RT,
|
||||||
|
NUM_STANDARD_AXES
|
||||||
// No correlation to SDL
|
};
|
||||||
enum StandardPoseChannel {
|
|
||||||
LeftPose = 0,
|
// No correlation to SDL
|
||||||
RightPose
|
enum StandardPoseChannel {
|
||||||
};
|
LEFT = 0,
|
||||||
|
RIGHT,
|
||||||
}
|
HEAD,
|
||||||
|
NUM_STANDARD_POSES
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue